fw4spl
Profile.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_PROFILE_PROFILE_HPP__
8 #define __FWRUNTIME_PROFILE_PROFILE_HPP__
9 
10 #include "fwRuntime/config.hpp"
11 
12 #include <fwCore/base.hpp>
13 
14 #include <boost/filesystem/path.hpp>
15 #include <boost/make_shared.hpp>
16 #include <boost/utility.hpp>
17 
18 #include <functional>
19 #include <vector>
20 
21 #ifdef ANDROID
22 class android_app;
23 #endif
24 
25 namespace fwRuntime
26 {
27 
31 namespace profile
32 {
33 
34 class Activater;
35 class Starter;
36 class Stopper;
37 class Initializer;
38 class Uninitializer;
39 
44 {
45 public:
46 
47  typedef std::vector< std::string > ParamsContainer;
48  typedef std::function< int () > RunCallbackType;
49 
50  fwCoreClassDefinitionsWithFactoryMacro( (Profile)(BaseObject), (()), std::make_shared< Profile >);
51 
55  FWRUNTIME_API Profile();
56 
57  FWRUNTIME_API ~Profile();
58 
64  FWRUNTIME_API void add( SPTR( Activater ) activater );
65 
71  FWRUNTIME_API void add( SPTR( Starter ) starter );
72 
78  FWRUNTIME_API void add( SPTR( Stopper ) stopper );
79 
85  FWRUNTIME_API void add( SPTR( Initializer ) initializer );
86 
92  FWRUNTIME_API void add( SPTR( Uninitializer ) uninitializer );
93 
97  FWRUNTIME_API void start();
98  FWRUNTIME_API void stop();
99 
103  FWRUNTIME_API int run();
104  FWRUNTIME_API int defaultRun();
105  FWRUNTIME_API void setRunCallback(RunCallbackType callback);
106 
110  FWRUNTIME_API void setup();
111  FWRUNTIME_API void cleanup();
112 
116  std::string getName() const
117  {
118  return m_sName;
119  }
120 
126  void setName(std::string _sName)
127  {
128  m_sName = _sName;
129  }
130 
132  ::boost::filesystem::path getFilePath() const
133  {
134  return m_filePath;
135  }
136 
138  void setFilePath(const ::boost::filesystem::path& _filePath)
139  {
140  m_filePath = _filePath;
141  }
142 
146  std::string getVersion() const
147  {
148  return m_sVersion;
149  }
150 
156  void setVersion(std::string _sVersion)
157  {
158  m_sVersion = _sVersion;
159  }
160 
165  {
166  return m_checkSingleInstance;
167  }
168 
174  void setCheckSingleInstance(bool _checkSingleInstance)
175  {
176  m_checkSingleInstance = _checkSingleInstance;
177  }
178 
179 #ifdef ANDROID
180  android_app* getApp() const
182  {
183  return m_app;
184  }
185  //------------------------------------------------------------------------------
186 
187  void setApp(android_app* app)
188  {
189  m_app = app;
190  }
191 #endif
192  //------------------------------------------------------------------------------
193 
194  ParamsContainer getParams() const
195  {
196  return m_params;
197  }
198 
199  FWRUNTIME_API void setParams(const ParamsContainer& params);
200  FWRUNTIME_API void setParams(int argc, char** argv);
201 
208  {
209  return m_argc;
210  }
211 
217  char** getRawParams() const
218  {
219  return m_argv;
220  }
221 
222 private:
223 
224  typedef std::vector< SPTR(Activater) > ActivaterContainer;
225  typedef std::vector< SPTR(Starter) > StarterContainer;
226  typedef std::vector< SPTR(Stopper) > StopperContainer;
227  typedef std::vector< SPTR(Initializer) > InitializerContainer;
228  typedef std::vector< SPTR(Uninitializer) > UninitializerContainer;
229 
230  ActivaterContainer m_activaters;
231  StarterContainer m_starters;
232  StopperContainer m_stoppers;
233  InitializerContainer m_initializers;
234  UninitializerContainer m_uninitializers;
235 
236  std::string m_sName;
237  std::string m_sVersion;
238  ::boost::filesystem::path m_filePath;
239 
240  bool m_checkSingleInstance;
241  RunCallbackType m_run;
242 
243 #ifdef ANDROID
244  android_app* m_app;
245 #endif
246  ParamsContainer m_params;
247  int m_argc;
248  char** m_argv;
249 };
250 
256 FWRUNTIME_API void setCurrentProfile(Profile::sptr prof);
257 
261 FWRUNTIME_API Profile::sptr getCurrentProfile();
262 
263 } // namespace profile
264 
265 } // namespace fwRuntime
266 
267 #endif /*__FWRUNTIME_PROFILE_PROFILE_HPP__*/
#define SPTR(_cls_)
FWRUNTIME_API void add(std::shared_ptr< Activater > activater)
Adds a new activator.
Definition: Profile.cpp:85
FWRUNTIME_API void setCurrentProfile(Profile::sptr prof)
Set current profile.
Definition: Profile.cpp:48
Activates a given bundle with optional parameters.
Definition: Activater.hpp:34
Base class for all FW4SPL&#39;s classes.
Definition: BaseObject.hpp:22
FWRUNTIME_API Profile::sptr getCurrentProfile()
Get current profile.
Definition: Profile.cpp:55
std::string getName() const
Return profile name.
Definition: Profile.hpp:116
Starts a given bundle.
Definition: Starter.hpp:26
bool getCheckSingleInstance() const
Return profile CheckSingleInstance.
Definition: Profile.hpp:164
char ** getRawParams() const
Returns a raw pointer on internal arguments. The returned data shall not be modified. This is provided for external library needs (QApplication contructor for example)
Definition: Profile.hpp:217
void setFilePath(const ::boost::filesystem::path &_filePath)
Set profile m_filePath.
Definition: Profile.hpp:138
void setCheckSingleInstance(bool _checkSingleInstance)
Set profile CheckSingleInstance.
Definition: Profile.hpp:174
FWRUNTIME_API void setup()
Once started, setup the profile.
Definition: Profile.cpp:174
FWRUNTIME_API int run()
Run the profile.
Definition: Profile.cpp:140
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
Implements a bundle set profile.
Definition: Profile.hpp:43
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
std::string getVersion() const
Return profile version.
Definition: Profile.hpp:146
void setVersion(std::string _sVersion)
Set profile version.
Definition: Profile.hpp:156
FWRUNTIME_API void start()
Starts the profile.
Definition: Profile.cpp:120
FWRUNTIME_API Profile()
Constructor : does nothing.
Definition: Profile.cpp:62
void setName(std::string _sName)
Set profile name.
Definition: Profile.hpp:126
::boost::filesystem::path getFilePath() const
Get profile m_filePath.
Definition: Profile.hpp:132
Starts a given bundle.
Definition: Initializer.hpp:26
Stops a given bundle.
Definition: Stopper.hpp:26
int & getRawArgCount()
Returns internal arg count. The returned int shall not be modified. This is provided for external lib...
Definition: Profile.hpp:207