fw4spl
Runtime.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #ifndef __FWRUNTIME_RUNTIME_HPP__
8 #define __FWRUNTIME_RUNTIME_HPP__
9 
10 #include "fwRuntime/config.hpp"
11 #include "fwRuntime/RuntimeException.hpp"
12 #include "fwRuntime/Version.hpp"
13 
14 #include <boost/filesystem/path.hpp>
15 
16 #include <set>
17 #include <vector>
18 
19 namespace fwRuntime
20 {
21 struct Bundle;
22 struct ConfigurationElement;
23 struct Extension;
24 struct ExtensionPoint;
25 struct IExecutable;
26 struct ExecutableFactory;
27 struct IPlugin;
28 }
29 
30 namespace fwRuntime
31 {
32 
37 struct Runtime
38 {
43  typedef std::set< std::shared_ptr<Bundle> > BundleContainer;
45 
47  typedef BundleContainer::iterator BundleIterator;
49  typedef std::set< std::shared_ptr<Extension> > ExtensionContainer;
51  typedef ExtensionContainer::iterator ExtensionIterator;
53 
57  FWRUNTIME_API static Runtime* getDefault();
58 
62  ~Runtime();
63 
69  FWRUNTIME_API void setWorkingPath(const ::boost::filesystem::path& workingPath);
70 
76  FWRUNTIME_API ::boost::filesystem::path getWorkingPath() const;
77 
90  FWRUNTIME_API void addBundle( std::shared_ptr< Bundle > bundle );
91 
97  FWRUNTIME_API void unregisterBundle( std::shared_ptr< Bundle > bundle );
98 
104  FWRUNTIME_API void addBundles( const ::boost::filesystem::path& repository );
105 
111  FWRUNTIME_API void addDefaultBundles();
112 
118  FWRUNTIME_API BundleIterator bundlesBegin();
119 
125  FWRUNTIME_API BundleIterator bundlesEnd();
126 
135  FWRUNTIME_API std::shared_ptr< Bundle > findBundle( const std::string& identifier,
136  const Version& version = Version() ) const;
137 
146  FWRUNTIME_API std::shared_ptr< Bundle > findEnabledBundle( const std::string& identifier,
147  const Version& version = Version() ) const;
148 
150 
162  FWRUNTIME_API void addExecutableFactory( std::shared_ptr< ExecutableFactory > factory );
163 
169  FWRUNTIME_API void unregisterExecutableFactory( std::shared_ptr< ExecutableFactory > factory );
170 
183  FWRUNTIME_API IExecutable* createExecutableInstance( const std::string& type );
184 
200  FWRUNTIME_API IExecutable* createExecutableInstance( const std::string& type,
201  std::shared_ptr< ConfigurationElement > configurationElement );
202 
210  FWRUNTIME_API std::shared_ptr< ExecutableFactory > findExecutableFactory( const std::string& type ) const;
211 
219  FWRUNTIME_API std::shared_ptr< IPlugin > getPlugin( const std::shared_ptr< Bundle > bundle ) const;
220 
222 
234  FWRUNTIME_API void addExtension( std::shared_ptr<Extension> extension);
235 
241  FWRUNTIME_API void unregisterExtension( std::shared_ptr<Extension> extension);
242 
248  FWRUNTIME_API ExtensionIterator extensionsBegin();
249 
255  FWRUNTIME_API ExtensionIterator extensionsEnd();
256 
264  FWRUNTIME_API std::shared_ptr< Extension > findExtension( const std::string& identifier ) const;
265 
267 
277  FWRUNTIME_API void addExtensionPoint( std::shared_ptr<ExtensionPoint> point);
278 
284  FWRUNTIME_API void unregisterExtensionPoint( std::shared_ptr<ExtensionPoint> point);
285 
293  FWRUNTIME_API std::shared_ptr< ExtensionPoint > findExtensionPoint( const std::string& identifier ) const;
295 
296  private:
297 
299  typedef std::set< std::shared_ptr< ExecutableFactory > > ExecutableFactoryContainer;
300 
302  typedef std::set< std::shared_ptr<ExtensionPoint> > ExtensionPointContainer;
303 
305  typedef std::vector< std::shared_ptr<IPlugin> > PluginContainer;
306 
307  static std::shared_ptr<Runtime> m_instance;
308 
309  ExecutableFactoryContainer m_executableFactories;
310  ExtensionContainer m_extensions;
311  ExtensionPointContainer m_extensionPoints;
312  BundleContainer m_bundles;
313  PluginContainer m_plugins;
314 
315  ::boost::filesystem::path m_workingPath;
316 
320  Runtime();
321 };
322 
323 } // namespace fwRuntime
324 
325 #endif // __FWRUNTIME_RUNTIME_HPP__
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
FWRUNTIME_API void addExtension(std::shared_ptr< Extension > extension)
Registers a new extension.
Definition: Runtime.cpp:188
FWRUNTIME_API ExtensionIterator extensionsEnd()
Retrieves the iterator on the end of the extension collection.
Definition: Runtime.cpp:221
FWRUNTIME_API BundleIterator bundlesBegin()
Retrieves the iterator on the begining of the bundle collection.
Definition: Runtime.cpp:133
FWRUNTIME_API std::shared_ptr< Bundle > findEnabledBundle(const std::string &identifier, const Version &version=Version()) const
Retrieves the enabled bundle for the specified idenfier.
Definition: Runtime.cpp:270
FWRUNTIME_API IExecutable * createExecutableInstance(const std::string &type)
Create an instance of the given executable object type.
Definition: Runtime.cpp:329
FWRUNTIME_API void unregisterExecutableFactory(std::shared_ptr< ExecutableFactory > factory)
Unregister a new executable factory instance to the runtime system.
Definition: Runtime.cpp:161
FWRUNTIME_API std::shared_ptr< Extension > findExtension(const std::string &identifier) const
Retrieves the extension instance matching the specified identifier.
Definition: Runtime.cpp:297
FWRUNTIME_API void setWorkingPath(const ::boost::filesystem::path &workingPath)
Set the working path where Bundles and share folder are located.
Definition: Runtime.cpp:395
FWRUNTIME_API ExtensionIterator extensionsBegin()
Retrieves the iterator on the beginning of the extension collection.
Definition: Runtime.cpp:214
FWRUNTIME_API void addBundle(std::shared_ptr< Bundle > bundle)
Adds a new bundle instance to the runtime system.
Definition: Runtime.cpp:83
Defines the base executable interface.An executable object is an instance created by an extension poi...
Definition: IExecutable.hpp:41
FWRUNTIME_API void unregisterBundle(std::shared_ptr< Bundle > bundle)
Unregister a bundle instance to the runtime system.
Definition: Runtime.cpp:96
FWRUNTIME_API BundleIterator bundlesEnd()
Retrieves the iterator on the end of the bundle collection.
Definition: Runtime.cpp:140
Contains fwAtomsFilter::factory utilities.
FWRUNTIME_API std::shared_ptr< Bundle > findBundle(const std::string &identifier, const Version &version=Version()) const
Retrieves the bundle for the specified idenfier.
Definition: Runtime.cpp:254
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
FWRUNTIME_API std::shared_ptr< ExtensionPoint > findExtensionPoint(const std::string &identifier) const
Retrieves the extension point instance matching the specified identifier.
Definition: Runtime.cpp:313
FWRUNTIME_API std::shared_ptr< ExecutableFactory > findExecutableFactory(const std::string &type) const
Retrieves the executable factory for the given identifier.
Definition: Runtime.cpp:172
~Runtime()
Destructor : does nothing.
Definition: Runtime.cpp:77
std::set< std::shared_ptr< Extension > > ExtensionContainer
Defines the extension container type.
Definition: Runtime.hpp:49
FWRUNTIME_API void addExecutableFactory(std::shared_ptr< ExecutableFactory > factory)
Adds a new executable factory instance to the runtime system.
Definition: Runtime.cpp:147
FWRUNTIME_API std::shared_ptr< IPlugin > getPlugin(const std::shared_ptr< Bundle > bundle) const
Retrieves the plugin instance for the specified bundle.
FWRUNTIME_API void addBundles(const ::boost::filesystem::path &repository)
Adds all bundle found in the given path.
Definition: Runtime.cpp:103
BundleContainer::iterator BundleIterator
Defines the bundle container iterator type.
Definition: Runtime.hpp:47
Holds version information for libraries and bundles.
std::set< std::shared_ptr< Bundle > > BundleContainer
Defines the bundle container type.
Definition: Runtime.hpp:44
FWRUNTIME_API void unregisterExtensionPoint(std::shared_ptr< ExtensionPoint > point)
Unregister a new extension point.
Definition: Runtime.cpp:242
FWRUNTIME_API void addDefaultBundles()
Adds all bundle found at the default location.
Definition: Runtime.cpp:119
FWRUNTIME_API void addExtensionPoint(std::shared_ptr< ExtensionPoint > point)
Registers a new extension point.
Definition: Runtime.cpp:228
FWRUNTIME_API void unregisterExtension(std::shared_ptr< Extension > extension)
Unregister a new extension.
Definition: Runtime.cpp:202
FWRUNTIME_API::boost::filesystem::path getWorkingPath() const
Get the path where Bundles and share folder are located.
Definition: Runtime.cpp:402