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 #include <stdio.h> 25 #include <rtl/ustring.hxx> 26 #include <cppuhelper/queryinterface.hxx> // helper for queryInterface() impl 27 #include <cppuhelper/factory.hxx> // helper for component factory 28 // generated c++ interfaces 29 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 30 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31 #include <com/sun/star/lang/XServiceInfo.hpp> 32 #include <com/sun/star/registry/XRegistryKey.hpp> 33 34 // include our specific addon header to get access to functions and definitions 35 #include <addon.hxx> 36 37 using namespace ::rtl; 38 using namespace ::osl; 39 using namespace ::cppu; 40 using namespace ::com::sun::star::uno; 41 using namespace ::com::sun::star::lang; 42 using namespace ::com::sun::star::registry; 43 44 //################################################################################################## 45 //#### EXPORTED #################################################################################### 46 //################################################################################################## 47 48 49 /** 50 * Gives the environment this component belongs to. 51 */ 52 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv) 53 { 54 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 55 } 56 57 /** 58 * This function creates an implementation section in the registry and another subkey 59 * 60 * for each supported service. 61 * @param pServiceManager the service manager 62 * @param pRegistryKey the registry key 63 */ 64 // This method not longer necessary since OOo 3.4 where the component registration was 65 // was changed to passive component registration. For more details see 66 // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 67 // 68 // extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey) 69 // { 70 // sal_Bool result = sal_False; 71 72 // if (pRegistryKey) 73 // { 74 // try 75 // { 76 // Reference< XRegistryKey > xNewKey( 77 // reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( 78 // OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLEMENTATION_NAME "/UNO/SERVICES") ) ) ); 79 80 // const Sequence< OUString > & rSNL = 81 // Addon_getSupportedServiceNames(); 82 // const OUString * pArray = rSNL.getConstArray(); 83 // for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) 84 // xNewKey->createKey( pArray[nPos] ); 85 86 // return sal_True; 87 // } 88 // catch (InvalidRegistryException &) 89 // { 90 // // we should not ignore exceptions 91 // } 92 // } 93 // return result; 94 // } 95 96 /** 97 * This function is called to get service factories for an implementation. 98 * 99 * @param pImplName name of implementation 100 * @param pServiceManager a service manager, need for component creation 101 * @param pRegistryKey the registry key for this component, need for persistent data 102 * @return a component factory 103 */ 104 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey) 105 { 106 void * pRet = 0; 107 108 if (rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) 109 { 110 Reference< XSingleServiceFactory > xFactory( createSingleFactory( 111 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 112 OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ), 113 Addon_createInstance, 114 Addon_getSupportedServiceNames() ) ); 115 116 if (xFactory.is()) 117 { 118 xFactory->acquire(); 119 pRet = xFactory.get(); 120 } 121 } 122 123 return pRet; 124 } 125