LCOV - code coverage report
Current view: top level - forms/source/inc - forms_module.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 7 7 100.0 %
Date: 2014-11-03 Functions: 20 20 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10