Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / cppuhelper / test / testlib / defbootstrap_lib.cxx
blob636707c24313b321c854f56e69677f2ce3b3ef67
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "EXTERN.h"
31 #include "perl.h"
32 #include "XSUB.h"
34 #include <cstdio>
36 #include <osl/module.hxx>
37 #include <rtl/process.h>
38 #include <cppuhelper/bootstrap.hxx>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 using namespace ::cppu;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::uno;
45 using namespace ::rtl;
47 static sal_Bool tryService(const char * serviceName)
49 // use micro deployment to create initial context
50 OUString libraryFileUrl;
51 ::osl::Module::getUrlFromAddress((void *)tryService, libraryFileUrl);
53 OUString iniName = libraryFileUrl.copy(0, libraryFileUrl.lastIndexOf((sal_Unicode)'.')); // cut the library extension
54 iniName += OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_CONFIGFILE(""))); // add the rc file extension
56 #if OSL_DEBUG_LEVEL > 1
57 OString sIniName = OUStringToOString(iniName, RTL_TEXTENCODING_ASCII_US);
58 fprintf(stderr, "defbootstrap.cxx:tryService: using ini: %s\n", sIniName.getStr());
59 #endif
61 sal_Bool result = sal_True;
63 try {
64 Reference<XComponentContext> xComponentContext = defaultBootstrap_InitialComponentContext(iniName);
65 Reference<XMultiServiceFactory> smgr(xComponentContext->getServiceManager(), UNO_QUERY);
67 OUString arg = OUString::createFromAscii(serviceName);
68 Reference<XInterface> xInterface = smgr->createInstance(arg);
70 #if OSL_DEBUG_LEVEL > 1
71 fprintf(stderr, "got the %s service %p\n", serviceName, xInterface.get());
72 #endif
73 result = result && (xInterface.get() != 0);
75 catch(Exception & exception) {
76 OString message = OUStringToOString(exception.Message, RTL_TEXTENCODING_ASCII_US);
78 fprintf(stderr, "an exception occurred: %s\n", message.getStr());
81 #if OSL_DEBUG_LEVEL > 1
82 OSL_TRACE("---------------------------------- %i", result);
83 #endif
85 return result;
88 XS(XS_UNO_tryService)
90 dXSARGS;
91 if (items != 1)
92 Perl_croak(aTHX_ "Usage: UNO::tryService(input)");
94 const char * input = (const char *)SvPV(ST(0),PL_na);
95 int RETVAL;
96 dXSTARG;
98 RETVAL = tryService(input);
99 XSprePUSH; PUSHi((IV)RETVAL);
101 XSRETURN(1);
104 extern "C" {
105 XS(boot_UNO)
107 dXSARGS;
108 char* file = __FILE__;
110 /* XS_VERSION_BOOTCHECK ;*/
112 newXS("UNO::tryService", XS_UNO_tryService, file);
113 XSRETURN_YES;
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */