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 __COMPHELPER_REGISTRATION_HXX_
25 #define __COMPHELPER_REGISTRATION_HXX_
26 
27 //_______________________________________________
28 // includes
29 
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <rtl/ustrbuf.hxx>
33 #include <cppuhelper/factory.hxx>
34 
35 //_______________________________________________
36 // namespace
37 
38 namespace comphelper{
39 
40 //_______________________________________________
41 // declaration
42 
43 //_______________________________________________
44 
45 /** TODO    doc
46  */
47 #define _COMPHELPER_COMPONENT_GETIMPLEMENTATIONENVIRONMENT                                                          \
48     extern "C" void SAL_CALL component_getImplementationEnvironment(const sal_Char**        ppEnvironmentTypeName,  \
49                                                                           uno_Environment** /* ppEnvironment */ )   \
50     {                                                                                                               \
51         *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;                                                \
52     }
53 
54 //_______________________________________________
55 
56 /** TODO    doc
57  */
58 #define _COMPHELPER_MULTIINSTANCEFACTORY(IMPLEMENTATIONNAME, SERVICENAMES, FACTORYMETHOD)   \
59     if (IMPLEMENTATIONNAME == sImplName)                                                    \
60         xFactory = ::cppu::createSingleFactory(xSMGR             ,                          \
61                                                IMPLEMENTATIONNAME,                          \
62                                                FACTORYMETHOD     ,                          \
63                                                SERVICENAMES      );
64 
65 //_______________________________________________
66 
67 /** TODO    doc
68  */
69 #define _COMPHELPER_ONEINSTANCEFACTORY(IMPLEMENTATIONNAME, SERVICENAMES, FACTORYMETHOD)     \
70     if (IMPLEMENTATIONNAME == sImplName)                                                    \
71         xFactory = ::cppu::createOneInstanceFactory(xSMGR             ,                     \
72                                                     IMPLEMENTATIONNAME,                     \
73                                                     FACTORYMETHOD     ,                     \
74                                                     SERVICENAMES      );
75 
76 //_______________________________________________
77 
78 /** TODO    doc
79  */
80 #define _COMPHELPER_COMPONENT_GETFACTORY(STATIC_INIT,FACTORYLIST)                                                                                               \
81     extern "C" void* SAL_CALL component_getFactory(const sal_Char* pImplementationName,                                                             \
82                                                          void*     pServiceManager    ,                                                             \
83                                                          void*     /* pRegistryKey */ )                                                             \
84     {                                                                                                                                               \
85         if (                                                                                                                                        \
86             (!pImplementationName) ||                                                                                                               \
87             (!pServiceManager    )                                                                                                                  \
88            )                                                                                                                                        \
89         return NULL;                                                                                                                                \
90                                                                                                                                                     \
91         STATIC_INIT                                                                                                                                 \
92                                                                                                                                                     \
93         css::uno::Reference< css::lang::XMultiServiceFactory >  xSMGR     = reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager);  \
94         css::uno::Reference< css::lang::XSingleServiceFactory > xFactory  ;                                                                         \
95         rtl::OUString                                           sImplName = ::rtl::OUString::createFromAscii(pImplementationName);                  \
96                                                                                                                                                     \
97         /* This parameter will expand to: */                                                                                                        \
98         /*  _COMPHELPER_xxxFACTORY(1)     */                                                                                                        \
99         /*  else                          */                                                                                                        \
100         /*  ...                           */                                                                                                        \
101         /*  else                          */                                                                                                        \
102         /*  _COMPHELPER_xxxFACTORY(n)     */                                                                                                        \
103         FACTORYLIST                                                                                                                                 \
104                                                                                                                                                     \
105         /* And if one of these checks was successfully => xFactory was set! */                                                                      \
106         if (xFactory.is())                                                                                                                          \
107         {                                                                                                                                           \
108             xFactory->acquire();                                                                                                                    \
109             return xFactory.get();                                                                                                                  \
110         }                                                                                                                                           \
111                                                                                                                                                     \
112         return NULL;                                                                                                                                \
113 	}
114 
115 } // namespace comphelper
116 
117 #endif  //  #ifndef __COMPHELPER_REGISTRATION_HXX_
118