All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimulationDrivenWare.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  \file SimulationDrivenWare.hpp
35  \brief Header of ...
36 
37  \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __SIMULATIONDRIVENWARE_HPP__
42 #define __SIMULATIONDRIVENWARE_HPP__
43 
44 
51 #include <openfluid/dllexport.hpp>
52 
53 
54 #define REQUIRE_SIMULATION_STAGE(stage,sender,msg) \
55  if (OPENFLUID_GetCurrentStage() != (stage)) \
56  throw openfluid::base::FrameworkException(sender,msg);
57 
58 #define REQUIRE_SIMULATION_STAGE_GE(stage,sender,msg) \
59  if (OPENFLUID_GetCurrentStage() < (stage)) \
60  throw openfluid::base::FrameworkException(sender,msg);
61 
62 #define REQUIRE_SIMULATION_STAGE_LE(stage,sender,msg) \
63  if (OPENFLUID_GetCurrentStage() > (stage)) \
64  throw openfluid::base::FrameworkException(sender,msg);
65 
66 
67 namespace openfluid { namespace ware {
68 
69 
71 {
72  private:
73 
74  const openfluid::base::SimulationStatus* mp_SimStatus;
75 
76  openfluid::core::TimeIndex_t m_PreviousTimeIndex;
77 
78 
79  protected:
80 
81 
82  /**
83  Pointer to the execution messages repository
84  */
86 
87 
88  virtual bool isLinked() const { return (PluggableWare::isLinked() && mp_SimLogger != NULL && mp_SimStatus != NULL); };
89 
90  /**
91  Returns the real beginning date of the simulated period
92  @return the date
93  */
94  openfluid::core::DateTime OPENFLUID_GetBeginDate() const;
95 
96  /**
97  Returns the real ending date of the simulated period
98  @return the date
99  */
100  openfluid::core::DateTime OPENFLUID_GetEndDate() const;
101 
102  /**
103  Returns the current real date corresponding to the current time index
104  @return the date
105  */
106  openfluid::core::DateTime OPENFLUID_GetCurrentDate() const;
107 
108  /**
109  Returns the simulation duration in seconds
110  @return the duration in seconds
111  */
112  openfluid::core::Duration_t OPENFLUID_GetSimulationDuration() const;
113 
114  /**
115  Returns the default DeltaT used by the scheduler
116  @return the deltaT in seconds
117  */
118  openfluid::core::Duration_t OPENFLUID_GetDefaultDeltaT() const;
119 
120  /**
121  Returns the current time index of the simulation, in seconds since the simulation started.
122  When the simulation starts, the time index is equal to zero.
123  @return the current time index in seconds
124  */
125  openfluid::core::TimeIndex_t OPENFLUID_GetCurrentTimeIndex() const;
126 
127  /**
128  Returns the time index of the simulation when the plugged ware was previously run
129  @return the time index in seconds
130  */
131  openfluid::core::TimeIndex_t OPENFLUID_GetPreviousRunTimeIndex() const;
132 
133  /**
134  Returns the current stage of the simulation
135  @return the stage
136  */
137  openfluid::base::SimulationStatus::SimulationStage OPENFLUID_GetCurrentStage() const;
138 
139  /**
140  Returns the scheduling constraint applied to the simulation (may be NONE)
141  @return the constraint type
142  */
143  openfluid::base::SimulationStatus::SchedulingConstraint OPENFLUID_GetSchedulingConstraint() const;
144 
145  /**
146  Raises a time-marked warning message to the kernel. This do not stops the simulation
147  @param[in] Msg the content of the message
148  */
149  virtual void OPENFLUID_RaiseWarning(const std::string& Msg);
150 
151  /**
152  Raises a time-marked warning message to the kernel. This do not stops the simulation
153  @param[in] Source the source of the message
154  @param[in] Msg the content of the message
155  */
156  virtual void OPENFLUID_RaiseWarning(const std::string& Source, const std::string& Msg);
157 
158  /**
159  Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
160  @param[in] Msg the content of the message
161  */
162  virtual void OPENFLUID_RaiseError(const std::string& Msg);
163 
164  /**
165  Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
166  @param[in] Source the source of the message
167  @param[in] Msg the content of the message
168  */
169  virtual void OPENFLUID_RaiseError(const std::string& Source, const std::string& Msg);
170 
172 
174  mp_SimStatus(NULL), m_PreviousTimeIndex(0), mp_SimLogger(NULL) { };
175 
176 
177  public:
178 
180  { };
181 
182  void linkToSimulation(const openfluid::base::SimulationStatus* SimStatus);
183 
185  {
186  mp_SimLogger = SimLogger;
187  };
188 
189  void initializeWare(const WareID_t& ID);
190 
191  void finalizeWare();
192 
193  void setPreviousTimeIndex(const openfluid::core::TimeIndex_t& TimeIndex) { m_PreviousTimeIndex = TimeIndex; };
194 
195 };
196 
197 
198 
199 } } // openfluid::ware
200 
201 
202 
203 #endif /* __SIMULATIONDRIVENWARE_HPP__ */
unsigned long long TimeIndex_t
Definition: DateTime.hpp:62
void setPreviousTimeIndex(const openfluid::core::TimeIndex_t &TimeIndex)
Definition: SimulationDrivenWare.hpp:193
virtual bool isLinked() const
Definition: SimulationDrivenWare.hpp:88
Header of ...
Class for management of date and time information.
Definition: DateTime.hpp:131
Definition: SimulationLogger.hpp:61
Definition: SimulationDrivenWare.hpp:70
WareType
Definition: PluggableWare.hpp:93
void linkToSimulationLogger(openfluid::base::SimulationLogger *SimLogger)
Definition: SimulationDrivenWare.hpp:184
SimulationDrivenWare(WareType WType)
Definition: SimulationDrivenWare.hpp:173
std::string WareID_t
Definition: WareSignature.hpp:86
openfluid::base::SimulationLogger * mp_SimLogger
Definition: SimulationDrivenWare.hpp:85
virtual bool isLinked() const
Definition: PluggableWare.hpp:111
SchedulingConstraint
Definition: SimulationStatus.hpp:62
Definition: SimulationStatus.hpp:56
virtual ~SimulationDrivenWare()
Definition: SimulationDrivenWare.hpp:179
SimulationStage
Definition: SimulationStatus.hpp:60
unsigned long long Duration_t
Definition: DateTime.hpp:68
Definition: StdoutFileOStream.hpp:60
Definition: PluggableWare.hpp:89
openfluid::base::StdoutAndFileOutputStream OPENFLUID_Logger
Definition: SimulationDrivenWare.hpp:171
Header of ...
Header of ...
Header of ...
#define DLLEXPORT
Definition: dllexport.hpp:51