fw4spl
ExtensionPoint.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwRuntime/BundleElement.hpp"
10 #include "fwRuntime/config.hpp"
11 #include "fwRuntime/Extension.hpp"
12 #include "fwRuntime/Runtime.hpp"
13 
14 #include <fwCore/base.hpp>
15 
16 #include <boost/filesystem/path.hpp>
17 
18 #include <algorithm>
19 #include <iostream>
20 #include <string>
21 
22 namespace fwRuntime
23 {
24 struct Bundle;
25 
26 namespace io
27 {
28 struct BundleDescriptorReader;
29 struct Validator;
30 }
31 }
32 
33 namespace fwRuntime
34 {
35 
40 {
41  friend struct ::fwRuntime::io::BundleDescriptorReader;
42 
43  typedef Extension::Container ConfigurationElementContainer;
44 
51  const ConfigurationElementContainer getAllConfigurationElements() const
52  {
53  typedef std::back_insert_iterator< ConfigurationElementContainer > Inserter;
54 
55  ConfigurationElementContainer container;
56  Inserter inserter(container);
57 
58  getAllConfigurationElements<Inserter>( inserter );
59 
60  return container;
61  }
62 
70  template<typename OutputIterator>
71  void getAllConfigurationElements( OutputIterator& output ) const
72  {
73  // Retrieves all connected extensions.
74  typedef std::vector< std::shared_ptr< Extension > > ExtensionContainer;
75  typedef std::back_insert_iterator< ExtensionContainer > Inserter;
76 
77  ExtensionContainer extensions;
78  Inserter inserter(extensions);
79 
80  getAllExtensions( inserter );
81 
82  // Walk through the collected extensions to extract configuration elements.
83  for( ExtensionContainer::const_iterator i = extensions.begin(); i != extensions.end(); ++i )
84  {
85  std::shared_ptr< Extension > extension( *i );
86  if ( extension->isEnable() )
87  {
88  std::copy( extension->begin(), extension->end(), output);
89  }
90  OSLM_DEBUG_IF("getAllConfigurationElements for point=" << extension->getPoint() <<
91  " extension" << extension->getIdentifier() << "extension disabled", !extension->isEnable());
92  }
93  }
94 
101  template<typename OutputIterator>
102  void getAllExtensions( OutputIterator& output ) const
103  {
104  Runtime* rntm( Runtime::getDefault() );
105 
106  for( Runtime::ExtensionIterator i = rntm->extensionsBegin(); i != rntm->extensionsEnd(); ++i )
107  {
108  std::shared_ptr< Extension > extension( *i );
109  if( extension->getPoint() == m_id && extension->isEnable() == true
110  && extension->validate() == Extension::Valid
111  )
112  {
113  *output = extension;
114  ++output;
115  }
116  }
117  }
118 
124  FWRUNTIME_API const std::string& getIdentifier() const;
125 
131  FWRUNTIME_API std::shared_ptr< io::Validator > getExtensionValidator() const;
132 
133  protected:
134 
145  const std::shared_ptr<Bundle> bundle,
146  const std::string& id,
147  const boost::filesystem::path& schema);
148 
149  private:
150 
151  const std::string m_id;
152  // identifier
153  const ::boost::filesystem::path m_schema;
154  // contributed extensions
155  mutable std::shared_ptr< io::Validator > m_validator;
156 
162  void operator=(const ExtensionPoint&) noexcept;
163 
164 };
165 
166 } // namespace fwRuntime
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Definition: Runtime.cpp:286
Defines the runtime class.
Definition: Runtime.hpp:37
ExtensionContainer::iterator ExtensionIterator
Defines the extension container type.
Definition: Runtime.hpp:51
The extension passed the validation.
Definition: Extension.hpp:41
Implements the base class for all element managed by a bundle.
#define OSLM_DEBUG_IF(message, cond)
Definition: spyLog.hpp:245
FWRUNTIME_API ExtensionIterator extensionsEnd()
Retrieves the iterator on the end of the extension collection.
Definition: Runtime.cpp:221
FWRUNTIME_API ExtensionIterator extensionsBegin()
Retrieves the iterator on the beginning of the extension collection.
Definition: Runtime.cpp:214
Defines the extension point class.
std::vector< std::shared_ptr< ConfigurationElement > > Container
Defines the configuration element container type.
void getAllConfigurationElements(OutputIterator &output) const
Retrieves all configuration elements contributed by extensions connected to the extension point insta...
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
const ConfigurationElementContainer getAllConfigurationElements() const
Retrieves all configuration elements contributed by extensions connected to the extension point insta...
void getAllExtensions(OutputIterator &output) const
Retrieves all extensions contributed to the point instance.