1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
27 #include <osl/module.hxx>
28 #include <rtl/process.h>
29 #include <cppuhelper/bootstrap.hxx>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 using namespace ::cppu
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::uno
;
37 static sal_Bool
tryService(const char * serviceName
)
39 // use micro deployment to create initial context
40 OUString libraryFileUrl
;
41 ::osl::Module::getUrlFromAddress((void *)tryService
, libraryFileUrl
);
43 OUString iniName
= libraryFileUrl
.copy(0, libraryFileUrl
.lastIndexOf((sal_Unicode
)'.')); // cut the library extension
44 iniName
+= OUString(SAL_CONFIGFILE("")); // add the rc file extension
46 #if OSL_DEBUG_LEVEL > 1
47 OString sIniName
= OUStringToOString(iniName
, RTL_TEXTENCODING_ASCII_US
);
48 fprintf(stderr
, "defbootstrap.cxx:tryService: using ini: %s\n", sIniName
.getStr());
51 sal_Bool result
= sal_True
;
54 Reference
<XComponentContext
> xComponentContext
= defaultBootstrap_InitialComponentContext(iniName
);
55 Reference
<XMultiServiceFactory
> smgr(xComponentContext
->getServiceManager(), UNO_QUERY
);
57 OUString arg
= OUString::createFromAscii(serviceName
);
58 Reference
<XInterface
> xInterface
= smgr
->createInstance(arg
);
60 #if OSL_DEBUG_LEVEL > 1
61 fprintf(stderr
, "got the %s service %p\n", serviceName
, xInterface
.get());
63 result
= result
&& (xInterface
.get() != 0);
65 catch(Exception
& exception
) {
66 OString message
= OUStringToOString(exception
.Message
, RTL_TEXTENCODING_ASCII_US
);
68 fprintf(stderr
, "an exception occurred: %s\n", message
.getStr());
71 #if OSL_DEBUG_LEVEL > 1
72 OSL_TRACE("---------------------------------- %i", result
);
82 Perl_croak(aTHX_
"Usage: UNO::tryService(input)");
84 const char * input
= (const char *)SvPV(ST(0),PL_na
);
88 RETVAL
= tryService(input
);
89 XSprePUSH
; PUSHi((IV
)RETVAL
);
98 char* file
= __FILE__
;
100 /* XS_VERSION_BOOTCHECK ;*/
102 newXS("UNO::tryService", XS_UNO_tryService
, file
);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */