All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RuntimeEnv.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 
34 /**
35  @file
36 
37  @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
38 */
39 
40 #ifndef __RUNTIMEENV_HPP__
41 #define __RUNTIMEENV_HPP__
42 
43 #include <string>
44 #include <boost/date_time/posix_time/posix_time.hpp>
45 #include <boost/filesystem/path.hpp>
46 
47 #include <openfluid/dllexport.hpp>
50 
51 
52 
53 namespace openfluid { namespace base {
54 
55 
56 // =====================================================================
57 // =====================================================================
58 
59 
60 /**
61 
62 */
64 {
65  private:
66 
67  static RuntimeEnvironment* mp_Singleton;
68 
69  std::string m_Version;
70  std::string m_FullVersion;
71  std::string m_MajorMinorVersion;
72 
73  std::string m_OutputDir;
74  std::string m_InputDir;
75  std::string m_UserDataDir;
76  std::string m_TempDir;
77  std::string m_HomeDir;
78  std::string m_MarketBagDir;
79  std::string m_MarketBagVersionDir;
80 
81  std::string m_MarketBagSimVersionDir;
82  std::string m_MarketBagObsVersionDir;
83  std::string m_MarketBagBuildVersionDir;
84  std::string m_MarketBagDataVersionDir;
85  std::string m_MarketBagBinSubDir;
86  std::string m_MarketBagSrcSubDir;
87 
88  std::string m_InstallPrefix;
89 
90  std::vector<std::string> m_DefaultSimulatorsPlugsDirs;
91  std::vector<std::string> m_ExtraSimulatorsPlugsDirs;
92 
93  std::vector<std::string> m_DefaultObserversPlugsDirs;
94  std::vector<std::string> m_ExtraObserversPlugsDirs;
95 
96 
97  std::string m_ProvidedExamplesDir;
98  std::string m_UserExamplesDir;
99 
100  std::string m_UserID;
101  std::string m_HostName;
102  std::string m_Arch;
103 
104  unsigned int m_SimulatorsMaxNumThreads;
105 
106  std::string m_DefaultConfigFilePath;
107 
108  bool m_ClearOutputDir;
109 
110  bool m_WriteResults;
111 
112  bool m_WriteSimReport;
113 
114  bool m_Profiling;
115 
116  unsigned int m_ValuesBufferSize;
117 
118  bool m_IsUserValuesBufferSize;
119 
121 
122  openfluid::base::EnvironmentProperties m_ExtraProperties;
123 
124  boost::posix_time::ptime m_IgnitionDateTime;
125 
126  boost::posix_time::time_duration m_EffectiveSimulationDuration;
127 
128  openfluid::core::DateTime m_StartTime;
129 
130  openfluid::core::DateTime m_EndTime;
131 
132  // TODO set correct type for time step
133  int m_TimeStep;
134 
135  bool m_IsLinkedToProject;
136 
137 
138  /**
139  Default constructor
140  */
142 
143  public:
144 
145  static RuntimeEnvironment* getInstance();
146 
147  /**
148  Destructor
149  */
151 
152 
153  /**
154  Returns the version of OpenFLUID
155  @return the version as a std::string
156  */
157  std::string getVersion() const { return m_Version; };
158 
159  /**
160  Returns the full version of OpenFLUID, including status (alpha, beta, rc, ...)
161  @return the full version as a std::string
162  */
163  std::string getFullVersion() const { return m_FullVersion; };
164 
165  /**
166  Returns the version of OpenFLUID, composed of major and minor numbers
167  @return the major.minor version as a std::string
168  */
169  std::string getMajorMinorVersion() const { return m_MajorMinorVersion; };
170 
171 
172 
173  /**
174  Sets the input directory, overriding the default input dir
175  @param[in] InputDir The input directory
176  */
177  void setInputDir(const std::string InputDir)
178  { m_InputDir = InputDir; mp_WareEnv->setValue("dir.input",m_InputDir); };
179 
180  /**
181  Returns the input directory
182  @return the input directory
183  */
184  inline std::string getInputDir() const { return m_InputDir; };
185 
186  /**
187  Sets the output directory, overriding the default output dir
188  @param[in] OutputDir The output directory
189  */
190  void setOutputDir(const std::string OutputDir)
191  { m_OutputDir = OutputDir; mp_WareEnv->setValue("dir.output",m_OutputDir); };
192 
193  /**
194  Returns the output directory
195  @return the output directory
196  */
197  inline std::string getOutputDir() const { return m_OutputDir; };
198 
199  /**
200  Sets the output directory as a directory located in the user data directory, with a name based on the current date-time
201  */
202  void setDateTimeOutputDir();
203 
204  /**
205  Returns the market bag directory (i.e. $HOME/.openfluid/market-bag)
206  @return the market bag directory
207  */
208  inline std::string getMarketBagDir() const { return m_MarketBagDir; };
209 
210  /**
211  @return the market bag directory for the current OpenFLUID version (i.e. $HOME/.openfluid/market-bag/2.0.0)
212  */
213  inline std::string getMarketBagVersionDir() const { return m_MarketBagVersionDir; };
214 
215  /**
216  @return the market bag directory for simulators of the current version (i.e. $HOME/.openfluid/market-bag/2.0.0/simulators)
217  */
218  inline std::string getMarketBagSimVersionDir() const { return m_MarketBagSimVersionDir; };
219 
220  /**
221  @return the market bag directory for observers of the current version (i.e. $HOME/.openfluid/market-bag/2.0.0/observers)
222  */
223  inline std::string getMarketBagObsVersionDir() const { return m_MarketBagObsVersionDir; };
224 
225  /**
226  @return the market bag directory for builderexts of the current version (i.e. $HOME/.openfluid/market-bag/2.0.0/builderexts)
227  */
228  inline std::string getMarketBagBuildVersionDir() const { return m_MarketBagBuildVersionDir; };
229 
230  /**
231  @return the market bag directory for datasets of the current version (i.e. $HOME/.openfluid/market-bag/2.0.0/datasets)
232  */
233  inline std::string getMarketBagDataVersionDir() const { return m_MarketBagDataVersionDir; };
234 
235  /**
236  @return the binairies market bag subdirectory
237  */
238  inline std::string getMarketBagBinSubDir() const { return m_MarketBagBinSubDir; };
239 
240  /**
241  @return the sources market bag subdirectory
242  */
243  inline std::string getMarketBagSrcSubDir() const { return m_MarketBagSrcSubDir; };
244 
245  /**
246  Returns the default config file path (i.e. $HOME/.openfluid/openfluid.conf)
247  @return the default config file path
248  */
249  inline std::string getDefaultConfigFile() const
250  { return m_DefaultConfigFilePath; };
251 
252  /**
253  Returns the path for a given config file (i.e. $HOME/.openfluid/Filename)
254  @param[in] Filename the given config file name
255  @return the path
256  */
257  std::string getConfigFilePath(std::string Filename) const
258  { return boost::filesystem::path(m_UserDataDir + "/" + Filename).string(); };
259 
260 
261  /**
262  Returns the absolute path of the home directory
263  @return the absolute path
264  */
265  std::string getUserHomeDir() const
266  { return m_HomeDir; };
267 
268  /**
269  Returns the absolute path for a given relative path in the user OpenFLUID directory (i.e. $HOME/.openfluid/RelativePath)
270  @param[in] RelativePath the given relative path
271  @return the absolute path
272  */
273  std::string getUserDataPath(std::string RelativePath) const
274  { return boost::filesystem::path(m_UserDataDir + "/" + RelativePath).string(); };
275 
276  /**
277  Returns the path of the temporary directory
278  @return the path of the temporary directory
279  */
280  inline std::string getTempDir() const
281  { return m_TempDir; };
282 
283  /**
284  Returns the path for a given input file (i.e. InputDir/Filename)
285  @param[in] Filename The given input file name
286  @return the path for a given input file
287  */
288  std::string getInputFullPath(std::string Filename) const
289  { return boost::filesystem::path(m_InputDir + "/" + Filename).string(); };
290 
291  /**
292  Returns the path for a given output file (i.e. OutputDir/Filename)
293  @param[in] Filename The given output file name
294  @return the path for a given output file
295  */
296  inline std::string getOutputFullPath(std::string Filename) const
297  { return boost::filesystem::path(m_OutputDir + "/" + Filename).string(); };
298 
299  /**
300  Returns the path for a given simulator plugin file, taking into account the simulator plugins path search order
301  @param[in] Filename The given simulator plugin file name
302  @return the first path found for a given simulator plugin file
303  */
304  std::string getSimulatorPluginFullPath(std::string Filename);
305 
306  /**
307  Adds search paths for plugins, separated by semicolon characters (i.e. /path/to/plugs:another/path/to/plugs).
308  These paths are added at the top of the search paths list.
309  @param[in] SemicolonSeparatedPaths a collection of paths separated by semicolons, as a std::string
310  */
311  void addExtraSimulatorsPluginsPaths(std::string SemicolonSeparatedPaths);
312 
313  inline void resetExtraSimulatorsPluginsPaths() { m_ExtraSimulatorsPlugsDirs.clear(); };
314 
315  inline std::vector<std::string> getDefaultSimulatorsPluginsPaths() const { return m_DefaultSimulatorsPlugsDirs; };
316 
317  inline std::vector<std::string> getExtraSimulatorsPluginsPaths() const { return m_ExtraSimulatorsPlugsDirs; };
318 
319  /**
320  Returns the ordered list of paths used to search for simulator plugins
321  @return the ordered list of paths
322  */
323  inline std::vector<std::string> getSimulatorsPluginsPaths() const
324  {
325  std::vector<std::string> ComposedPaths(m_ExtraSimulatorsPlugsDirs);
326  ComposedPaths.insert(ComposedPaths.end(), m_DefaultSimulatorsPlugsDirs.begin(), m_DefaultSimulatorsPlugsDirs.end());
327  return ComposedPaths;
328  };
329 
330  /**
331  Returns the path for a given observer plugin file, taking into account the observer plugins path search order
332  @param[in] Filename The given observer plugin file name
333  @return the first path found for a given observer plugin file
334  */
335  std::string getObserverPluginFullPath(std::string Filename);
336 
337  /**
338  Adds search paths for plugins, separated by semicolon characters (i.e. /path/to/plugs:another/path/to/plugs).
339  These paths are added at the top of the search paths list.
340  @param[in] SemicolonSeparatedPaths a collection of paths separated by semicolons, as a std::string
341  */
342  void addExtraObserversPluginsPaths(std::string SemicolonSeparatedPaths);
343 
344  inline void resetExtraObserversPluginsPaths() { m_ExtraObserversPlugsDirs.clear(); };
345 
346  inline std::vector<std::string> getDefaultObserversPluginsPaths() const { return m_DefaultObserversPlugsDirs; };
347 
348  inline std::vector<std::string> getExtraObserversPluginsPaths() const { return m_ExtraObserversPlugsDirs; };
349 
350  /**
351  Returns the ordered list of paths used to search for observer plugins
352  @return the ordered list of paths
353  */
354  inline std::vector<std::string> getObserversPluginsPaths() const
355  {
356  std::vector<std::string> ComposedPaths(m_ExtraObserversPlugsDirs);
357  ComposedPaths.insert(ComposedPaths.end(), m_DefaultObserversPlugsDirs.begin(), m_DefaultObserversPlugsDirs.end());
358  return ComposedPaths;
359  };
360 
361 
362 
363  /**
364  Returns the install prefix path.
365  The install prefix is given at compile time, but can be overriden by the OPENFLUID_INSTALL_PREFIX environment variable (recommended on windows systems).
366  @return the install prefix path
367  */
368  inline std::string getInstallPrefix() const
369  { return m_InstallPrefix; };
370 
371  /**
372  Returns the path for common resources, taking into account the install prefix path
373  @return the path for common resources
374  */
375  std::string getCommonResourcesDir() const;
376 
377  /**
378  Returns the path for a given file, relative to the common resources path
379  @param[in] RelativeFilePath The given file
380  @return the path for a given file in the common resources
381  */
382  std::string getCommonResourceFilePath(std::string RelativeFilePath) const;
383 
384  /**
385  Returns the path for resources of a given application, taking into account the install prefix path
386  @param[in] AppName The given application name
387  @return the path for resources of a given application
388  */
389  std::string getAppResourcesDir(std::string AppName) const;
390 
391  /**
392  Returns the path for a given file, relative a given application resources path
393  @param[in] AppName The given application name
394  @param[in] RelativeFilePath The given file
395  @return the path for a given file in the given application resources
396  */
397  std::string getAppResourceFilePath(std::string AppName, std::string RelativeFilePath) const;
398 
399  /**
400  Returns the translations directory
401  @return the path for translationslocale directory
402  */
403  std::string getTranslationsDir() const;
404 
405  /**
406  Returns the path for provided examples, taking into account the install prefix path
407  @return the path for provided examples
408  */
409  std::string getProvidedExamplesDir() const { return m_ProvidedExamplesDir; };
410 
411 
412  /**
413  Returns the path for examples in user's directory
414  @return the path for user's examples
415  */
416  std::string getUserExamplesDir() const { return m_UserExamplesDir; };
417 
418 
419  /**
420  Returns the extra properties list
421  @return the extra properties list
422  */
424  { return m_ExtraProperties; };
425 
426  /**
427  Returns the clear output directory flag
428  */
429  inline bool isClearOutputDir() const { return m_ClearOutputDir; };
430 
431  /**
432  Sets the clear output directory flag
433  @param[in] ClearDir The value of the flag
434  */
435  inline void setClearOutputDir(bool ClearDir)
436  { m_ClearOutputDir = ClearDir; mp_WareEnv->setValue("mode.clearoutputdir",m_ClearOutputDir); };
437 
438  /**
439  Returns the write results flag
440  @return the flag as a boolean
441  */
442  inline bool isWriteResults() const
443  { return m_WriteResults; };
444 
445  /**
446  Sets the write results flag
447  @param[in] WriteIt The value of the flag
448  */
449  void setWriteResults(bool WriteIt)
450  { m_WriteResults = WriteIt; mp_WareEnv->setValue("mode.saveresults",m_WriteResults); };
451 
452  /**
453  Returns the write simulation report flag
454  @return the flag as a boolean
455  */
456  inline bool isWriteSimReport() const { return m_WriteSimReport; };
457 
458  /**
459  Sets the write simulation report flag
460  @param[in] WriteIt The value of the flag
461  */
462  void setWriteSimReport(bool WriteIt)
463  { m_WriteSimReport = WriteIt; mp_WareEnv->setValue("mode.writereport",m_WriteSimReport); };
464 
466  { return mp_WareEnv; };
467 
468 
469  boost::posix_time::ptime getIgnitionDateTime() const
470  { return m_IgnitionDateTime; };
471 
472 
473  void resetIgnitionDateTime();
474 
475 
476  boost::posix_time::time_duration getEffectiveSimulationDuration() const
477  { return m_EffectiveSimulationDuration; };
478 
479 
480  void setEffectiveSimulationDuration(const boost::posix_time::time_duration& TimeDuration)
481  { m_EffectiveSimulationDuration = TimeDuration; };
482 
483  /**
484  Returns the local host name (if could be determined)
485  @return the local host name
486  */
487  std::string getHostName() const {return m_HostName; };
488 
489  /**
490  Returns the local user ID (if could be determined)
491  @return the local user ID
492  */
493  std::string getUserID() const {return m_UserID; };
494 
495  /**
496  Returns the local system architecture (if could be determined)
497  @return the local architecture
498  */
499  std::string getArch() const {return m_Arch; };
500 
501  unsigned int getSimulatorsMaxNumThreads() const { return m_SimulatorsMaxNumThreads; };
502 
503  void setSimulatorsMaxNumThreads(const unsigned int& MaxNumThreads)
504  { if (MaxNumThreads > 0) m_SimulatorsMaxNumThreads = MaxNumThreads; };
505 
506 
507  void setSimulationTimeInformation(openfluid::core::DateTime StartTime,
509  int TimeStep);
510 
512  { return m_StartTime; };
513 
515  { return m_EndTime; };
516 
517  // TODO set correct type for time step
519  { return m_TimeStep; };
520 
521  void setValuesBufferSize(const unsigned int StepsNbr)
522  { m_ValuesBufferSize = StepsNbr; m_IsUserValuesBufferSize = true; };
523 
524  inline unsigned int getValuesBufferSize() const
525  { return m_ValuesBufferSize; };
526 
527  bool isUserValuesBufferSize() const { return m_IsUserValuesBufferSize; };
528 
530  { m_IsUserValuesBufferSize = false; }
531 
532  void linkToProject();
533 
534  void detachFromProject();
535 
537  { return m_IsLinkedToProject; };
538 
539  bool isSimulationProfilingEnabled() const { return m_Profiling; };
540 
541  void setSimulationProfilingEnabled(bool Profiling) { m_Profiling = Profiling; };
542 
543 };
544 
545 
546 } } //namespaces
547 
548 #endif
549 
550 
551 
std::string getUserDataPath(std::string RelativePath) const
Definition: RuntimeEnv.hpp:273
std::string getMarketBagDataVersionDir() const
Definition: RuntimeEnv.hpp:233
void setInputDir(const std::string InputDir)
Definition: RuntimeEnv.hpp:177
std::string getInstallPrefix() const
Definition: RuntimeEnv.hpp:368
std::string getDefaultConfigFile() const
Definition: RuntimeEnv.hpp:249
std::vector< std::string > getDefaultObserversPluginsPaths() const
Definition: RuntimeEnv.hpp:346
bool isWriteResults() const
Definition: RuntimeEnv.hpp:442
std::vector< std::string > getExtraSimulatorsPluginsPaths() const
Definition: RuntimeEnv.hpp:317
std::string getHostName() const
Definition: RuntimeEnv.hpp:487
bool isSimulationProfilingEnabled() const
Definition: RuntimeEnv.hpp:539
openfluid::core::DateTime getSimulationStartTime() const
Definition: RuntimeEnv.hpp:511
std::string getUserID() const
Definition: RuntimeEnv.hpp:493
std::string getMarketBagSrcSubDir() const
Definition: RuntimeEnv.hpp:243
void setSimulatorsMaxNumThreads(const unsigned int &MaxNumThreads)
Definition: RuntimeEnv.hpp:503
void setValuesBufferSize(const unsigned int StepsNbr)
Definition: RuntimeEnv.hpp:521
std::string getInputDir() const
Definition: RuntimeEnv.hpp:184
std::string getOutputDir() const
Definition: RuntimeEnv.hpp:197
std::vector< std::string > getExtraObserversPluginsPaths() const
Definition: RuntimeEnv.hpp:348
openfluid::core::DateTime getSimulationEndTime() const
Definition: RuntimeEnv.hpp:514
std::vector< std::string > getObserversPluginsPaths() const
Definition: RuntimeEnv.hpp:354
std::string getOutputFullPath(std::string Filename) const
Definition: RuntimeEnv.hpp:296
bool isLinkedToProject()
Definition: RuntimeEnv.hpp:536
std::string getFullVersion() const
Definition: RuntimeEnv.hpp:163
void setOutputDir(const std::string OutputDir)
Definition: RuntimeEnv.hpp:190
Class for management of date and time information.
Definition: DateTime.hpp:131
std::string getArch() const
Definition: RuntimeEnv.hpp:499
std::string getConfigFilePath(std::string Filename) const
Definition: RuntimeEnv.hpp:257
boost::posix_time::time_duration getEffectiveSimulationDuration() const
Definition: RuntimeEnv.hpp:476
bool isWriteSimReport() const
Definition: RuntimeEnv.hpp:456
int getSimulationTimeStep() const
Definition: RuntimeEnv.hpp:518
std::string getMarketBagSimVersionDir() const
Definition: RuntimeEnv.hpp:218
std::vector< std::string > getSimulatorsPluginsPaths() const
Definition: RuntimeEnv.hpp:323
std::string getInputFullPath(std::string Filename) const
Definition: RuntimeEnv.hpp:288
std::string getMarketBagBinSubDir() const
Definition: RuntimeEnv.hpp:238
std::string getMajorMinorVersion() const
Definition: RuntimeEnv.hpp:169
void resetExtraObserversPluginsPaths()
Definition: RuntimeEnv.hpp:344
openfluid::base::EnvironmentProperties & getExtraProperties()
Definition: RuntimeEnv.hpp:423
void unsetUserValuesBufferSize()
Definition: RuntimeEnv.hpp:529
std::string getProvidedExamplesDir() const
Definition: RuntimeEnv.hpp:409
bool isUserValuesBufferSize() const
Definition: RuntimeEnv.hpp:527
std::vector< std::string > getDefaultSimulatorsPluginsPaths() const
Definition: RuntimeEnv.hpp:315
unsigned int getSimulatorsMaxNumThreads() const
Definition: RuntimeEnv.hpp:501
std::string getUserExamplesDir() const
Definition: RuntimeEnv.hpp:416
bool isClearOutputDir() const
Definition: RuntimeEnv.hpp:429
std::string getVersion() const
Definition: RuntimeEnv.hpp:157
boost::posix_time::ptime getIgnitionDateTime() const
Definition: RuntimeEnv.hpp:469
void setWriteSimReport(bool WriteIt)
Definition: RuntimeEnv.hpp:462
std::string getTempDir() const
Definition: RuntimeEnv.hpp:280
std::string getMarketBagBuildVersionDir() const
Definition: RuntimeEnv.hpp:228
openfluid::base::EnvironmentProperties * getWareEnvironment() const
Definition: RuntimeEnv.hpp:465
Definition: RuntimeEnv.hpp:63
unsigned int getValuesBufferSize() const
Definition: RuntimeEnv.hpp:524
void resetExtraSimulatorsPluginsPaths()
Definition: RuntimeEnv.hpp:313
void setSimulationProfilingEnabled(bool Profiling)
Definition: RuntimeEnv.hpp:541
std::string getMarketBagObsVersionDir() const
Definition: RuntimeEnv.hpp:223
void setEffectiveSimulationDuration(const boost::posix_time::time_duration &TimeDuration)
Definition: RuntimeEnv.hpp:480
std::string getMarketBagDir() const
Definition: RuntimeEnv.hpp:208
std::string getUserHomeDir() const
Definition: RuntimeEnv.hpp:265
std::string getMarketBagVersionDir() const
Definition: RuntimeEnv.hpp:213
void setClearOutputDir(bool ClearDir)
Definition: RuntimeEnv.hpp:435
Definition: EnvProperties.hpp:53
void setWriteResults(bool WriteIt)
Definition: RuntimeEnv.hpp:449
#define DLLEXPORT
Definition: dllexport.hpp:51