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 10f8e07b45SAndrew Rist * 11f8e07b45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12f8e07b45SAndrew Rist * 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. 19f8e07b45SAndrew Rist * 20f8e07b45SAndrew Rist *************************************************************/ 21f8e07b45SAndrew Rist 22f8e07b45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef __FRAMEWORK_MACROS_XSERVICEINFO_HXX_ 25cdf0e10cSrcweir #define __FRAMEWORK_MACROS_XSERVICEINFO_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 28cdf0e10cSrcweir // my own includes 29cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <general.h> 32cdf0e10cSrcweir 33cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34cdf0e10cSrcweir // interface includes 35cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp> 37cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 38cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 39cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42cdf0e10cSrcweir // other includes 43cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 45cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 46cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 47cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx> 48cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 49cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 50cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 51cdf0e10cSrcweir #include <comphelper/sequence.hxx> 52cdf0e10cSrcweir #include <rtl/ustring.hxx> 53cdf0e10cSrcweir #include <rtl/logfile.hxx> 54cdf0e10cSrcweir 55cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 56cdf0e10cSrcweir // namespace 57cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 58cdf0e10cSrcweir 59cdf0e10cSrcweir namespace framework{ 60cdf0e10cSrcweir 61cdf0e10cSrcweir /*_________________________________________________________________________________________________________________ 62cdf0e10cSrcweir 63cdf0e10cSrcweir macros for declaration and definition of XServiceInfo 64cdf0e10cSrcweir Please use follow public macros only! 65cdf0e10cSrcweir 66cdf0e10cSrcweir 1) DECLARE_XSERVICEINFO => use it to declare XServiceInfo in your header 67cdf0e10cSrcweir 2) DEFINE_XSERVICEINFO_MULTISERVICE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) => use it to define XServiceInfo for multi service mode 68cdf0e10cSrcweir 3) DEFINE_XSERVICEINFO_ONEINSTANCESERVICE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) => use it to define XServiceInfo for one instance service mode 69*07a3d7f1SPedro Giffuni 4) DEFINE_INIT_SERVICE( CLASS ) => use it to implement your own impl_initService() method, which is necessary for initializeing object by using his own reference! 70cdf0e10cSrcweir 71cdf0e10cSrcweir _________________________________________________________________________________________________________________*/ 72cdf0e10cSrcweir 73cdf0e10cSrcweir //***************************************************************************************************************** 74cdf0e10cSrcweir // private 75cdf0e10cSrcweir // implementation of XServiceInfo and helper functions 76cdf0e10cSrcweir //***************************************************************************************************************** 77cdf0e10cSrcweir #define PRIVATE_DEFINE_XSERVICEINFO_BASE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 78cdf0e10cSrcweir /*===========================================================================================================*/ \ 79cdf0e10cSrcweir /* XServiceInfo */ \ 80cdf0e10cSrcweir /*===========================================================================================================*/ \ 81cdf0e10cSrcweir ::rtl::OUString SAL_CALL CLASS::getImplementationName() throw( css::uno::RuntimeException ) \ 82cdf0e10cSrcweir { \ 83cdf0e10cSrcweir return impl_getStaticImplementationName(); \ 84cdf0e10cSrcweir } \ 85cdf0e10cSrcweir \ 86cdf0e10cSrcweir /*===========================================================================================================*/ \ 87cdf0e10cSrcweir /* XServiceInfo */ \ 88cdf0e10cSrcweir /*===========================================================================================================*/ \ 89cdf0e10cSrcweir sal_Bool SAL_CALL CLASS::supportsService( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ) \ 90cdf0e10cSrcweir { \ 91cdf0e10cSrcweir return ::comphelper::findValue(getSupportedServiceNames(), sServiceName, sal_True).getLength() != 0; \ 92cdf0e10cSrcweir } \ 93cdf0e10cSrcweir \ 94cdf0e10cSrcweir /*===========================================================================================================*/ \ 95cdf0e10cSrcweir /* XServiceInfo */ \ 96cdf0e10cSrcweir /*===========================================================================================================*/ \ 97cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL CLASS::getSupportedServiceNames() throw( css::uno::RuntimeException ) \ 98cdf0e10cSrcweir { \ 99cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); \ 100cdf0e10cSrcweir } \ 101cdf0e10cSrcweir \ 102cdf0e10cSrcweir /*===========================================================================================================*/ \ 103cdf0e10cSrcweir /* Helper for XServiceInfo */ \ 104cdf0e10cSrcweir /*===========================================================================================================*/ \ 105cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > CLASS::impl_getStaticSupportedServiceNames() \ 106cdf0e10cSrcweir { \ 107cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > seqServiceNames( 1 ); \ 108cdf0e10cSrcweir seqServiceNames.getArray() [0] = SERVICENAME ; \ 109cdf0e10cSrcweir return seqServiceNames; \ 110cdf0e10cSrcweir } \ 111cdf0e10cSrcweir \ 112cdf0e10cSrcweir /*===========================================================================================================*/ \ 113cdf0e10cSrcweir /* Helper for XServiceInfo */ \ 114cdf0e10cSrcweir /*===========================================================================================================*/ \ 115cdf0e10cSrcweir ::rtl::OUString CLASS::impl_getStaticImplementationName() \ 116cdf0e10cSrcweir { \ 117cdf0e10cSrcweir return IMPLEMENTATIONNAME ; \ 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir #define PRIVATE_DEFINE_XSERVICEINFO_OLDSTYLE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 121cdf0e10cSrcweir PRIVATE_DEFINE_XSERVICEINFO_BASE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 122cdf0e10cSrcweir /*===========================================================================================================*/ \ 123cdf0e10cSrcweir /* Helper for registry */ \ 124cdf0e10cSrcweir /* Attention: To avoid against wrong ref counts during our own initialize procedure, we must */ \ 125cdf0e10cSrcweir /* use right EXTERNAL handling of them. That's why you should do nothing in your ctor, which could*/ \ 126cdf0e10cSrcweir /* work on your ref count! All other things are allowed. Do work with your own reference - please */ \ 127cdf0e10cSrcweir /* use "impl_initService()" method. */ \ 128cdf0e10cSrcweir /*===========================================================================================================*/ \ 129cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL CLASS::impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception ) \ 130cdf0e10cSrcweir { \ 131cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework","Ocke.Janssen@sun.com",U2B(IMPLEMENTATIONNAME).getStr()); \ 132cdf0e10cSrcweir /* create new instance of service */ \ 133cdf0e10cSrcweir CLASS* pClass = new CLASS( xServiceManager ); \ 134cdf0e10cSrcweir /* hold it alive by increasing his ref count!!! */ \ 135cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xService( static_cast< XINTERFACECAST* >(pClass), css::uno::UNO_QUERY ); \ 136cdf0e10cSrcweir /* initialize new service instance ... he can use his own refcount ... we hold it! */ \ 137cdf0e10cSrcweir pClass->impl_initService(); \ 138cdf0e10cSrcweir /* return new created service as reference */ \ 139cdf0e10cSrcweir return xService; \ 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir #define PRIVATE_DEFINE_XSERVICEINFO_NEWSTYLE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 143cdf0e10cSrcweir PRIVATE_DEFINE_XSERVICEINFO_BASE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 144cdf0e10cSrcweir /*===========================================================================================================*/ \ 145cdf0e10cSrcweir /* Helper for registry */ \ 146cdf0e10cSrcweir /* Attention: To avoid against wrong ref counts during our own initialize procedure, we must */ \ 147cdf0e10cSrcweir /* use right EXTERNAL handling of them. That's why you should do nothing in your ctor, which could*/ \ 148cdf0e10cSrcweir /* work on your ref count! All other things are allowed. Do work with your own reference - please */ \ 149cdf0e10cSrcweir /* use "impl_initService()" method. */ \ 150cdf0e10cSrcweir /*===========================================================================================================*/ \ 151cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL CLASS::impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager )\ 152cdf0e10cSrcweir throw( css::uno::Exception ) \ 153cdf0e10cSrcweir { \ 154cdf0e10cSrcweir /* retrieve component context from the given service manager */ \ 155cdf0e10cSrcweir static const ::rtl::OUString PROP_DEFAULTCONTEXT = ::rtl::OUString::createFromAscii("DefaultContext"); \ 156cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xSMGRProps(xServiceManager, css::uno::UNO_QUERY_THROW); \ 157cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > xComponentContext; \ 158cdf0e10cSrcweir xSMGRProps->getPropertyValue( PROP_DEFAULTCONTEXT ) >>= xComponentContext; \ 159cdf0e10cSrcweir /* create new instance of service */ \ 160cdf0e10cSrcweir CLASS* pClass = new CLASS( xComponentContext ); \ 161cdf0e10cSrcweir /* hold it alive by increasing his ref count!!! */ \ 162cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xService( static_cast< XINTERFACECAST* >(pClass), css::uno::UNO_QUERY ); \ 163cdf0e10cSrcweir /* initialize new service instance ... he can use his own refcount ... we hold it! */ \ 164cdf0e10cSrcweir pClass->impl_initService(); \ 165cdf0e10cSrcweir /* return new created service as reference */ \ 166cdf0e10cSrcweir return xService; \ 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir //***************************************************************************************************************** 170cdf0e10cSrcweir // private 171cdf0e10cSrcweir // definition of helper function createFactory() for multiple services 172cdf0e10cSrcweir //***************************************************************************************************************** 173cdf0e10cSrcweir #define PRIVATE_DEFINE_SINGLEFACTORY( CLASS ) \ 174cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > CLASS::impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) \ 175cdf0e10cSrcweir { \ 176cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xReturn ( cppu::createSingleFactory ( xServiceManager , \ 177cdf0e10cSrcweir CLASS::impl_getStaticImplementationName() , \ 178cdf0e10cSrcweir CLASS::impl_createInstance , \ 179cdf0e10cSrcweir CLASS::impl_getStaticSupportedServiceNames() \ 180cdf0e10cSrcweir ) \ 181cdf0e10cSrcweir ); \ 182cdf0e10cSrcweir return xReturn; \ 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir //***************************************************************************************************************** 186cdf0e10cSrcweir // private 187cdf0e10cSrcweir // definition of helper function createFactory() for one instance services 188cdf0e10cSrcweir //***************************************************************************************************************** 189cdf0e10cSrcweir #define PRIVATE_DEFINE_ONEINSTANCEFACTORY( CLASS ) \ 190cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > CLASS::impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) \ 191cdf0e10cSrcweir { \ 192cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xReturn ( cppu::createOneInstanceFactory ( xServiceManager , \ 193cdf0e10cSrcweir CLASS::impl_getStaticImplementationName() , \ 194cdf0e10cSrcweir CLASS::impl_createInstance , \ 195cdf0e10cSrcweir CLASS::impl_getStaticSupportedServiceNames() \ 196cdf0e10cSrcweir ) \ 197cdf0e10cSrcweir ); \ 198cdf0e10cSrcweir return xReturn; \ 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir //***************************************************************************************************************** 202cdf0e10cSrcweir // public 203cdf0e10cSrcweir // declaration of XServiceInfo and helper functions 204cdf0e10cSrcweir //***************************************************************************************************************** 205cdf0e10cSrcweir #define DECLARE_XSERVICEINFO \ 206cdf0e10cSrcweir /* interface XServiceInfo */ \ 207cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName ( ) throw( css::uno::RuntimeException ); \ 208cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService ( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ); \ 209cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames ( ) throw( css::uno::RuntimeException ); \ 210cdf0e10cSrcweir /* Helper for XServiceInfo */ \ 211cdf0e10cSrcweir static css::uno::Sequence< ::rtl::OUString > SAL_CALL impl_getStaticSupportedServiceNames( ); \ 212cdf0e10cSrcweir static ::rtl::OUString SAL_CALL impl_getStaticImplementationName ( ); \ 213cdf0e10cSrcweir /* Helper for registry */ \ 214cdf0e10cSrcweir static css::uno::Reference< css::uno::XInterface > SAL_CALL impl_createInstance ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception ); \ 215cdf0e10cSrcweir static css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL impl_createFactory ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ); \ 216cdf0e10cSrcweir /* Helper for initialization of service by using own reference! */ \ 217cdf0e10cSrcweir virtual void SAL_CALL impl_initService ( ); \ 218cdf0e10cSrcweir 219cdf0e10cSrcweir //***************************************************************************************************************** 220cdf0e10cSrcweir // public 221cdf0e10cSrcweir // implementation of XServiceInfo 222cdf0e10cSrcweir //***************************************************************************************************************** 223cdf0e10cSrcweir #define DEFINE_XSERVICEINFO_MULTISERVICE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 224cdf0e10cSrcweir PRIVATE_DEFINE_XSERVICEINFO_OLDSTYLE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 225cdf0e10cSrcweir PRIVATE_DEFINE_SINGLEFACTORY( CLASS ) 226cdf0e10cSrcweir 227cdf0e10cSrcweir #define DEFINE_XSERVICEINFO_ONEINSTANCESERVICE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 228cdf0e10cSrcweir PRIVATE_DEFINE_XSERVICEINFO_OLDSTYLE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 229cdf0e10cSrcweir PRIVATE_DEFINE_ONEINSTANCEFACTORY( CLASS ) 230cdf0e10cSrcweir 231cdf0e10cSrcweir #define DEFINE_XSERVICEINFO_MULTISERVICE_2( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 232cdf0e10cSrcweir PRIVATE_DEFINE_XSERVICEINFO_NEWSTYLE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 233cdf0e10cSrcweir PRIVATE_DEFINE_SINGLEFACTORY( CLASS ) 234cdf0e10cSrcweir 235cdf0e10cSrcweir #define DEFINE_XSERVICEINFO_ONEINSTANCESERVICE_2( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 236cdf0e10cSrcweir PRIVATE_DEFINE_XSERVICEINFO_NEWSTYLE( CLASS, XINTERFACECAST, SERVICENAME, IMPLEMENTATIONNAME ) \ 237cdf0e10cSrcweir PRIVATE_DEFINE_ONEINSTANCEFACTORY( CLASS ) 238cdf0e10cSrcweir 239cdf0e10cSrcweir //***************************************************************************************************************** 240cdf0e10cSrcweir // public 241cdf0e10cSrcweir // implementation of service initialize! 242cdf0e10cSrcweir // example of using: DEFINE_INIT_SERVICE( MyClassName, 243cdf0e10cSrcweir // { 244cdf0e10cSrcweir // ... 245cdf0e10cSrcweir // Reference< XInterface > xThis( this, UNO_QUERY ); 246cdf0e10cSrcweir // myMember* pMember = new myMember( xThis ); 247cdf0e10cSrcweir // ... 248cdf0e10cSrcweir // } 249cdf0e10cSrcweir // ) 250cdf0e10cSrcweir //***************************************************************************************************************** 251cdf0e10cSrcweir #define DEFINE_INIT_SERVICE( CLASS, FUNCTIONBODY ) \ 252cdf0e10cSrcweir void SAL_CALL CLASS::impl_initService() \ 253cdf0e10cSrcweir { \ 254cdf0e10cSrcweir FUNCTIONBODY \ 255cdf0e10cSrcweir } 256cdf0e10cSrcweir 257cdf0e10cSrcweir #define DEFINE_INIT_SERVICE_WITH_BASECLASS( CLASS, BASECLASS, FUNCTIONBODY ) \ 258cdf0e10cSrcweir void SAL_CALL CLASS::impl_initService() \ 259cdf0e10cSrcweir { \ 260cdf0e10cSrcweir BASECLASS::impl_initService(); \ 261cdf0e10cSrcweir { \ 262cdf0e10cSrcweir FUNCTIONBODY \ 263cdf0e10cSrcweir } \ 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir } // namespace framework 267cdf0e10cSrcweir 268cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_MACROS_XSERVICEINFO_HXX_ 269