1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
21 #define __FRAMEWORK_MACROS_REGISTRATION_HXX_
23 #include <macros/debug.hxx>
25 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 //namespace framework{
30 /*_________________________________________________________________________________________________________________
32 macros for registration of services
33 Please use follow public macros only!
35 IFFACTORY( CLASS ) => use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
36 COMPONENTGETFACTORY( LIB, IFFACTORIES ) => use it to define exported function LIB_component_getFactory()
38 _________________________________________________________________________________________________________________*/
40 //*****************************************************************************************************************
42 // use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES )
43 //*****************************************************************************************************************
44 #define IFFACTORY( CLASS ) \
45 /* If searched name found ... */ \
46 /* You can't add some statements before follow line ... Here can be an ELSE-statement! */ \
47 if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \
49 LOG_REGISTRATION_GETFACTORY( "\t\tImplementationname found - try to create factory! ...\n" ) \
50 /* ... then create right factory for this service. */ \
51 /* xFactory and xServiceManager are local variables of method which use this macro. */ \
52 xFactory = CLASS::impl_createFactory( xServiceManager ); \
55 //*****************************************************************************************************************
57 // define method to instanciate new services
58 //*****************************************************************************************************************
59 #define COMPONENTGETFACTORY( LIB, IFFACTORIES ) \
60 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL LIB##_component_getFactory( const sal_Char* pImplementationName, \
61 void* pServiceManager , \
62 void* /*pRegistryKey*/ ) \
64 LOG_REGISTRATION_GETFACTORY( "\t[start]\n" ) \
65 /* Set default return value for this operation - if it failed. */ \
66 void* pReturn = NULL ; \
68 ( pImplementationName != NULL ) && \
69 ( pServiceManager != NULL ) \
72 LOG_REGISTRATION_GETFACTORY( "\t\tpImplementationName and pServiceManager are valid ...\n" ) \
73 /* Define variables which are used in following macros. */ \
74 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xFactory ; \
75 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager ; \
76 xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ; \
77 /* These parameter will expand to */ \
78 /* "IF_NAME_CREATECOMPONENTFACTORY(a) */ \
82 /* IF_NAME_CREATECOMPONENTFACTORY(z)" */ \
84 /* Factory is valid, if service was found. */ \
85 if ( xFactory.is() == sal_True ) \
87 LOG_REGISTRATION_GETFACTORY( "\t\t\txFactory valid - service was found ...\n" ) \
88 xFactory->acquire(); \
89 pReturn = xFactory.get(); \
92 LOG_REGISTRATION_GETFACTORY( "\t[end]\n" ) \
93 /* Return with result of this operation. */ \
97 //} // namespace framework
99 #endif // #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */