fw4spl
Bundle.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 "fwCore/base.hpp"
10 
11 #include "fwRuntime/config.hpp"
12 #include "fwRuntime/dl/Library.hpp"
13 #include "fwRuntime/RuntimeException.hpp"
14 #include "fwRuntime/Version.hpp"
15 
16 #include <boost/filesystem/path.hpp>
17 
18 #include <map>
19 #include <set>
20 #include <string>
21 
22 namespace fwRuntime
23 {
24 struct Extension;
25 struct ExtensionPoint;
26 struct ExtensionRegistry;
27 struct IExecutable;
28 struct ExecutableFactory;
29 struct IPlugin;
30 struct Runtime;
31 
32 namespace io
33 {
35 }
36 }
37 
38 namespace fwRuntime
39 {
40 
45 struct Bundle : public std::enable_shared_from_this< Bundle >
46 {
47  friend struct ::fwRuntime::io::BundleDescriptorReader;
48 
49  static const char s_VERSION_DELIMITER = '-';
54  typedef std::set< SPTR( ExecutableFactory ) > ExecutableFactoryContainer;
55  // factory container type.
56  typedef ExecutableFactoryContainer::const_iterator ExecutableFactoryConstIterator;
57  // factory container constant
58  // iterator type.
59 
60  typedef std::set< SPTR( Extension ) > ExtensionContainer;
61  // type.
62  typedef ExtensionContainer::const_iterator ExtensionConstIterator;
63  // constant iterator type.
64 
65  typedef std::set< SPTR( ExtensionPoint ) > ExtensionPointContainer;
66  // container type.
67  typedef ExtensionPointContainer::const_iterator ExtensionPointConstIterator;
68  // container constant iterator type.
69 
70  typedef std::set< SPTR(dl::Library) > LibraryContainer;
71  // type.
72  typedef LibraryContainer::const_iterator LibraryConstIterator;
73  // constant iterator type.
75 
79  static SPTR( Bundle ) getLoadingBundle();
80 
90  FWRUNTIME_API void addLibrary( SPTR( dl::Library ) library );
91 
98  FWRUNTIME_API LibraryConstIterator librariesBegin() const;
99 
106  FWRUNTIME_API LibraryConstIterator librariesEnd() const;
108 
118  FWRUNTIME_API void addExecutableFactory( SPTR( ExecutableFactory ) factory );
119 
129  FWRUNTIME_API IExecutable* createExecutableInstance( const std::string& type );
130 
137  FWRUNTIME_API ExecutableFactoryConstIterator executableFactoriesBegin() const;
138 
145  FWRUNTIME_API ExecutableFactoryConstIterator executableFactoriesEnd() const;
146 
154  FWRUNTIME_API SPTR( ExecutableFactory ) findExecutableFactory( const std::string& type ) const;
156 
166  void addExtension( SPTR( Extension ) extension );
167 
175  FWRUNTIME_API bool hasExtension(const std::string& identifier) const;
176 
186  FWRUNTIME_API void setEnableExtension(const std::string& identifier, const bool enable);
187 
194  FWRUNTIME_API ExtensionConstIterator extensionsBegin() const;
195 
202  FWRUNTIME_API ExtensionConstIterator extensionsEnd() const;
204 
214  void addExtensionPoint( SPTR( ExtensionPoint ) extension );
215 
223  FWRUNTIME_API SPTR( ExtensionPoint ) findExtensionPoint( const std::string& identifier ) const;
224 
232  FWRUNTIME_API bool hasExtensionPoint(const std::string& identifier) const;
233 
243  FWRUNTIME_API void setEnableExtensionPoint(const std::string& identifier, const bool enable);
244 
251  FWRUNTIME_API ExtensionPointConstIterator extensionPointsBegin() const;
252 
259  FWRUNTIME_API ExtensionPointConstIterator extensionPointsEnd() const;
261 
271  FWRUNTIME_API void addRequirement( const std::string& requirement );
272 
278  FWRUNTIME_API const std::string& getIdentifier() const;
279 
285  FWRUNTIME_API const ::boost::filesystem::path& getLibraryLocation() const;
286 
292  FWRUNTIME_API const ::boost::filesystem::path& getResourcesLocation() const;
293 
299  FWRUNTIME_API const std::string getClass() const;
300 
306  FWRUNTIME_API const Version& getVersion() const;
307 
313  FWRUNTIME_API SPTR( IPlugin ) getPlugin() const;
315 
323  FWRUNTIME_API bool isEnable() const;
324 
331  FWRUNTIME_API void setEnable( const bool state );
332 
338  FWRUNTIME_API void start();
339 
340  FWRUNTIME_API void stop();
342 
348  FWRUNTIME_API void initialize();
349 
350  FWRUNTIME_API void uninitialize();
352 
363  FWRUNTIME_API void addParameter( const std::string& identifier, const std::string& value );
364 
376  FWRUNTIME_API const std::string getParameterValue( const std::string& identifier ) const;
377 
383  FWRUNTIME_API bool hasParameter( const std::string& name ) const;
385 
386  bool isStarted()
387  {
388  return m_started;
389  }
390  //------------------------------------------------------------------------------
391 
392  bool isInitialized()
393  {
394  return m_initialized;
395  }
396 
397  FWRUNTIME_API static std::string getBundleStr(const std::string& identifier, const Version& version);
398 
399  protected:
400 
411  Bundle( const ::boost::filesystem::path& location,
412  const std::string& id,
413  const std::string& version );
414 
426  Bundle( const ::boost::filesystem::path& location,
427  const std::string& id,
428  const std::string& version,
429  const std::string& pluginClass );
430 
431  private:
432 
433  typedef std::set< std::string > RequirementContainer;
434  // type.
435  typedef std::map< std::string, std::string > ParameterContainer;
436 
437  static SPTR( Bundle ) m_loadingBundle;
438  // dynamic libaries
439 
440  ::boost::filesystem::path m_libraryLocation;
441  const ::boost::filesystem::path m_resourcesLocation;
442  const std::string m_identifier;
443  const Version m_version;
444  const std::string m_class;
445  bool m_enable { false };
446  // not
447  ExtensionContainer m_extensions;
448  ExtensionPointContainer m_extensionPoints;
449  ExecutableFactoryContainer m_executableFactories;
450  LibraryContainer m_libraries;
451  RequirementContainer m_requirements;
452  SPTR( IPlugin ) m_plugin;
453  ParameterContainer m_parameters;
454 
455  bool m_started { false };
456  bool m_initialized { false };
457 
463  void operator= (const Bundle& );
464 
468  void loadLibraries();
469 
473  void loadRequirements();
474 
478  void startPlugin();
479 
480 };
481 
482 } // namespace fwRuntime
#define SPTR(_cls_)
Defines the extension class.
Definition: Extension.hpp:30
Defines the abstract executable factory class.
STL namespace.
std::set< std::shared_ptr< ExecutableFactory > > ExecutableFactoryContainer
Defines the executable.
Definition: Bundle.hpp:54
Defines the extension point class.
Defines the base executable interface.An executable object is an instance created by an extension poi...
Definition: IExecutable.hpp:41
std::set< std::shared_ptr< ExtensionPoint > > ExtensionPointContainer
Defines the extension point.
Definition: Bundle.hpp:65
Contains fwAtomsFilter::factory utilities.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
FWRUNTIME_API std::shared_ptr< ExtensionPoint > findExtensionPoint(const std::string &identifier)
Retrieves the extension point having the specified identifier.
Definition: operations.cpp:83
LibraryContainer::const_iterator LibraryConstIterator
Defines the dynamic library container.
Definition: Bundle.hpp:72
Defines the plugin interface.
Definition: IPlugin.hpp:29
std::set< std::shared_ptr< Extension > > ExtensionContainer
Defines the extension container.
Definition: Bundle.hpp:60
ExtensionContainer::const_iterator ExtensionConstIterator
Defines the extension container.
Definition: Bundle.hpp:62
ExecutableFactoryContainer::const_iterator ExecutableFactoryConstIterator
Defines the executable.
Definition: Bundle.hpp:56
T * createExecutableInstance(const std::shared_ptr< Extension > extension, const std::string &element="executable", const std::string &attribute="class")
Creates an executable instance for the specified configuration element.
Definition: operations.hpp:61
Defines the bundle class.
Definition: Bundle.hpp:45
Holds version information for libraries and bundles.
std::set< std::shared_ptr< dl::Library > > LibraryContainer
Defines the dynamic library container.
Definition: Bundle.hpp:70
ExtensionPointContainer::const_iterator ExtensionPointConstIterator
Defines the extension point.
Definition: Bundle.hpp:67
Defines the bundle descriptor reader class.