LibreOffice Module comphelper (master)  1
componentmodule.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_COMPHELPER_COMPONENTMODULE_HXX
20 #define INCLUDED_COMPHELPER_COMPONENTMODULE_HXX
21 
23 
24 #include <com/sun/star/uno/Sequence.hxx>
25 
26 #include <cppuhelper/factory.hxx>
27 
28 #include <osl/mutex.hxx>
29 
30 #include <memory>
31 
32 
33 namespace comphelper
34 {
35 
36 
39  typedef css::uno::Reference< css::lang::XSingleComponentFactory > (*FactoryInstantiation)
40  (
41  ::cppu::ComponentFactoryFunc _pFactoryFunc,
42  OUString const& _rComponentName,
43  css::uno::Sequence< OUString > const & _rServiceNames,
44  rtl_ModuleCount*
45  );
46 
47 
48  //= ComponentDescription
49 
51  {
53  OUString const sImplementationName;
55  css::uno::Sequence< OUString > const aSupportedServices;
57  ::cppu::ComponentFactoryFunc const pComponentCreationFunc;
60 
62  const OUString& _rImplementationName,
63  const css::uno::Sequence< OUString >& _rSupportedServices,
64  ::cppu::ComponentFactoryFunc _pComponentCreationFunc,
65  FactoryInstantiation _pFactoryCreationFunc
66  )
67  :sImplementationName( _rImplementationName )
68  ,aSupportedServices( _rSupportedServices )
69  ,pComponentCreationFunc( _pComponentCreationFunc )
70  ,pFactoryCreationFunc( _pFactoryCreationFunc )
71  {
72  }
73  };
74 
75 
76  //= OModule
77 
78  class OModuleImpl;
80  {
81  private:
82  std::unique_ptr<OModuleImpl> m_pImpl;
83 
84  protected:
85  mutable ::osl::Mutex m_aMutex;
86 
87  public:
88  OModule();
89 
90  virtual ~OModule();
91 
102  void registerImplementation(
103  const OUString& _rImplementationName,
104  const css::uno::Sequence< OUString >& _rServiceNames,
105  ::cppu::ComponentFactoryFunc _pCreateFunction );
106 
109  void registerImplementation( const ComponentDescription& _rComp );
110 
118  css::uno::Reference< css::uno::XInterface > getComponentFactory(
119  const OUString& _rImplementationName );
120 
123  void* getComponentFactory( const sal_Char* _pImplementationName );
124 
125  private:
126  OModule( const OModule& ) = delete;
127  OModule& operator=( const OModule& ) = delete;
128  };
129 
130 
131  //= OAutoRegistration
132 
133  template <class TYPE>
135  {
136  public:
150  OAutoRegistration( OModule& _rModule );
151  };
152 
153  template <class TYPE>
155  {
156  _rModule.registerImplementation(
157  TYPE::getImplementationName_static(),
158  TYPE::getSupportedServiceNames_static(),
159  TYPE::Create
160  );
161  }
162 
163 } // namespace comphelper
164 
165 
166 #endif // INCLUDED_COMPHELPER_COMPONENTMODULE_HXX
167 
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString const sImplementationName
the implementation name of the component
char sal_Char
OAutoRegistration(OModule &_rModule)
automatically provides all component information to an OModule instance
css::uno::Reference< css::lang::XSingleComponentFactory >(* FactoryInstantiation)(::cppu::ComponentFactoryFunc _pFactoryFunc, OUString const &_rComponentName, css::uno::Sequence< OUString > const &_rServiceNames, rtl_ModuleCount *)
factory declaration
FactoryInstantiation const pFactoryCreationFunc
the function to create a factory for the component (usually cppu::createSingleComponentFactory) ...
css::uno::Sequence< OUString > const aSupportedServices
the services supported by the component implementation
::cppu::ComponentFactoryFunc const pComponentCreationFunc
the function to create an instance of the component
mutable::osl::Mutex m_aMutex
impl class. lives as long as at least one client for the module is registered
void registerImplementation(const OUString &_rImplementationName, const css::uno::Sequence< OUString > &_rServiceNames,::cppu::ComponentFactoryFunc _pCreateFunction)
register a component implementing a service with the given data.
#define COMPHELPER_DLLPUBLIC
std::unique_ptr< OModuleImpl > m_pImpl
ComponentDescription(const OUString &_rImplementationName, const css::uno::Sequence< OUString > &_rSupportedServices,::cppu::ComponentFactoryFunc _pComponentCreationFunc, FactoryInstantiation _pFactoryCreationFunc)