1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_ 29 #define __FRAMEWORK_MACROS_REGISTRATION_HXX_ 30 31 //_________________________________________________________________________________________________________________ 32 // my own includes 33 //_________________________________________________________________________________________________________________ 34 35 #include <macros/debug.hxx> 36 37 //_________________________________________________________________________________________________________________ 38 // interface includes 39 //_________________________________________________________________________________________________________________ 40 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 41 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 42 43 //_________________________________________________________________________________________________________________ 44 // other includes 45 //_________________________________________________________________________________________________________________ 46 47 //_________________________________________________________________________________________________________________ 48 // namespace 49 //_________________________________________________________________________________________________________________ 50 51 //namespace framework{ 52 53 /*_________________________________________________________________________________________________________________ 54 55 macros for registration of services 56 Please use follow public macros only! 57 58 IFFACTORY( CLASS ) => use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES ) 59 COMPONENTGETIMPLEMENTATIONENVIRONMENT => use it to define exported function component_getImplementationEnvironment() 60 COMPONENTGETFACTORY( IFFACTORIES ) => use it to define exported function component_getFactory() 61 62 _________________________________________________________________________________________________________________*/ 63 64 //***************************************************************************************************************** 65 // public 66 // use it as parameter for COMPONENT_GETFACTORY( IFFACTORIES ) 67 //***************************************************************************************************************** 68 #define IFFACTORY( CLASS ) \ 69 /* If searched name found ... */ \ 70 /* You can't add some statements before follow line ... Here can be an ELSE-statement! */ \ 71 if ( CLASS::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) ) \ 72 { \ 73 LOG_REGISTRATION_GETFACTORY( "\t\tImplementationname found - try to create factory! ...\n" ) \ 74 /* ... then create right factory for this service. */ \ 75 /* xFactory and xServiceManager are local variables of method which use this macro. */ \ 76 xFactory = CLASS::impl_createFactory( xServiceManager ); \ 77 } 78 79 //***************************************************************************************************************** 80 // public 81 // define helper to get information about service environment 82 //***************************************************************************************************************** 83 #define COMPONENTGETIMPLEMENTATIONENVIRONMENT \ 84 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvironmentTypeName , \ 85 uno_Environment** ) \ 86 { \ 87 *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ; \ 88 } 89 90 //***************************************************************************************************************** 91 // public 92 // define method to instanciate new services 93 //***************************************************************************************************************** 94 #define COMPONENTGETFACTORY( IFFACTORIES ) \ 95 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char* pImplementationName , \ 96 void* pServiceManager , \ 97 void* /*pRegistryKey*/ ) \ 98 { \ 99 LOG_REGISTRATION_GETFACTORY( "\t[start]\n" ) \ 100 /* Set default return value for this operation - if it failed. */ \ 101 void* pReturn = NULL ; \ 102 if ( \ 103 ( pImplementationName != NULL ) && \ 104 ( pServiceManager != NULL ) \ 105 ) \ 106 { \ 107 LOG_REGISTRATION_GETFACTORY( "\t\tpImplementationName and pServiceManager are valid ...\n" ) \ 108 /* Define variables which are used in following macros. */ \ 109 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory ; \ 110 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager ; \ 111 xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ; \ 112 /* These parameter will expand to */ \ 113 /* "IF_NAME_CREATECOMPONENTFACTORY(a) */ \ 114 /* else */ \ 115 /* ... */ \ 116 /* else */ \ 117 /* IF_NAME_CREATECOMPONENTFACTORY(z)" */ \ 118 IFFACTORIES \ 119 /* Factory is valid, if service was found. */ \ 120 if ( xFactory.is() == sal_True ) \ 121 { \ 122 LOG_REGISTRATION_GETFACTORY( "\t\t\txFactory valid - service was found ...\n" ) \ 123 xFactory->acquire(); \ 124 pReturn = xFactory.get(); \ 125 } \ 126 } \ 127 LOG_REGISTRATION_GETFACTORY( "\t[end]\n" ) \ 128 /* Return with result of this operation. */ \ 129 return pReturn ; \ 130 } 131 132 //} // namespace framework 133 134 #endif // #ifndef __FRAMEWORK_MACROS_REGISTRATION_HXX_ 135