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 #ifndef _CPPUHELPER_FACTORY_HXX_
24 #define _CPPUHELPER_FACTORY_HXX_
25 
26 #include <rtl/ustring.hxx>
27 #include <uno/dispatcher.h>
28 #include <rtl/unload.h>
29 
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
32 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/registry/XRegistryKey.hpp>
35 
36 //##################################################################################################
37 
38 #define COMPONENT_GETENV			"component_getImplementationEnvironment"
39 #define COMPONENT_GETENVEXT         "component_getImplementationEnvironmentExt"
40 #define COMPONENT_GETDESCRIPTION	"component_getDescription"
41 #define COMPONENT_WRITEINFO			"component_writeInfo"
42 #define COMPONENT_GETFACTORY		"component_getFactory"
43 
44 typedef struct _uno_Environment uno_Environment;
45 
46 /** Function pointer declaration.
47     Function determines the environment of the component implementation, i.e. which compiler
48     compiled it. If the environment is NOT session specific (needs no additional context),
49     then this function should return the environment type name and leave ppEnv (to 0).
50 
51     @param ppEnvTypeName environment type name; string must be constant
52     @param ppEnv function returns its environment if the environment is session specific,
53                  i.e. has special context
54 */
55 typedef void (SAL_CALL * component_getImplementationEnvironmentFunc)(
56 	const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv );
57 
58 /** Function pointer declaration.
59     Function determines the environment of the component implementation, i.e. the compiler.
60 	If the environment is NOT session specific (needs no additional context),
61     then this function should return the environment type name and leave ppEnv (to 0).
62 
63     @param ppEnvTypeName environment type name; string must be a constant
64     @param ppEnv         function returns an environment if the environment is session specific,
65                          i.e. has special context
66     @param pImplName
67 */
68 typedef void (SAL_CALL * component_getImplementationEnvironmentExtFunc)(
69 	sal_Char        const ** ppEnvTypeName,
70 	uno_Environment       ** ppEnv,
71 	sal_Char        const  * pImplName,
72 	uno_Environment        * pTargetEnv
73 );
74 
75 /** Function pointer declaration.
76     Function retrieves a component description.
77 
78     @return an XML formatted string containing a short component description
79     @deprecated
80 */
81 typedef const sal_Char * (SAL_CALL * component_getDescriptionFunc)(void);
82 
83 /** Function pointer declaration.
84 
85     @obsolete component_writeInfo should no longer be used in new components
86 
87     Function writes component registry info, at least writing the supported service names.
88 
89     @param pServiceManager
90 	a service manager (the type is an XMultiServiceFactory that can be used
91     by the environment returned by component_getImplementationEnvironment)
92     @param pRegistryKey a registry key
93     (the type is XRegistryKey that can be used by the environment
94     returned by component_getImplementationEnvironment)
95     @return true if everything went fine
96 */
97 typedef sal_Bool (SAL_CALL * component_writeInfoFunc)(
98 	void * pServiceManager, void * pRegistryKey );
99 
100 /** Function pointer declaration.
101     Retrieves a factory to create component instances.
102 
103    @param pImplName
104    desired implementation name
105    @param pServiceManager
106    a service manager (the type is XMultiServiceFactory that can be used by the environment
107    returned by component_getImplementationEnvironment)
108    @param pRegistryKey
109    a registry key (the type is XRegistryKey that can be used by the environment
110    returned by component_getImplementationEnvironment)
111    @return acquired component factory
112    (the type is lang::XSingleComponentFactory or lang::XSingleServiceFactory to be used by the
113    environment returned by component_getImplementationEnvironment)
114 */
115 typedef void * (SAL_CALL * component_getFactoryFunc)(
116 	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey );
117 
118 //##################################################################################################
119 
120 namespace cppu
121 {
122 
123 /** Function pointer declaration.
124     Function creates component instance passing the component context to be used.
125 
126     @param xContext component context to be used
127     @return component instance
128 */
129 typedef ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
130     SAL_CALL * ComponentFactoryFunc)(
131         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext )
132     SAL_THROW( (::com::sun::star::uno::Exception) );
133 
134 /** Creates a single component factory supporting the XSingleComponentFactory interface.
135 
136     @param fptr function pointer for instanciating the object
137     @param rImplementationName implementation name of service
138     @param rServiceNames supported services
139 	@param pModCount for future extension (library unloading concept).
140 */
141 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >
142 SAL_CALL createSingleComponentFactory(
143 	ComponentFactoryFunc fptr,
144 	::rtl::OUString const & rImplementationName,
145 	::com::sun::star::uno::Sequence< ::rtl::OUString > const & rServiceNames,
146 	rtl_ModuleCount * pModCount = 0 )
147 	SAL_THROW( () );
148 
149 /** Creates a single service factory which holds the instance created only once.
150 
151     @param fptr function pointer for instanciating the object
152     @param rImplementationName implementation name of service
153     @param rServiceNames supported services
154 	@param pModCount for future extension (library unloading concept).
155 
156     @see createSingleComponentFactory
157 */
158 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > SAL_CALL
159 createOneInstanceComponentFactory(
160 	ComponentFactoryFunc fptr,
161 	::rtl::OUString const & rImplementationName,
162 	::com::sun::star::uno::Sequence< ::rtl::OUString > const & rServiceNames,
163 	rtl_ModuleCount * pModCount = 0 )
164 	SAL_THROW( () );
165 
166 /** Deprecated.  The type of the instanciate function used as argument of the create*Fcatory functions.
167 
168     @see createSingleFactory
169     @see createOneInstanceFactory
170     @deprecated
171 */
172 typedef ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(SAL_CALL * ComponentInstantiation)(
173 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager );
174 
175 /** Deprecated.  Creates a single service factory.
176 
177     @param rServiceManager		the service manager used by the implementation.
178     @param rImplementationName	the implementation name. An empty string is possible.
179     @param ComponentInstantiation the function pointer to create an object.
180     @param rServiceNames			the service supported by the implementation.
181     @param pModCount             for future extension (library unloading concept).
182     @return a factory that support the interfaces XServiceProvider, XServiceInfo
183     XSingleServiceFactory and XComponent.
184 
185     @see createOneInstanceFactory
186     @deprecated
187 */
188 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL
189 createSingleFactory(
190 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager,
191 	const ::rtl::OUString & rImplementationName,
192 	ComponentInstantiation pCreateFunction,
193 	const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rServiceNames,
194 	rtl_ModuleCount * pModCount = 0  )
195 	SAL_THROW( () );
196 
197 /** Deprecated.  Creates a factory wrapping another one.
198     This means the methods of the interfaces XServiceProvider, XServiceInfo and
199     XSingleServiceFactory are forwarded.
200     @attention
201     The XComponent interface is not supported!
202 
203     @param rServiceManager		the service manager used by the implementation.
204     @param xSingleServiceFactory	the wrapped service factory.
205     @return a factory that support the interfaces XServiceProvider, XServiceInfo
206     XSingleServiceFactory.
207 
208     @see createSingleFactory
209     @deprecated
210 */
211 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL
212 createFactoryProxy(
213 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager,
214 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > & rFactory )
215 	SAL_THROW( () );
216 
217 /** Deprecated.  Creates a single service factory which holds the instance created only once.
218 
219     @param rServiceManager		the service manager used by the implementation.
220     @param rImplementationName	the implementation name. An empty string is possible.
221     @param ComponentInstantiation the function pointer to create an object.
222     @param rServiceNames			the service supported by the implementation.
223     @param pModCount             for future extension (library unloading concept).
224     @return a factory that support the interfaces XServiceProvider, XServiceInfo
225     XSingleServiceFactory and XComponent.
226 
227     @see createSingleFactory
228     @deprecated
229 */
230 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL
231 createOneInstanceFactory(
232 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager,
233 	const ::rtl::OUString & rComponentName,
234 	ComponentInstantiation pCreateFunction,
235 	const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rServiceNames,
236 	rtl_ModuleCount * pModCount = 0  )
237 	SAL_THROW( () );
238 
239 /** Deprecated.  Creates a single service factory based on a registry.
240 
241     @param rServiceManager		the service manager used by the implementation.
242     @param rImplementationName	the implementation name. An empty string is possible.
243     @param rImplementationKey	the registry key of the implementation section.
244     @return a factory that support the interfaces XServiceProvider, XServiceInfo
245     XSingleServiceFactory and XComponent.
246     @deprecated
247 */
248 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL createSingleRegistryFactory(
249 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager,
250 	const ::rtl::OUString & rImplementationName,
251 	const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > & rImplementationKey )
252 	SAL_THROW( () );
253 
254 /** Deprecated.  Creates a single service factory which holds the instance created only once
255     based on a registry.
256 
257     @param rServiceManager		the service manager used by the implementation.
258     @param rImplementationName	the implementation name. An empty string is possible.
259     @param rImplementationKey	the registry key of the implementation section.
260     @return a factory that support the interfaces XServiceProvider, XServiceInfo
261     XSingleServiceFactory and XComponent.
262 
263     @see createSingleRegistryFactory
264     @deprecated
265 */
266 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL createOneInstanceRegistryFactory(
267 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager,
268 	const ::rtl::OUString & rComponentName,
269 	const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > & rImplementationKey )
270 	SAL_THROW( () );
271 
272 }
273 
274 #endif
275