134dd1e25SAndrew Rist /**************************************************************
2*3ba931c7Smseidel  *
334dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
434dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
534dd1e25SAndrew Rist  * distributed with this work for additional information
634dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
734dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
834dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
934dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3ba931c7Smseidel  *
1134dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3ba931c7Smseidel  *
1334dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1434dd1e25SAndrew Rist  * software distributed under the License is distributed on an
1534dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1634dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
1734dd1e25SAndrew Rist  * specific language governing permissions and limitations
1834dd1e25SAndrew Rist  * under the License.
19*3ba931c7Smseidel  *
2034dd1e25SAndrew Rist  *************************************************************/
2134dd1e25SAndrew Rist 
2234dd1e25SAndrew 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>
36*3ba931c7Smseidel 
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;
42*3ba931c7Smseidel 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
66*3ba931c7Smseidel // https://wiki.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") ) ) );
79*3ba931c7Smseidel 
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] );
85*3ba931c7Smseidel 
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
102*3ba931c7Smseidel  * @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;
107*3ba931c7Smseidel 
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() ) );
115*3ba931c7Smseidel 
116cdf0e10cSrcweir 		if (xFactory.is())
117cdf0e10cSrcweir 		{
118cdf0e10cSrcweir 			xFactory->acquire();
119cdf0e10cSrcweir 			pRet = xFactory.get();
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 	}
122*3ba931c7Smseidel 
123cdf0e10cSrcweir 	return pRet;
124*3ba931c7Smseidel }
125*3ba931c7Smseidel 
126