1*2d785d7eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2d785d7eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2d785d7eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2d785d7eSAndrew Rist * distributed with this work for additional information 6*2d785d7eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2d785d7eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2d785d7eSAndrew Rist * "License"); you may not use this file except in compliance 9*2d785d7eSAndrew Rist * with the License. You may obtain a copy of the License at 10*2d785d7eSAndrew Rist * 11*2d785d7eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2d785d7eSAndrew Rist * 13*2d785d7eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2d785d7eSAndrew Rist * software distributed under the License is distributed on an 15*2d785d7eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2d785d7eSAndrew Rist * KIND, either express or implied. See the License for the 17*2d785d7eSAndrew Rist * specific language governing permissions and limitations 18*2d785d7eSAndrew Rist * under the License. 19*2d785d7eSAndrew Rist * 20*2d785d7eSAndrew Rist *************************************************************/ 21*2d785d7eSAndrew Rist 22*2d785d7eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef FORMS_MODULE_INCLUDE_CONTEXT 25cdf0e10cSrcweir #error "not to be included directly! use 'foo_module.hxx instead'!" 26cdf0e10cSrcweir #endif 27cdf0e10cSrcweir 28cdf0e10cSrcweir #ifndef FORMS_MODULE_NAMESPACE 29cdf0e10cSrcweir #error "set FORMS_MODULE_NAMESPACE to your namespace identifier!" 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <osl/mutex.hxx> 33cdf0e10cSrcweir #include <tools/resid.hxx> 34cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 36cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 37cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 38cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 39cdf0e10cSrcweir #include <rtl/string.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //......................................................................... 42cdf0e10cSrcweir namespace FORMS_MODULE_NAMESPACE 43cdf0e10cSrcweir { 44cdf0e10cSrcweir //......................................................................... 45cdf0e10cSrcweir 46cdf0e10cSrcweir typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation) 47cdf0e10cSrcweir ( 48cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rServiceManager, 49cdf0e10cSrcweir const ::rtl::OUString & _rComponentName, 50cdf0e10cSrcweir ::cppu::ComponentInstantiation _pCreateFunction, 51cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::rtl::OUString > & _rServiceNames, 52cdf0e10cSrcweir rtl_ModuleCount* _pModuleCounter 53cdf0e10cSrcweir ); 54cdf0e10cSrcweir 55cdf0e10cSrcweir //========================================================================= 56cdf0e10cSrcweir //= OFormsModule 57cdf0e10cSrcweir //========================================================================= 58cdf0e10cSrcweir class OFormsModule 59cdf0e10cSrcweir { 60cdf0e10cSrcweir private: 61cdf0e10cSrcweir OFormsModule(); 62cdf0e10cSrcweir // not implemented. OFormsModule is a static class 63cdf0e10cSrcweir 64cdf0e10cSrcweir protected: 65cdf0e10cSrcweir // auto registration administration 66cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString >* 67cdf0e10cSrcweir s_pImplementationNames; 68cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > >* 69cdf0e10cSrcweir s_pSupportedServices; 70cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< sal_Int64 >* 71cdf0e10cSrcweir s_pCreationFunctionPointers; 72cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< sal_Int64 >* 73cdf0e10cSrcweir s_pFactoryFunctionPointers; 74cdf0e10cSrcweir 75cdf0e10cSrcweir public: 76cdf0e10cSrcweir /** register a component implementing a service with the given data. 77cdf0e10cSrcweir @param _rImplementationName 78cdf0e10cSrcweir the implementation name of the component 79cdf0e10cSrcweir @param _rServiceNames 80cdf0e10cSrcweir the services the component supports 81cdf0e10cSrcweir @param _pCreateFunction 82cdf0e10cSrcweir a function for creating an instance of the component 83cdf0e10cSrcweir @param _pFactoryFunction 84cdf0e10cSrcweir a function for creating a factory for that component 85cdf0e10cSrcweir @see revokeComponent 86cdf0e10cSrcweir */ 87cdf0e10cSrcweir static void registerComponent( 88cdf0e10cSrcweir const ::rtl::OUString& _rImplementationName, 89cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames, 90cdf0e10cSrcweir ::cppu::ComponentInstantiation _pCreateFunction, 91cdf0e10cSrcweir FactoryInstantiation _pFactoryFunction); 92cdf0e10cSrcweir 93cdf0e10cSrcweir /** revoke the registration for the specified component 94cdf0e10cSrcweir @param _rImplementationName 95cdf0e10cSrcweir the implementation name of the component 96cdf0e10cSrcweir */ 97cdf0e10cSrcweir static void revokeComponent( 98cdf0e10cSrcweir const ::rtl::OUString& _rImplementationName); 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** creates a Factory for the component with the given implementation name. 101cdf0e10cSrcweir <p>Usually used from within component_getFactory.<p/> 102cdf0e10cSrcweir @param _rxServiceManager 103cdf0e10cSrcweir a pointer to an XMultiServiceFactory interface as got in component_getFactory 104cdf0e10cSrcweir @param _pImplementationName 105cdf0e10cSrcweir the implementation name of the component 106cdf0e10cSrcweir @return 107cdf0e10cSrcweir the XInterface access to a factory for the component 108cdf0e10cSrcweir */ 109cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory( 110cdf0e10cSrcweir const ::rtl::OUString& _rImplementationName, 111cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager 112cdf0e10cSrcweir ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir private: 115cdf0e10cSrcweir /** ensure that the impl class exists 116cdf0e10cSrcweir @precond m_aMutex is guarded when this method gets called 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir static void ensureImpl(); 119cdf0e10cSrcweir }; 120cdf0e10cSrcweir 121cdf0e10cSrcweir //========================================================================== 122cdf0e10cSrcweir //= OMultiInstanceAutoRegistration 123cdf0e10cSrcweir //========================================================================== 124cdf0e10cSrcweir template <class TYPE> 125cdf0e10cSrcweir class OMultiInstanceAutoRegistration 126cdf0e10cSrcweir { 127cdf0e10cSrcweir public: 128cdf0e10cSrcweir /** automatically registeres a multi instance component 129cdf0e10cSrcweir <p>Assumed that the template argument has the three methods 130cdf0e10cSrcweir <ul> 131cdf0e10cSrcweir <li><code>static ::rtl::OUString getImplementationName_Static()</code><li/> 132cdf0e10cSrcweir <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><li/> 133cdf0e10cSrcweir <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 134cdf0e10cSrcweir Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code> 135cdf0e10cSrcweir </li> 136cdf0e10cSrcweir <ul/> 137cdf0e10cSrcweir the instantiation of this object will automatically register the class via <method>OFormsModule::registerComponent</method>. 138cdf0e10cSrcweir <p/> 139cdf0e10cSrcweir <p>The factory creation function used is <code>::cppu::createSingleFactory</code>.</p> 140cdf0e10cSrcweir 141cdf0e10cSrcweir @see OOneInstanceAutoRegistration 142cdf0e10cSrcweir */ 143cdf0e10cSrcweir OMultiInstanceAutoRegistration(); 144cdf0e10cSrcweir ~OMultiInstanceAutoRegistration(); 145cdf0e10cSrcweir }; 146cdf0e10cSrcweir 147cdf0e10cSrcweir template <class TYPE> OMultiInstanceAutoRegistration()148cdf0e10cSrcweir OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration() 149cdf0e10cSrcweir { 150cdf0e10cSrcweir OFormsModule::registerComponent( 151cdf0e10cSrcweir TYPE::getImplementationName_Static(), 152cdf0e10cSrcweir TYPE::getSupportedServiceNames_Static(), 153cdf0e10cSrcweir TYPE::Create, 154cdf0e10cSrcweir ::cppu::createSingleFactory 155cdf0e10cSrcweir ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir template <class TYPE> ~OMultiInstanceAutoRegistration()159cdf0e10cSrcweir OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration() 160cdf0e10cSrcweir { 161cdf0e10cSrcweir OFormsModule::revokeComponent(TYPE::getImplementationName_Static()); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir //========================================================================== 165cdf0e10cSrcweir //= OOneInstanceAutoRegistration 166cdf0e10cSrcweir //========================================================================== 167cdf0e10cSrcweir template <class TYPE> 168cdf0e10cSrcweir class OOneInstanceAutoRegistration 169cdf0e10cSrcweir { 170cdf0e10cSrcweir public: 171cdf0e10cSrcweir /** automatically registeres a single instance component 172cdf0e10cSrcweir <p>Assumed that the template argument has the three methods 173cdf0e10cSrcweir <ul> 174cdf0e10cSrcweir <li><code>static ::rtl::OUString getImplementationName_Static()</code><li/> 175cdf0e10cSrcweir <li><code>static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static()</code><li/> 176cdf0e10cSrcweir <li><code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 177cdf0e10cSrcweir Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code> 178cdf0e10cSrcweir </li> 179cdf0e10cSrcweir <ul/> 180cdf0e10cSrcweir the instantiation of this object will automatically register the class via <method>OFormsModule::registerComponent</method>. 181cdf0e10cSrcweir <p/> 182cdf0e10cSrcweir The factory creation function used is <code>::cppu::createOneInstanceFactory</code>. 183cdf0e10cSrcweir @see OOneInstanceAutoRegistration 184cdf0e10cSrcweir */ 185cdf0e10cSrcweir OOneInstanceAutoRegistration(); 186cdf0e10cSrcweir ~OOneInstanceAutoRegistration(); 187cdf0e10cSrcweir }; 188cdf0e10cSrcweir 189cdf0e10cSrcweir template <class TYPE> OOneInstanceAutoRegistration()190cdf0e10cSrcweir OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration() 191cdf0e10cSrcweir { 192cdf0e10cSrcweir OFormsModule::registerComponent( 193cdf0e10cSrcweir TYPE::getImplementationName_Static(), 194cdf0e10cSrcweir TYPE::getSupportedServiceNames_Static(), 195cdf0e10cSrcweir TYPE::Create, 196cdf0e10cSrcweir ::cppu::createOneInstanceFactory 197cdf0e10cSrcweir ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir template <class TYPE> ~OOneInstanceAutoRegistration()201cdf0e10cSrcweir OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration() 202cdf0e10cSrcweir { 203cdf0e10cSrcweir OFormsModule::revokeComponent(TYPE::getImplementationName_Static()); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir //========================================================================== 207cdf0e10cSrcweir //= helper for classes implementing the service handling via 208cdf0e10cSrcweir //= OMultiInstanceAutoRegistration or OOneInstanceAutoRegistration 209cdf0e10cSrcweir //========================================================================== 210cdf0e10cSrcweir #define DECLARE_SERVICE_REGISTRATION( classname ) \ 211cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \ 212cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); \ 213cdf0e10cSrcweir \ 214cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_Static(); \ 215cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static(); \ 216cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory ); \ 217cdf0e10cSrcweir \ 218cdf0e10cSrcweir friend class OOneInstanceAutoRegistration< classname >; \ 219cdf0e10cSrcweir friend class OMultiInstanceAutoRegistration< classname >; \ 220cdf0e10cSrcweir 221cdf0e10cSrcweir #define IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \ 222cdf0e10cSrcweir \ 223cdf0e10cSrcweir ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw ( RuntimeException ) \ 224cdf0e10cSrcweir { return getImplementationName_Static(); } \ 225cdf0e10cSrcweir \ 226cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw (RuntimeException) \ 227cdf0e10cSrcweir { \ 228cdf0e10cSrcweir return ::comphelper::concatSequences( \ 229cdf0e10cSrcweir getAggregateServiceNames(), \ 230cdf0e10cSrcweir getSupportedServiceNames_Static() \ 231cdf0e10cSrcweir ); \ 232cdf0e10cSrcweir } \ 233cdf0e10cSrcweir \ 234cdf0e10cSrcweir ::rtl::OUString SAL_CALL classname::getImplementationName_Static() \ 235cdf0e10cSrcweir { return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.forms."#classname ) ); } \ 236cdf0e10cSrcweir \ 237cdf0e10cSrcweir Reference< XInterface > SAL_CALL classname::Create( const Reference< XMultiServiceFactory >& _rxFactory ) \ 238cdf0e10cSrcweir { return static_cast< XServiceInfo* >( new classname( _rxFactory ) ); } \ 239cdf0e10cSrcweir \ 240cdf0e10cSrcweir 241cdf0e10cSrcweir #define IMPLEMENT_SERVICE_REGISTRATION_1( classname, baseclass, service1 ) \ 242cdf0e10cSrcweir IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \ 243cdf0e10cSrcweir \ 244cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \ 245cdf0e10cSrcweir { \ 246cdf0e10cSrcweir Sequence< ::rtl::OUString > aOwnNames( 1 ); \ 247cdf0e10cSrcweir aOwnNames[ 0 ] = service1; \ 248cdf0e10cSrcweir \ 249cdf0e10cSrcweir return ::comphelper::concatSequences( \ 250cdf0e10cSrcweir baseclass::getSupportedServiceNames_Static(), \ 251cdf0e10cSrcweir aOwnNames \ 252cdf0e10cSrcweir ); \ 253cdf0e10cSrcweir } \ 254cdf0e10cSrcweir 255cdf0e10cSrcweir #define IMPLEMENT_SERVICE_REGISTRATION_2( classname, baseclass, service1, service2 ) \ 256cdf0e10cSrcweir IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \ 257cdf0e10cSrcweir \ 258cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \ 259cdf0e10cSrcweir { \ 260cdf0e10cSrcweir Sequence< ::rtl::OUString > aOwnNames( 2 ); \ 261cdf0e10cSrcweir aOwnNames[ 0 ] = service1; \ 262cdf0e10cSrcweir aOwnNames[ 1 ] = service2; \ 263cdf0e10cSrcweir \ 264cdf0e10cSrcweir return ::comphelper::concatSequences( \ 265cdf0e10cSrcweir baseclass::getSupportedServiceNames_Static(), \ 266cdf0e10cSrcweir aOwnNames \ 267cdf0e10cSrcweir ); \ 268cdf0e10cSrcweir } \ 269cdf0e10cSrcweir 270cdf0e10cSrcweir #define IMPLEMENT_SERVICE_REGISTRATION_7( classname, baseclass, service1, service2, service3, service4 , service5, service6, service7 ) \ 271cdf0e10cSrcweir IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \ 272cdf0e10cSrcweir \ 273cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \ 274cdf0e10cSrcweir { \ 275cdf0e10cSrcweir Sequence< ::rtl::OUString > aOwnNames( 7 ); \ 276cdf0e10cSrcweir aOwnNames[ 0 ] = service1; \ 277cdf0e10cSrcweir aOwnNames[ 1 ] = service2; \ 278cdf0e10cSrcweir aOwnNames[ 2 ] = service3; \ 279cdf0e10cSrcweir aOwnNames[ 3 ] = service4; \ 280cdf0e10cSrcweir aOwnNames[ 4 ] = service5; \ 281cdf0e10cSrcweir aOwnNames[ 5 ] = service6; \ 282cdf0e10cSrcweir aOwnNames[ 6 ] = service7; \ 283cdf0e10cSrcweir \ 284cdf0e10cSrcweir return ::comphelper::concatSequences( \ 285cdf0e10cSrcweir baseclass::getSupportedServiceNames_Static(), \ 286cdf0e10cSrcweir aOwnNames \ 287cdf0e10cSrcweir ); \ 288cdf0e10cSrcweir } \ 289cdf0e10cSrcweir 290cdf0e10cSrcweir #define IMPLEMENT_SERVICE_REGISTRATION_8( classname, baseclass, service1, service2, service3, service4 , service5, service6, service7, service8 ) \ 291cdf0e10cSrcweir IMPLEMENT_SERVICE_REGISTRATION_BASE( classname, baseclass ) \ 292cdf0e10cSrcweir \ 293cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames_Static() \ 294cdf0e10cSrcweir { \ 295cdf0e10cSrcweir Sequence< ::rtl::OUString > aOwnNames( 8 ); \ 296cdf0e10cSrcweir aOwnNames[ 0 ] = service1; \ 297cdf0e10cSrcweir aOwnNames[ 1 ] = service2; \ 298cdf0e10cSrcweir aOwnNames[ 2 ] = service3; \ 299cdf0e10cSrcweir aOwnNames[ 3 ] = service4; \ 300cdf0e10cSrcweir aOwnNames[ 4 ] = service5; \ 301cdf0e10cSrcweir aOwnNames[ 5 ] = service6; \ 302cdf0e10cSrcweir aOwnNames[ 6 ] = service7; \ 303cdf0e10cSrcweir aOwnNames[ 6 ] = service8; \ 304cdf0e10cSrcweir \ 305cdf0e10cSrcweir return ::comphelper::concatSequences( \ 306cdf0e10cSrcweir baseclass::getSupportedServiceNames_Static(), \ 307cdf0e10cSrcweir aOwnNames \ 308cdf0e10cSrcweir ); \ 309cdf0e10cSrcweir } \ 310cdf0e10cSrcweir 311cdf0e10cSrcweir //......................................................................... 312cdf0e10cSrcweir } // namespace FORMS_MODULE_NAMESPACE 313cdf0e10cSrcweir //......................................................................... 314