1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cppuhelper.hxx"
26
27 #include "EXTERN.h"
28 #include "perl.h"
29 #include "XSUB.h"
30
31 #include <cstdio>
32
33 #include <osl/module.hxx>
34 #include <rtl/process.h>
35 #include <cppuhelper/bootstrap.hxx>
36
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38
39 using namespace ::cppu;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::uno;
42 using namespace ::rtl;
43
tryService(const char * serviceName)44 static sal_Bool tryService(const char * serviceName)
45 {
46 // use micro deployment to create initial context
47 OUString libraryFileUrl;
48 ::osl::Module::getUrlFromAddress((void *)tryService, libraryFileUrl);
49
50 OUString iniName = libraryFileUrl.copy(0, libraryFileUrl.lastIndexOf((sal_Unicode)'.')); // cut the library extension
51 iniName += OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_CONFIGFILE(""))); // add the rc file extension
52
53 #if OSL_DEBUG_LEVEL > 1
54 OString sIniName = OUStringToOString(iniName, RTL_TEXTENCODING_ASCII_US);
55 fprintf(stderr, "defbootstrap.cxx:tryService: using ini: %s\n", sIniName.getStr());
56 #endif
57
58 sal_Bool result = sal_True;
59
60 try {
61 Reference<XComponentContext> xComponentContext = defaultBootstrap_InitialComponentContext(iniName);
62 Reference<XMultiServiceFactory> smgr(xComponentContext->getServiceManager(), UNO_QUERY);
63
64 OUString arg = OUString::createFromAscii(serviceName);
65 Reference<XInterface> xInterface = smgr->createInstance(arg);
66
67 #if OSL_DEBUG_LEVEL > 1
68 fprintf(stderr, "got the %s service %p\n", serviceName, xInterface.get());
69 #endif
70 result = result && (xInterface.get() != 0);
71 }
72 catch(Exception & exception) {
73 OString message = OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
74
75 fprintf(stderr, "an exception occurred: %s\n", message.getStr());
76 }
77
78 #if OSL_DEBUG_LEVEL > 1
79 OSL_TRACE("---------------------------------- %i", result);
80 #endif
81
82 return result;
83 }
84
XS(XS_UNO_tryService)85 XS(XS_UNO_tryService)
86 {
87 dXSARGS;
88 if (items != 1)
89 Perl_croak(aTHX_ "Usage: UNO::tryService(input)");
90 {
91 const char * input = (const char *)SvPV(ST(0),PL_na);
92 int RETVAL;
93 dXSTARG;
94
95 RETVAL = tryService(input);
96 XSprePUSH; PUSHi((IV)RETVAL);
97 }
98 XSRETURN(1);
99 }
100
101 extern "C" {
XS(boot_UNO)102 XS(boot_UNO)
103 {
104 dXSARGS;
105 char* file = __FILE__;
106
107 /* XS_VERSION_BOOTCHECK ;*/
108
109 newXS("UNO::tryService", XS_UNO_tryService, file);
110 XSRETURN_YES;
111 }
112
113 }
114