1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist *
3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*34dd1e25SAndrew Rist * distributed with this work for additional information
6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at
10*34dd1e25SAndrew Rist *
11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist *
13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the
17*34dd1e25SAndrew Rist * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist * under the License.
19*34dd1e25SAndrew Rist *
20*34dd1e25SAndrew Rist *************************************************************/
21*34dd1e25SAndrew Rist
22*34dd1e25SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir #include <rtl/ustring.hxx>
26cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> // helper for queryInterface() impl
27cdf0e10cSrcweir #include <cppuhelper/factory.hxx> // helper for component factory
28cdf0e10cSrcweir // generated c++ interfaces
29cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
33cdf0e10cSrcweir
34cdf0e10cSrcweir // include our specific addon header to get access to functions and definitions
35cdf0e10cSrcweir #include <addon.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace ::rtl;
38cdf0e10cSrcweir using namespace ::osl;
39cdf0e10cSrcweir using namespace ::cppu;
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir using namespace ::com::sun::star::lang;
42cdf0e10cSrcweir using namespace ::com::sun::star::registry;
43cdf0e10cSrcweir
44cdf0e10cSrcweir //##################################################################################################
45cdf0e10cSrcweir //#### EXPORTED ####################################################################################
46cdf0e10cSrcweir //##################################################################################################
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir /**
50cdf0e10cSrcweir * Gives the environment this component belongs to.
51cdf0e10cSrcweir */
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)52cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
57cdf0e10cSrcweir /**
58cdf0e10cSrcweir * This function creates an implementation section in the registry and another subkey
59cdf0e10cSrcweir *
60cdf0e10cSrcweir * for each supported service.
61cdf0e10cSrcweir * @param pServiceManager the service manager
62cdf0e10cSrcweir * @param pRegistryKey the registry key
63cdf0e10cSrcweir */
64cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration was
65cdf0e10cSrcweir // was changed to passive component registration. For more details see
66cdf0e10cSrcweir // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
67cdf0e10cSrcweir //
68cdf0e10cSrcweir // extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey)
69cdf0e10cSrcweir // {
70cdf0e10cSrcweir // sal_Bool result = sal_False;
71cdf0e10cSrcweir
72cdf0e10cSrcweir // if (pRegistryKey)
73cdf0e10cSrcweir // {
74cdf0e10cSrcweir // try
75cdf0e10cSrcweir // {
76cdf0e10cSrcweir // Reference< XRegistryKey > xNewKey(
77cdf0e10cSrcweir // reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
78cdf0e10cSrcweir // OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLEMENTATION_NAME "/UNO/SERVICES") ) ) );
79cdf0e10cSrcweir
80cdf0e10cSrcweir // const Sequence< OUString > & rSNL =
81cdf0e10cSrcweir // Addon_getSupportedServiceNames();
82cdf0e10cSrcweir // const OUString * pArray = rSNL.getConstArray();
83cdf0e10cSrcweir // for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
84cdf0e10cSrcweir // xNewKey->createKey( pArray[nPos] );
85cdf0e10cSrcweir
86cdf0e10cSrcweir // return sal_True;
87cdf0e10cSrcweir // }
88cdf0e10cSrcweir // catch (InvalidRegistryException &)
89cdf0e10cSrcweir // {
90cdf0e10cSrcweir // // we should not ignore exceptions
91cdf0e10cSrcweir // }
92cdf0e10cSrcweir // }
93cdf0e10cSrcweir // return result;
94cdf0e10cSrcweir // }
95cdf0e10cSrcweir
96cdf0e10cSrcweir /**
97cdf0e10cSrcweir * This function is called to get service factories for an implementation.
98cdf0e10cSrcweir *
99cdf0e10cSrcweir * @param pImplName name of implementation
100cdf0e10cSrcweir * @param pServiceManager a service manager, need for component creation
101cdf0e10cSrcweir * @param pRegistryKey the registry key for this component, need for persistent data
102cdf0e10cSrcweir * @return a component factory
103cdf0e10cSrcweir */
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)104cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir void * pRet = 0;
107cdf0e10cSrcweir
108cdf0e10cSrcweir if (rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir Reference< XSingleServiceFactory > xFactory( createSingleFactory(
111cdf0e10cSrcweir reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
112cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ),
113cdf0e10cSrcweir Addon_createInstance,
114cdf0e10cSrcweir Addon_getSupportedServiceNames() ) );
115cdf0e10cSrcweir
116cdf0e10cSrcweir if (xFactory.is())
117cdf0e10cSrcweir {
118cdf0e10cSrcweir xFactory->acquire();
119cdf0e10cSrcweir pRet = xFactory.get();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
123cdf0e10cSrcweir return pRet;
124cdf0e10cSrcweir }
125