1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 #include <stdio.h>
36 #include <rtl/ustring.hxx>
37 #include <cppuhelper/queryinterface.hxx> // helper for queryInterface() impl
38 #include <cppuhelper/factory.hxx> // helper for component factory
39 // generated c++ interfaces
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/registry/XRegistryKey.hpp>
44 
45 // include our specific addon header to get access to functions and definitions
46 #include <addon.hxx>
47 
48 using namespace ::rtl;
49 using namespace ::osl;
50 using namespace ::cppu;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::registry;
54 
55 //##################################################################################################
56 //#### EXPORTED ####################################################################################
57 //##################################################################################################
58 
59 
60 /**
61  * Gives the environment this component belongs to.
62  */
63 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv)
64 {
65 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
66 }
67 
68 /**
69  * This function creates an implementation section in the registry and another subkey
70  *
71  * for each supported service.
72  * @param pServiceManager   the service manager
73  * @param pRegistryKey      the registry key
74  */
75 // This method not longer necessary since OOo 3.4 where the component registration was
76 // was changed to passive component registration. For more details see
77 // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
78 //
79 // extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey)
80 // {
81 // 	sal_Bool result = sal_False;
82 
83 // 	if (pRegistryKey)
84 // 	{
85 // 		try
86 // 		{
87 // 			Reference< XRegistryKey > xNewKey(
88 // 				reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
89 // 					OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLEMENTATION_NAME "/UNO/SERVICES") ) ) );
90 
91 // 			const Sequence< OUString > & rSNL =
92 // 				Addon_getSupportedServiceNames();
93 // 			const OUString * pArray = rSNL.getConstArray();
94 // 			for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
95 // 				xNewKey->createKey( pArray[nPos] );
96 
97 // 			return sal_True;
98 // 		}
99 // 		catch (InvalidRegistryException &)
100 // 		{
101 // 			// we should not ignore exceptions
102 // 		}
103 // 	}
104 // 	return result;
105 // }
106 
107 /**
108  * This function is called to get service factories for an implementation.
109  *
110  * @param pImplName       name of implementation
111  * @param pServiceManager a service manager, need for component creation
112  * @param pRegistryKey    the registry key for this component, need for persistent data
113  * @return a component factory
114  */
115 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey)
116 {
117 	void * pRet = 0;
118 
119 	if (rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0)
120 	{
121 		Reference< XSingleServiceFactory > xFactory( createSingleFactory(
122 			reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
123 			OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ),
124 			Addon_createInstance,
125 			Addon_getSupportedServiceNames() ) );
126 
127 		if (xFactory.is())
128 		{
129 			xFactory->acquire();
130 			pRet = xFactory.get();
131 		}
132 	}
133 
134 	return pRet;
135 }
136