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 
24 #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
25 #define __FRAMEWORK_MACROS_REGISTRATION_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <macros/debug.hxx>
32 
33 //_________________________________________________________________________________________________________________
34 //	interface includes
35 //_________________________________________________________________________________________________________________
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 
39 //_________________________________________________________________________________________________________________
40 //	other includes
41 //_________________________________________________________________________________________________________________
42 
43 //_________________________________________________________________________________________________________________
44 //	namespace
45 //_________________________________________________________________________________________________________________
46 
47 //namespace framework{
48 
49 /*_________________________________________________________________________________________________________________
50 
51 	macros for registration of services
52 	Please use follow public macros only!
53 
54 	IFFACTORY( CLASS )							=> use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
55 	COMPONENTGETIMPLEMENTATIONENVIRONMENT		=> use it to define exported function component_getImplementationEnvironment()
56 	COMPONENTGETFACTORY( IFFACTORIES )			=> use it to define exported function component_getFactory()
57 
58 _________________________________________________________________________________________________________________*/
59 
60 //*****************************************************************************************************************
61 //	public
62 //	use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
63 //*****************************************************************************************************************
64 #define	IFFACTORY( CLASS )																												\
65 	/* If searched name found ... */																									\
66 	/* You can't add some statements before follow line ... Here can be an ELSE-statement! */											\
67 	if ( CLASS::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) )					\
68 	{																																	\
69 		LOG_REGISTRATION_GETFACTORY( "\t\tImplementationname found - try to create factory! ...\n" )									\
70 		/* ... then create right factory for this service.									*/											\
71 		/* xFactory and xServiceManager are local variables of method which use this macro.	*/											\
72 		xFactory = CLASS::impl_createFactory( xServiceManager );																		\
73 	}
74 
75 //*****************************************************************************************************************
76 //	public
77 //	define helper to get information about service environment
78 //*****************************************************************************************************************
79 #define	COMPONENTGETIMPLEMENTATIONENVIRONMENT																							\
80 	extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const	sal_Char**			ppEnvironmentTypeName	,				\
81 																	 		uno_Environment**	            			)				\
82 	{																																	\
83 		*ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;																	\
84 	}
85 
86 //*****************************************************************************************************************
87 //	public
88 //	define method to instanciate new services
89 //*****************************************************************************************************************
90 #define	COMPONENTGETFACTORY( IFFACTORIES )																								\
91 	extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(	const	sal_Char*	pImplementationName	,											\
92 															void*		pServiceManager		,											\
93 															void*	  /*pRegistryKey*/		)											\
94 	{																																	\
95 		LOG_REGISTRATION_GETFACTORY( "\t[start]\n" )																					\
96 		/* Set default return value for this operation - if it failed. */																\
97 		void* pReturn = NULL ;																											\
98 		if	(																															\
99 				( pImplementationName	!=	NULL ) &&																					\
100 				( pServiceManager		!=	NULL )																						\
101 			)																															\
102 		{																																\
103 			LOG_REGISTRATION_GETFACTORY( "\t\tpImplementationName and pServiceManager are valid ...\n" )								\
104 			/* Define variables which are used in following macros. */																	\
105 			::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >	xFactory			;					\
106 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	xServiceManager		;					\
107 			xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager )	;					\
108 			/* These parameter will expand to      */																					\
109 			/* "IF_NAME_CREATECOMPONENTFACTORY(a)  */																					\
110 			/*  else                               */																					\
111 			/*  ...                                */																					\
112 			/*  else                               */																					\
113 			/*  IF_NAME_CREATECOMPONENTFACTORY(z)" */																					\
114 			IFFACTORIES																													\
115 			/* Factory is valid, if service was found. */																				\
116 			if ( xFactory.is() == sal_True )																							\
117 			{																															\
118 				LOG_REGISTRATION_GETFACTORY( "\t\t\txFactory valid - service was found ...\n" )											\
119 				xFactory->acquire();																									\
120 				pReturn = xFactory.get();																								\
121 			}																															\
122 		}																																\
123 		LOG_REGISTRATION_GETFACTORY( "\t[end]\n" )																						\
124 		/* Return with result of this operation. */																						\
125 		return pReturn ;																												\
126 	}
127 
128 //}		//	namespace framework
129 
130 #endif	//	#ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
131