1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2e2212a7SAndrew Rist  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2e2212a7SAndrew Rist  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19*2e2212a7SAndrew Rist  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _REGISTRATIONHELPER_INCLUDED_INDIRECTLY_
25cdf0e10cSrcweir #error "don't include this file directly! use dbu_reghelper.hxx instead!"
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir 
28cdf0e10cSrcweir typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation)
29cdf0e10cSrcweir 		(
30cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rServiceManager,
31cdf0e10cSrcweir 			const ::rtl::OUString & _rComponentName,
32cdf0e10cSrcweir 			::cppu::ComponentInstantiation _pCreateFunction,
33cdf0e10cSrcweir 			const ::com::sun::star::uno::Sequence< ::rtl::OUString > & _rServiceNames,
34cdf0e10cSrcweir 			rtl_ModuleCount* _p
35cdf0e10cSrcweir 		);
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //==========================================================================
38cdf0e10cSrcweir class OModuleRegistration
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	static	::com::sun::star::uno::Sequence< ::rtl::OUString >*
41cdf0e10cSrcweir 		s_pImplementationNames;
42cdf0e10cSrcweir 	static	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > >*
43cdf0e10cSrcweir 		s_pSupportedServices;
44cdf0e10cSrcweir 	static	::com::sun::star::uno::Sequence< sal_Int64 >*
45cdf0e10cSrcweir 		s_pCreationFunctionPointers;
46cdf0e10cSrcweir 	static	::com::sun::star::uno::Sequence< sal_Int64 >*
47cdf0e10cSrcweir 		s_pFactoryFunctionPointers;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	// no direct instantiation, only static members/methods
OModuleRegistration()50cdf0e10cSrcweir 	OModuleRegistration() { }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir 	/** register a component implementing a service with the given data.
54cdf0e10cSrcweir 		@param		_rImplementationName		the implementation name of the component
55cdf0e10cSrcweir 		@param		_rServiceNames				the services the component supports
56cdf0e10cSrcweir 		@param		_pCreateFunction			a function for creating an instance of the component
57cdf0e10cSrcweir 		@param		_pFactoryFunction			a function for creating a factory for that component
58cdf0e10cSrcweir 		@see revokeComponent
59cdf0e10cSrcweir 	*/
60cdf0e10cSrcweir 	static void registerComponent(
61cdf0e10cSrcweir 		const ::rtl::OUString& _rImplementationName,
62cdf0e10cSrcweir 		const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
63cdf0e10cSrcweir 		::cppu::ComponentInstantiation _pCreateFunction,
64cdf0e10cSrcweir 		FactoryInstantiation _pFactoryFunction);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	/** revoke the registration for the specified component
67cdf0e10cSrcweir 		@param		_rImplementationName		the implementation name of the component
68cdf0e10cSrcweir 	*/
69cdf0e10cSrcweir 	static void revokeComponent(
70cdf0e10cSrcweir 		const ::rtl::OUString& _rImplementationName);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	/** creates a Factory for the component with the given implementation name. Usually used from within component_getFactory.
73cdf0e10cSrcweir 		@param		_rxServiceManager		a pointer to an XMultiServiceFactory interface as got in component_getFactory
74cdf0e10cSrcweir 		@param		_pImplementationName	the implementation name of the component
75cdf0e10cSrcweir 		@return								the XInterface access to a factory for the component
76cdf0e10cSrcweir 	*/
77cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
78cdf0e10cSrcweir 		const ::rtl::OUString& _rImplementationName,
79cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
80cdf0e10cSrcweir 		);
81cdf0e10cSrcweir };
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //==========================================================================
84cdf0e10cSrcweir template <class TYPE>
85cdf0e10cSrcweir class OMultiInstanceAutoRegistration
86cdf0e10cSrcweir {
87cdf0e10cSrcweir public:
88cdf0e10cSrcweir 	/** assumed that the template argument has the three methods<BR>
89cdf0e10cSrcweir 		<code>static ::rtl::OUString getImplementationName_Static()</code><BR>
90cdf0e10cSrcweir 		<code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><BR>
91cdf0e10cSrcweir 		and<BR>
92cdf0e10cSrcweir 		<code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
93cdf0e10cSrcweir 			Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
94cdf0e10cSrcweir 		the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
95cdf0e10cSrcweir 		The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
96cdf0e10cSrcweir 		@see OOneInstanceAutoRegistration
97cdf0e10cSrcweir 	*/
98cdf0e10cSrcweir 	OMultiInstanceAutoRegistration();
99cdf0e10cSrcweir 	~OMultiInstanceAutoRegistration();
100cdf0e10cSrcweir };
101cdf0e10cSrcweir 
102cdf0e10cSrcweir template <class TYPE>
OMultiInstanceAutoRegistration()103cdf0e10cSrcweir OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	OModuleRegistration::registerComponent(
106cdf0e10cSrcweir 		TYPE::getImplementationName_Static(),
107cdf0e10cSrcweir 		TYPE::getSupportedServiceNames_Static(),
108cdf0e10cSrcweir 		TYPE::Create,
109cdf0e10cSrcweir 		::cppu::createSingleFactory
110cdf0e10cSrcweir 		);
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir template <class TYPE>
~OMultiInstanceAutoRegistration()114cdf0e10cSrcweir OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir //==========================================================================
120cdf0e10cSrcweir template <class TYPE>
121cdf0e10cSrcweir class OOneInstanceAutoRegistration
122cdf0e10cSrcweir {
123cdf0e10cSrcweir public:
124cdf0e10cSrcweir 	/** provided that the template argument has three methods<BR>
125cdf0e10cSrcweir 		<code>static ::rtl::OUString getImplementationName_Static()</code><BR>
126cdf0e10cSrcweir 		<code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><BR>
127cdf0e10cSrcweir 		and<BR>
128cdf0e10cSrcweir 		<code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
129cdf0e10cSrcweir 			Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
130cdf0e10cSrcweir 		the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
131cdf0e10cSrcweir 		The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
132cdf0e10cSrcweir 		@see OMultiInstanceAutoRegistration
133cdf0e10cSrcweir 	*/
134cdf0e10cSrcweir 	OOneInstanceAutoRegistration();
135cdf0e10cSrcweir 	~OOneInstanceAutoRegistration();
136cdf0e10cSrcweir };
137cdf0e10cSrcweir 
138cdf0e10cSrcweir template <class TYPE>
OOneInstanceAutoRegistration()139cdf0e10cSrcweir OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	OModuleRegistration::registerComponent(
142cdf0e10cSrcweir 		TYPE::getImplementationName_Static(),
143cdf0e10cSrcweir 		TYPE::getSupportedServiceNames_Static(),
144cdf0e10cSrcweir 		TYPE::Create,
145cdf0e10cSrcweir 		::cppu::createOneInstanceFactory
146cdf0e10cSrcweir 		);
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir template <class TYPE>
~OOneInstanceAutoRegistration()150cdf0e10cSrcweir OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155