LibreOffice Module comphelper (master)  1
componentmodule.cxx
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 
21 
22 #include <vector>
23 
24 namespace comphelper
25 {
26 
27  using namespace ::cppu;
28  using ::com::sun::star::uno::Sequence;
29  using ::com::sun::star::uno::RuntimeException;
30  using ::com::sun::star::uno::Reference;
31  using ::com::sun::star::uno::XInterface;
32 
33  typedef std::vector< ComponentDescription > ComponentDescriptions;
34 
38  {
39  public:
40  ComponentDescriptions m_aRegisteredComponents;
41 
42  OModuleImpl();
43  };
44 
46  {
47  }
48 
50  : m_pImpl(new OModuleImpl)
51  {
52  }
53 
55  {
56  }
57 
59  {
60  ::osl::MutexGuard aGuard( m_aMutex );
61  if ( !m_pImpl )
62  throw RuntimeException();
63 
64  m_pImpl->m_aRegisteredComponents.push_back( _rComp );
65  }
66 
67  void OModule::registerImplementation( const OUString& _rImplementationName, const css::uno::Sequence< OUString >& _rServiceNames,
68  ::cppu::ComponentFactoryFunc _pCreateFunction )
69  {
70  ComponentDescription aComponent( _rImplementationName, _rServiceNames, _pCreateFunction, ::cppu::createSingleComponentFactory );
71  registerImplementation( aComponent );
72  }
73 
74  void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
75  {
77  OUString::createFromAscii( _pImplementationName ) ) );
78  return xFactory.get();
79  }
80 
81  Reference< XInterface > OModule::getComponentFactory( const OUString& _rImplementationName )
82  {
84 
85  for (const auto& rComponent : m_pImpl->m_aRegisteredComponents)
86  {
87  if ( rComponent.sImplementationName == _rImplementationName )
88  {
89  xReturn = rComponent.pFactoryCreationFunc(
90  rComponent.pComponentCreationFunc,
91  rComponent.sImplementationName,
92  rComponent.aSupportedServices,
93  nullptr
94  );
95  if ( xReturn.is() )
96  {
97  xReturn->acquire();
98  return xReturn.get();
99  }
100  }
101  }
102 
103  return nullptr;
104  }
105 
106 } // namespace comphelper
107 
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ComponentDescriptions m_aRegisteredComponents
css::uno::Reference< css::uno::XInterface >(SAL_CALL *ComponentFactoryFunc)(css CPPUHELPER_DLLPUBLIC css::uno::Reference< css::lang::XSingleComponentFactory > SAL_CALL createSingleComponentFactory(ComponentFactoryFunc fptr,::rtl::OUString const &rImplementationName, css::uno::Sequence< ::rtl::OUString > const &rServiceNames, rtl_ModuleCount *pModCount=NULL)
OModule()
access safety
char sal_Char
css::uno::Reference< css::uno::XInterface > getComponentFactory(const OUString &_rImplementationName)
creates a Factory for the component with the given implementation name.
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.
implementation for OModule.
std::vector< ComponentDescription > ComponentDescriptions
std::unique_ptr< OModuleImpl > m_pImpl