merge the formfield patch from ooo-build
[ooovba.git] / framework / inc / macros / registration.hxx
blob153f588322e405456abcc12b0dfe353d40d73267
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registration.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
32 #define __FRAMEWORK_MACROS_REGISTRATION_HXX_
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
38 #include <macros/debug.hxx>
40 //_________________________________________________________________________________________________________________
41 // interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/registry/XRegistryKey.hpp>
44 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/registry/InvalidRegistryException.hpp>
48 //_________________________________________________________________________________________________________________
49 // other includes
50 //_________________________________________________________________________________________________________________
52 //_________________________________________________________________________________________________________________
53 // namespace
54 //_________________________________________________________________________________________________________________
56 //namespace framework{
58 /*_________________________________________________________________________________________________________________
60 macros for registration of services
61 Please use follow public macros only!
63 1) COMPONENTINFO( CLASS ) => use it as parameter for COMPONENT_WRITEINFO( INFOS )
64 2) IFFACTORY( CLASS ) => use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
65 3) COMPONENTGETIMPLEMENTATIONENVIRONMENT => use it to define exported function component_getImplementationEnvironment()
66 4) COMPONENTWRITEINFO( INFOS ) => use it to define exported function component_writeInfo()
67 5) COMPONENTGETFACTORY( IFFACTORIES ) => use it to define exported function component_getFactory()
69 _________________________________________________________________________________________________________________*/
71 //*****************************************************************************************************************
72 // public
73 // use it as parameter for COMPONENT_WRITEINFO( INFOS )
74 //*****************************************************************************************************************
76 #define COMPONENTINFO( CLASS ) \
77 try \
78 { \
79 /* Set default result of follow operations !!! */ \
80 bReturn = sal_False; \
81 /* Do the follow only, if given key is valid ! */ \
82 if ( xKey.is() == sal_True ) \
83 { \
84 LOG_REGISTRATION_WRITEINFO( "\t\t\txKey is valid ...\n" ) \
85 /* Build new keyname */ \
86 sKeyName = DECLARE_ASCII( "/" ); \
87 sKeyName += CLASS::impl_getStaticImplementationName(); \
88 sKeyName += DECLARE_ASCII( "/UNO/SERVICES" ); \
89 LOG_REGISTRATION_WRITEINFO( "\t\t\tcreate key \"" ) \
90 LOG_REGISTRATION_WRITEINFO( U2B( sKeyName ) ) \
91 LOG_REGISTRATION_WRITEINFO( "\" ...\n" ) \
92 /* Create new key with new name. */ \
93 xNewKey = xKey->createKey( sKeyName ); \
94 /* If this new key valid ... */ \
95 if ( xNewKey.is() == sal_True ) \
96 { \
97 LOG_REGISTRATION_WRITEINFO( "\t\t\t\ttsuccessful ...\n" ) \
98 /* Get information about supported services. */ \
99 seqServiceNames = CLASS::impl_getStaticSupportedServiceNames() ; \
100 pArray = seqServiceNames.getArray() ; \
101 nLength = seqServiceNames.getLength() ; \
102 nCounter = 0 ; \
103 /* Then set this information on this key. */ \
104 for ( nCounter = 0; nCounter < nLength; ++nCounter ) \
106 LOG_REGISTRATION_WRITEINFO( "\t\t\t\twrite key \"" ) \
107 LOG_REGISTRATION_WRITEINFO( U2B( pArray[nCounter] ) ) \
108 LOG_REGISTRATION_WRITEINFO( "\" to registry ...\n" ) \
109 xNewKey->createKey( pArray[nCounter] ); \
111 /* Result of this operations = OK. */ \
112 bReturn = sal_True ; \
116 catch( ::com::sun::star::registry::InvalidRegistryException& ) \
118 LOG_REGISTRATION_WRITEINFO( "\n\nERROR:\nInvalidRegistryException detected\n\n" ) \
119 bReturn = sal_False ; \
122 //*****************************************************************************************************************
123 // public
124 // use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
125 //*****************************************************************************************************************
126 #define IFFACTORY( CLASS ) \
127 /* If searched name found ... */ \
128 /* You can't add some statements before follow line ... Here can be an ELSE-statement! */ \
129 if ( CLASS::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) ) \
131 LOG_REGISTRATION_GETFACTORY( "\t\tImplementationname found - try to create factory! ...\n" ) \
132 /* ... then create right factory for this service. */ \
133 /* xFactory and xServiceManager are local variables of method which use this macro. */ \
134 xFactory = CLASS::impl_createFactory( xServiceManager ); \
137 //*****************************************************************************************************************
138 // public
139 // define helper to get information about service environment
140 //*****************************************************************************************************************
141 #define COMPONENTGETIMPLEMENTATIONENVIRONMENT \
142 extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvironmentTypeName , \
143 uno_Environment** ) \
145 *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ; \
148 //*****************************************************************************************************************
149 // public
150 // define registration of service
151 //*****************************************************************************************************************
152 #define COMPONENTWRITEINFO( INFOS ) \
153 extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/ , \
154 void* pRegistryKey ) \
156 LOG_REGISTRATION_WRITEINFO( "\t[start]\n" ) \
157 /* Set default return value for this operation - if it failed. */ \
158 sal_Bool bReturn = sal_False ; \
159 if ( pRegistryKey != NULL ) \
161 LOG_REGISTRATION_WRITEINFO( "\t\tpRegistryKey is valid ...\n" ) \
162 /* Define variables for following helper macros! */ \
163 /* bReturn will set automaticly. */ \
164 ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > xKey ; \
165 ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > xNewKey ; \
166 ::com::sun::star::uno::Sequence< ::rtl::OUString > seqServiceNames ; \
167 const ::rtl::OUString* pArray ; \
168 sal_Int32 nLength ; \
169 sal_Int32 nCounter ; \
170 ::rtl::OUString sKeyName ; \
171 xKey = reinterpret_cast< ::com::sun::star::registry::XRegistryKey* >( pRegistryKey ); \
172 /* This parameter will expand to */ \
173 /* "COMPONENT_INFO(a) */ \
174 /* ... */ \
175 /* COMPONENT_INFO(z)" */ \
176 INFOS \
178 LOG_REGISTRATION_WRITEINFO( "\t[end]\n" ) \
179 /* Return with result of this operation. */ \
180 return bReturn ; \
183 //*****************************************************************************************************************
184 // public
185 // define method to instanciate new services
186 //*****************************************************************************************************************
187 #define COMPONENTGETFACTORY( IFFACTORIES ) \
188 extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplementationName , \
189 void* pServiceManager , \
190 void* /*pRegistryKey*/ ) \
192 LOG_REGISTRATION_GETFACTORY( "\t[start]\n" ) \
193 /* Set default return value for this operation - if it failed. */ \
194 void* pReturn = NULL ; \
195 if ( \
196 ( pImplementationName != NULL ) && \
197 ( pServiceManager != NULL ) \
200 LOG_REGISTRATION_GETFACTORY( "\t\tpImplementationName and pServiceManager are valid ...\n" ) \
201 /* Define variables which are used in following macros. */ \
202 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory ; \
203 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager ; \
204 xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ; \
205 /* These parameter will expand to */ \
206 /* "IF_NAME_CREATECOMPONENTFACTORY(a) */ \
207 /* else */ \
208 /* ... */ \
209 /* else */ \
210 /* IF_NAME_CREATECOMPONENTFACTORY(z)" */ \
211 IFFACTORIES \
212 /* Factory is valid, if service was found. */ \
213 if ( xFactory.is() == sal_True ) \
215 LOG_REGISTRATION_GETFACTORY( "\t\t\txFactory valid - service was found ...\n" ) \
216 xFactory->acquire(); \
217 pReturn = xFactory.get(); \
220 LOG_REGISTRATION_GETFACTORY( "\t[end]\n" ) \
221 /* Return with result of this operation. */ \
222 return pReturn ; \
225 //} // namespace framework
227 #endif // #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_