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