1*22e87013SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*22e87013SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*22e87013SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*22e87013SAndrew Rist  * distributed with this work for additional information
6*22e87013SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*22e87013SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*22e87013SAndrew Rist  * "License"); you may not use this file except in compliance
9*22e87013SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*22e87013SAndrew Rist  *
11*22e87013SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*22e87013SAndrew Rist  *
13*22e87013SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*22e87013SAndrew Rist  * software distributed under the License is distributed on an
15*22e87013SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*22e87013SAndrew Rist  * KIND, either express or implied.  See the License for the
17*22e87013SAndrew Rist  * specific language governing permissions and limitations
18*22e87013SAndrew Rist  * under the License.
19*22e87013SAndrew Rist  *
20*22e87013SAndrew Rist  *************************************************************/
21*22e87013SAndrew Rist 
22*22e87013SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __COMPHELPER_REGISTRATION_HXX_
25cdf0e10cSrcweir #define __COMPHELPER_REGISTRATION_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_______________________________________________
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
33cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //_______________________________________________
36cdf0e10cSrcweir // namespace
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace comphelper{
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //_______________________________________________
41cdf0e10cSrcweir // declaration
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //_______________________________________________
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /** TODO    doc
46cdf0e10cSrcweir  */
47cdf0e10cSrcweir #define _COMPHELPER_COMPONENT_GETIMPLEMENTATIONENVIRONMENT                                                          \
48cdf0e10cSrcweir     extern "C" void SAL_CALL component_getImplementationEnvironment(const sal_Char**        ppEnvironmentTypeName,  \
49cdf0e10cSrcweir                                                                           uno_Environment** /* ppEnvironment */ )   \
50cdf0e10cSrcweir     {                                                                                                               \
51cdf0e10cSrcweir         *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;                                                \
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //_______________________________________________
55cdf0e10cSrcweir 
56cdf0e10cSrcweir /** TODO    doc
57cdf0e10cSrcweir  */
58cdf0e10cSrcweir #define _COMPHELPER_MULTIINSTANCEFACTORY(IMPLEMENTATIONNAME, SERVICENAMES, FACTORYMETHOD)   \
59cdf0e10cSrcweir     if (IMPLEMENTATIONNAME == sImplName)                                                    \
60cdf0e10cSrcweir         xFactory = ::cppu::createSingleFactory(xSMGR             ,                          \
61cdf0e10cSrcweir                                                IMPLEMENTATIONNAME,                          \
62cdf0e10cSrcweir                                                FACTORYMETHOD     ,                          \
63cdf0e10cSrcweir                                                SERVICENAMES      );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //_______________________________________________
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /** TODO    doc
68cdf0e10cSrcweir  */
69cdf0e10cSrcweir #define _COMPHELPER_ONEINSTANCEFACTORY(IMPLEMENTATIONNAME, SERVICENAMES, FACTORYMETHOD)     \
70cdf0e10cSrcweir     if (IMPLEMENTATIONNAME == sImplName)                                                    \
71cdf0e10cSrcweir         xFactory = ::cppu::createOneInstanceFactory(xSMGR             ,                     \
72cdf0e10cSrcweir                                                     IMPLEMENTATIONNAME,                     \
73cdf0e10cSrcweir                                                     FACTORYMETHOD     ,                     \
74cdf0e10cSrcweir                                                     SERVICENAMES      );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //_______________________________________________
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /** TODO    doc
79cdf0e10cSrcweir  */
80cdf0e10cSrcweir #define _COMPHELPER_COMPONENT_GETFACTORY(STATIC_INIT,FACTORYLIST)                                                                                               \
81cdf0e10cSrcweir     extern "C" void* SAL_CALL component_getFactory(const sal_Char* pImplementationName,                                                             \
82cdf0e10cSrcweir                                                          void*     pServiceManager    ,                                                             \
83cdf0e10cSrcweir                                                          void*     /* pRegistryKey */ )                                                             \
84cdf0e10cSrcweir     {                                                                                                                                               \
85cdf0e10cSrcweir         if (                                                                                                                                        \
86cdf0e10cSrcweir             (!pImplementationName) ||                                                                                                               \
87cdf0e10cSrcweir             (!pServiceManager    )                                                                                                                  \
88cdf0e10cSrcweir            )                                                                                                                                        \
89cdf0e10cSrcweir         return NULL;                                                                                                                                \
90cdf0e10cSrcweir                                                                                                                                                     \
91cdf0e10cSrcweir         STATIC_INIT                                                                                                                                 \
92cdf0e10cSrcweir                                                                                                                                                     \
93cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory >  xSMGR     = reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager);  \
94cdf0e10cSrcweir         css::uno::Reference< css::lang::XSingleServiceFactory > xFactory  ;                                                                         \
95cdf0e10cSrcweir         rtl::OUString                                           sImplName = ::rtl::OUString::createFromAscii(pImplementationName);                  \
96cdf0e10cSrcweir                                                                                                                                                     \
97cdf0e10cSrcweir         /* This parameter will expand to: */                                                                                                        \
98cdf0e10cSrcweir         /*  _COMPHELPER_xxxFACTORY(1)     */                                                                                                        \
99cdf0e10cSrcweir         /*  else                          */                                                                                                        \
100cdf0e10cSrcweir         /*  ...                           */                                                                                                        \
101cdf0e10cSrcweir         /*  else                          */                                                                                                        \
102cdf0e10cSrcweir         /*  _COMPHELPER_xxxFACTORY(n)     */                                                                                                        \
103cdf0e10cSrcweir         FACTORYLIST                                                                                                                                 \
104cdf0e10cSrcweir                                                                                                                                                     \
105cdf0e10cSrcweir         /* And if one of these checks was successfully => xFactory was set! */                                                                      \
106cdf0e10cSrcweir         if (xFactory.is())                                                                                                                          \
107cdf0e10cSrcweir         {                                                                                                                                           \
108cdf0e10cSrcweir             xFactory->acquire();                                                                                                                    \
109cdf0e10cSrcweir             return xFactory.get();                                                                                                                  \
110cdf0e10cSrcweir         }                                                                                                                                           \
111cdf0e10cSrcweir                                                                                                                                                     \
112cdf0e10cSrcweir         return NULL;                                                                                                                                \
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir } // namespace comphelper
116cdf0e10cSrcweir 
117cdf0e10cSrcweir #endif  //  #ifndef __COMPHELPER_REGISTRATION_HXX_
118