7 #include "fwRuntime/operations.hpp" 9 #include "fwRuntime/Bundle.hpp" 10 #include "fwRuntime/ConfigurationElement.hpp" 11 #include "fwRuntime/io/ProfileReader.hpp" 12 #include "fwRuntime/profile/Profile.hpp" 13 #include "fwRuntime/Runtime.hpp" 32 struct ConfigurationElementIdentifierPredicate
34 ConfigurationElementIdentifierPredicate(
const std::string& identifier ) :
35 m_identifier( identifier )
41 bool operator() ( std::shared_ptr< ConfigurationElement > element )
43 return element->getAttributeValue(
"id") == m_identifier;
48 std::string m_identifier;
57 const std::string& pointIdentifier )
59 typedef std::vector< ConfigurationElement::sptr > ElementContainer;
60 ConfigurationElement::sptr resultConfig;
61 ElementContainer elements =
62 getAllConfigurationElementsForPoint< ElementContainer >( pointIdentifier );
63 ElementContainer::iterator foundElement = ::std::find_if( elements.begin(),
65 ConfigurationElementIdentifierPredicate(identifier) );
66 if(foundElement != elements.end())
68 resultConfig = *foundElement;
75 std::shared_ptr< Extension >
findExtension(
const std::string& identifier )
94 std::shared_ptr<Bundle> bundle = rntm->
findBundle( bundleIdentifier );
98 SLM_ERROR(
"Could not find bundle " + bundleIdentifier +
"'");
99 return ::boost::filesystem::path();
101 return bundle->getResourcesLocation();
107 const ::boost::filesystem::path& path) noexcept
110 std::shared_ptr<Bundle> bundle = rntm->
findBundle( bundleIdentifier );
112 if(bundle ==
nullptr)
114 SLM_ERROR(
"Could not find bundle '" + bundleIdentifier +
"'");
115 return ::boost::filesystem::path();
124 SLM_ASSERT(
"Path should be relative", path.is_relative());
125 const std::string bundleIdentifierAndVersion = path.begin()->string();
128 auto itVersionDelimiter = bundleIdentifierAndVersion.find(Bundle::s_VERSION_DELIMITER);
129 auto bundleIdentifier = bundleIdentifierAndVersion.substr(0, itVersionDelimiter);
130 auto bundleVersion = bundleIdentifierAndVersion.substr(itVersionDelimiter + 1);
133 ::boost::filesystem::path pathWithoutBundle;
134 for(
auto itPath = ++path.begin(); itPath != path.end(); itPath++)
136 pathWithoutBundle /= *itPath;
142 Version version(bundleVersion);
143 std::shared_ptr<Bundle> bundle = rntm->
findBundle( bundleIdentifier, version );
145 if(bundle ==
nullptr)
147 SLM_ERROR(
"Could not find bundle '" + bundleIdentifier +
"' with version '" + version.
string() +
"'");
148 return ::boost::filesystem::path();
154 SLM_ERROR(
"Error looking for bundle '" + bundleIdentifier +
"' with version '" + bundleVersion +
"'");
155 return ::boost::filesystem::path();
173 auto file = ::fwRuntime::getBundleResourceFilePath(path);
177 file = ::fwRuntime::getLibraryResourceFilePath(path);
178 SLM_ERROR_IF(
"Resource '" + path.string() +
"' has not been found in any bundle or library", file.empty());
186 const ::boost::filesystem::path& path) noexcept
188 return bundle->getResourcesLocation() / path;
194 const ::boost::filesystem::path& path) noexcept
202 const ::boost::filesystem::path& path) noexcept
209 void addBundles( const ::boost::filesystem::path& directory)
217 ::fwRuntime::profile::Profile::sptr
startProfile( const ::boost::filesystem::path& path )
225 catch(
const std::exception& exception )
227 throw RuntimeException( std::string(path.string() +
": invalid profile file. ") + exception.what() );
245 std::shared_ptr<Bundle> bundle = rntm->
findBundle( identifier );
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Defines the runtime class.
FWRUNTIME_API::boost::filesystem::path getLibraryResourceFilePath(const ::boost::filesystem::path &path) noexcept
Retrieve a filesystem valid path for a resource path whose first element is a library identifier...
FWRUNTIME_API::boost::filesystem::path getResourceFilePath(const ::boost::filesystem::path &path) noexcept
Retrieve a filesystem valid path for a resource path whose first element is a library or a bundle ide...
FWRUNTIME_API std::shared_ptr< ConfigurationElement > findConfigurationElement(const std::string &identifier, const std::string &pointIdentifier)
Retrieve the configuation element with the given identifier for the given extension point...
Defines the runtime exception class.
FWRUNTIME_API std::shared_ptr< Extension > findExtension(const std::string &identifier) const
Retrieves the extension instance matching the specified identifier.
Defines the base executable interface.An executable object is an instance created by an extension poi...
FWRUNTIME_API std::shared_ptr< Extension > findExtension(const std::string &identifier)
Retrieve the extension having the specified identifier.
FWRUNTIME_API std::shared_ptr< Bundle > findBundle(const std::string &identifier, const Version &version=Version()) const
Retrieves the bundle for the specified idenfier.
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.
#define SLM_ERROR(message)
FWRUNTIME_API std::shared_ptr< ExtensionPoint > findExtensionPoint(const std::string &identifier)
Retrieves the extension point having the specified identifier.
FWRUNTIME_API void addBundles(const boost::filesystem::path &directory)
Loads all bundles that can be found in the specified directory.
FWRUNTIME_API void startBundle(const std::string &identifier)
Starts the bundle specified by the given identifier.
#define SLM_ERROR_IF(message, cond)
FWRUNTIME_API std::shared_ptr< ::fwRuntime::profile::Profile > startProfile(const boost::filesystem::path &path)
Starts the given bundle set profile.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRUNTIME_API std::shared_ptr< Bundle > findBundle(const std::string &identifier, const Version &version=Version())
Retrieves the bundle with the given identifier and version.
FWRUNTIME_API void addBundles(const ::boost::filesystem::path &repository)
Adds all bundle found in the given path.
static FWRUNTIME_API std::shared_ptr< ::fwRuntime::profile::Profile > createProfile(const boost::filesystem::path &path)
Creates a profile from an xml file located at the given path.
FWRUNTIME_API::boost::filesystem::path getBundleResourceFilePath(const std::string &bundleIdentifier, const ::boost::filesystem::path &path) noexcept
Retrieve a filesystem valid path for a path relative to the bundle having the specified identifier...
FWRUNTIME_API::boost::filesystem::path getBundleResourcePath(const std::string &bundleIdentifier) noexcept
Retrieve the filesystem valid path of resources of a bundle.
Holds version information for libraries and bundles.
FWRUNTIME_API const std::string string() const
String converter.
FWRUNTIME_API::boost::filesystem::path getWorkingPath() const
Get the path where Bundles and share folder are located.