bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / inc / componentmodule.hxx
blob899c0f9e6315d133d23cd9db374c65f75c185188
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_INC_COMPONENTMODULE_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_INC_COMPONENTMODULE_HXX
23 /** you may find this file helpful if you implement a component (in its own library) which can't use
24 the usual infrastructure.<br/>
25 More precise, you find helper classes to ease the use of resources and the registration of services.
28 #include <osl/mutex.hxx>
29 #include <unotools/resmgr.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 <vector>
38 namespace compmodule
41 typedef css::uno::Reference< css::lang::XSingleServiceFactory > (*FactoryInstantiation)
43 const css::uno::Reference< css::lang::XMultiServiceFactory >& _rServiceManager,
44 const OUString & _rComponentName,
45 ::cppu::ComponentInstantiation _pCreateFunction,
46 const css::uno::Sequence< OUString > & _rServiceNames,
47 rtl_ModuleCount*
50 class OModule
52 private:
53 OModule() = delete; //TODO: get rid of this class
55 protected:
56 // auto registration administration
57 static std::vector< OUString >*
58 s_pImplementationNames;
59 static std::vector< css::uno::Sequence< OUString > >*
60 s_pSupportedServices;
61 static std::vector< cppu::ComponentInstantiation >*
62 s_pCreationFunctionPointers;
63 static std::vector< FactoryInstantiation >*
64 s_pFactoryFunctionPointers;
66 public:
67 /** register a component implementing a service with the given data.
68 @param _rImplementationName
69 the implementation name of the component
70 @param _rServiceNames
71 the services the component supports
72 @param _pCreateFunction
73 a function for creating an instance of the component
74 @param _pFactoryFunction
75 a function for creating a factory for that component
76 @see revokeComponent
78 static void registerComponent(
79 const OUString& _rImplementationName,
80 const css::uno::Sequence< OUString >& _rServiceNames,
81 ::cppu::ComponentInstantiation _pCreateFunction,
82 FactoryInstantiation _pFactoryFunction);
84 /** revoke the registration for the specified component
85 @param _rImplementationName
86 the implementation name of the component
88 static void revokeComponent(
89 const OUString& _rImplementationName);
91 /** creates a Factory for the component with the given implementation name.
92 <p>Usually used from within component_getFactory.<p/>
93 @param _rxServiceManager
94 a pointer to an XMultiServiceFactory interface as got in component_getFactory
95 @param _pImplementationName
96 the implementation name of the component
97 @return
98 the XInterface access to a factory for the component
100 static css::uno::Reference< css::uno::XInterface > getComponentFactory(
101 const OUString& _rImplementationName,
102 const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxServiceManager
106 // specialized ResId, using the resource locale provided by the global module
107 OUString ModuleRes(const char* pId);
109 template <class TYPE>
110 class OMultiInstanceAutoRegistration
112 public:
113 /** automatically registers a multi instance component
114 <p>Assumed that the template argument has the three methods
115 <ul>
116 <li><code>static OUString getImplementationName_Static()</code><li/>
117 <li><code>static css::uno::Sequence< OUString > getSupportedServiceNames_Static()</code><li/>
118 <li><code>static css::uno::Reference< css::uno::XInterface >
119 Create(const css::uno::Reference< css::lang::XMultiServiceFactory >&)</code>
120 </li>
121 <ul/>
122 the instantiation of this object will automatically register the class via <method>OModule::registerComponent</method>.
123 <p/>
124 The factory creation function used is <code>::cppu::createSingleFactory</code>.
126 OMultiInstanceAutoRegistration();
127 ~OMultiInstanceAutoRegistration();
130 template <class TYPE>
131 OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
133 OModule::registerComponent(
134 TYPE::getImplementationName_Static(),
135 TYPE::getSupportedServiceNames_Static(),
136 TYPE::Create,
137 ::cppu::createSingleFactory
141 template <class TYPE>
142 OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
144 OModule::revokeComponent(TYPE::getImplementationName_Static());
147 } // namespace compmodule
150 #endif // INCLUDED_EXTENSIONS_SOURCE_INC_COMPONENTMODULE_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */