xref: /AOO42X/main/framework/inc/macros/registration.hxx (revision 9bce9b0d387299c68bd81d539e1478357a103de5) !
1f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f8e07b45SAndrew Rist  * distributed with this work for additional information
6f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18f8e07b45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f8e07b45SAndrew Rist  *************************************************************/
21f8e07b45SAndrew Rist 
22f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_MACROS_REGISTRATION_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir //  my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <macros/debug.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34cdf0e10cSrcweir //  interface includes
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir //  other includes
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44cdf0e10cSrcweir //  namespace
45cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //namespace framework{
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /*_________________________________________________________________________________________________________________
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     macros for registration of services
52cdf0e10cSrcweir     Please use follow public macros only!
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     IFFACTORY( CLASS )                          => use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
55cdf0e10cSrcweir     COMPONENTGETIMPLEMENTATIONENVIRONMENT       => use it to define exported function component_getImplementationEnvironment()
56cdf0e10cSrcweir     COMPONENTGETFACTORY( IFFACTORIES )          => use it to define exported function component_getFactory()
57cdf0e10cSrcweir 
58cdf0e10cSrcweir _________________________________________________________________________________________________________________*/
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //*****************************************************************************************************************
61cdf0e10cSrcweir //  public
62cdf0e10cSrcweir //  use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
63cdf0e10cSrcweir //*****************************************************************************************************************
64cdf0e10cSrcweir #define IFFACTORY( CLASS )                                                                                                              \
65cdf0e10cSrcweir     /* If searched name found ... */                                                                                                    \
66cdf0e10cSrcweir     /* You can't add some statements before follow line ... Here can be an ELSE-statement! */                                           \
67cdf0e10cSrcweir     if ( CLASS::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) )                  \
68cdf0e10cSrcweir     {                                                                                                                                   \
69cdf0e10cSrcweir         LOG_REGISTRATION_GETFACTORY( "\t\tImplementationname found - try to create factory! ...\n" )                                    \
70cdf0e10cSrcweir         /* ... then create right factory for this service.                                  */                                          \
71cdf0e10cSrcweir         /* xFactory and xServiceManager are local variables of method which use this macro. */                                          \
72cdf0e10cSrcweir         xFactory = CLASS::impl_createFactory( xServiceManager );                                                                        \
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir //*****************************************************************************************************************
76cdf0e10cSrcweir //  public
77cdf0e10cSrcweir //  define helper to get information about service environment
78cdf0e10cSrcweir //*****************************************************************************************************************
79cdf0e10cSrcweir #define COMPONENTGETIMPLEMENTATIONENVIRONMENT                                                                                           \
80cdf0e10cSrcweir     extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const sal_Char**          ppEnvironmentTypeName   ,               \
81cdf0e10cSrcweir                                                                             uno_Environment**                           )               \
82cdf0e10cSrcweir     {                                                                                                                                   \
83cdf0e10cSrcweir         *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;                                                                   \
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //*****************************************************************************************************************
87cdf0e10cSrcweir //  public
88*b7dc5163SJohn Bampton //  define method to instantiate new services
89cdf0e10cSrcweir //*****************************************************************************************************************
90cdf0e10cSrcweir #define COMPONENTGETFACTORY( IFFACTORIES )                                                                                              \
91cdf0e10cSrcweir     extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(    const   sal_Char*   pImplementationName ,                                           \
92cdf0e10cSrcweir                                                             void*       pServiceManager     ,                                           \
93cdf0e10cSrcweir                                                             void*     /*pRegistryKey*/      )                                           \
94cdf0e10cSrcweir     {                                                                                                                                   \
95cdf0e10cSrcweir         LOG_REGISTRATION_GETFACTORY( "\t[start]\n" )                                                                                    \
96cdf0e10cSrcweir         /* Set default return value for this operation - if it failed. */                                                               \
97cdf0e10cSrcweir         void* pReturn = NULL ;                                                                                                          \
98cdf0e10cSrcweir         if  (                                                                                                                           \
99cdf0e10cSrcweir                 ( pImplementationName   !=  NULL ) &&                                                                                   \
100cdf0e10cSrcweir                 ( pServiceManager       !=  NULL )                                                                                      \
101cdf0e10cSrcweir             )                                                                                                                           \
102cdf0e10cSrcweir         {                                                                                                                               \
103cdf0e10cSrcweir             LOG_REGISTRATION_GETFACTORY( "\t\tpImplementationName and pServiceManager are valid ...\n" )                                \
104cdf0e10cSrcweir             /* Define variables which are used in following macros. */                                                                  \
105d975be8cSAndre Fischer             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >   xFactory            ;                   \
106cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    xServiceManager     ;                   \
107cdf0e10cSrcweir             xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager )  ;                   \
108cdf0e10cSrcweir             /* These parameter will expand to      */                                                                                   \
109cdf0e10cSrcweir             /* "IF_NAME_CREATECOMPONENTFACTORY(a)  */                                                                                   \
110cdf0e10cSrcweir             /*  else                               */                                                                                   \
111cdf0e10cSrcweir             /*  ...                                */                                                                                   \
112cdf0e10cSrcweir             /*  else                               */                                                                                   \
113cdf0e10cSrcweir             /*  IF_NAME_CREATECOMPONENTFACTORY(z)" */                                                                                   \
114cdf0e10cSrcweir             IFFACTORIES                                                                                                                 \
115cdf0e10cSrcweir             /* Factory is valid, if service was found. */                                                                               \
116cdf0e10cSrcweir             if ( xFactory.is() == sal_True )                                                                                            \
117cdf0e10cSrcweir             {                                                                                                                           \
118cdf0e10cSrcweir                 LOG_REGISTRATION_GETFACTORY( "\t\t\txFactory valid - service was found ...\n" )                                         \
119cdf0e10cSrcweir                 xFactory->acquire();                                                                                                    \
120cdf0e10cSrcweir                 pReturn = xFactory.get();                                                                                               \
121cdf0e10cSrcweir             }                                                                                                                           \
122cdf0e10cSrcweir         }                                                                                                                               \
123cdf0e10cSrcweir         LOG_REGISTRATION_GETFACTORY( "\t[end]\n" )                                                                                      \
124cdf0e10cSrcweir         /* Return with result of this operation. */                                                                                     \
125cdf0e10cSrcweir         return pReturn ;                                                                                                                \
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir //}     //  namespace framework
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #endif  //  #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
131