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