ware/SimulationDrivenWare.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 /**
00034   \file SimulationDrivenWare.hpp
00035   \brief Header of ...
00036 
00037   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00038  */
00039 
00040 
00041 #ifndef __SIMULATIONDRIVENWARE_HPP__
00042 #define __SIMULATIONDRIVENWARE_HPP__
00043 
00044 
00045 #include <openfluid/ware/PluggableWare.hpp>
00046 #include <openfluid/base/SimulationLogger.hpp>
00047 #include <openfluid/base/StdoutFileOStream.hpp>
00048 #include <openfluid/ware/WareException.hpp>
00049 #include <openfluid/base/SimulationStatus.hpp>
00050 #include <openfluid/base/FrameworkException.hpp>
00051 #include <openfluid/dllexport.hpp>
00052 
00053 
00054 #define REQUIRE_SIMULATION_STAGE(stage,sender,msg) \
00055   if (OPENFLUID_GetCurrentStage() != (stage)) \
00056     throw openfluid::base::FrameworkException(sender,msg);
00057 
00058 #define REQUIRE_SIMULATION_STAGE_GE(stage,sender,msg) \
00059   if (OPENFLUID_GetCurrentStage() < (stage)) \
00060     throw openfluid::base::FrameworkException(sender,msg);
00061 
00062 #define REQUIRE_SIMULATION_STAGE_LE(stage,sender,msg) \
00063   if (OPENFLUID_GetCurrentStage() > (stage)) \
00064     throw openfluid::base::FrameworkException(sender,msg);
00065 
00066 
00067 namespace openfluid { namespace ware {
00068 
00069 
00070 class DLLEXPORT SimulationDrivenWare : public PluggableWare
00071 {
00072   private:
00073 
00074     const openfluid::base::SimulationStatus* mp_SimStatus;
00075 
00076     openfluid::core::TimeIndex_t m_PreviousTimeIndex;
00077 
00078 
00079   protected:
00080 
00081 
00082     /**
00083       Pointer to the execution messages repository
00084      */
00085     openfluid::base::SimulationLogger* mp_SimLogger;
00086 
00087 
00088     virtual bool isLinked() const { return (PluggableWare::isLinked() &&  mp_SimLogger != NULL && mp_SimStatus != NULL); };
00089 
00090     /**
00091       Returns the real beginning date of the simulated period
00092       @return the date
00093     */
00094     openfluid::core::DateTime OPENFLUID_GetBeginDate() const;
00095 
00096     /**
00097       Returns the real ending date of the simulated period
00098       @return the date
00099     */
00100     openfluid::core::DateTime OPENFLUID_GetEndDate() const;
00101 
00102     /**
00103       Returns the current real date corresponding to the current time index
00104       @return the date
00105     */
00106     openfluid::core::DateTime OPENFLUID_GetCurrentDate() const;
00107 
00108     /**
00109       Returns the simulation duration in seconds
00110       @return the duration in seconds
00111     */
00112     openfluid::core::Duration_t OPENFLUID_GetSimulationDuration() const;
00113 
00114     /**
00115       Returns the default DeltaT used by the scheduler
00116       @return the deltaT in seconds
00117     */
00118     openfluid::core::Duration_t OPENFLUID_GetDefaultDeltaT() const;
00119 
00120     /**
00121       Returns the current time index of the simulation, in seconds since the simulation started.
00122       When the simulation starts, the time index is equal to zero.
00123       @return the current time index in seconds
00124     */
00125     openfluid::core::TimeIndex_t OPENFLUID_GetCurrentTimeIndex() const;
00126 
00127     /**
00128       Returns the time index of the simulation when the plugged ware was previously run
00129       @return the time index in seconds
00130     */
00131     openfluid::core::TimeIndex_t OPENFLUID_GetPreviousRunTimeIndex() const;
00132 
00133     /**
00134       Returns the current stage of the simulation
00135       @return the stage
00136     */
00137     openfluid::base::SimulationStatus::SimulationStage OPENFLUID_GetCurrentStage() const;
00138 
00139     /**
00140       Returns the scheduling constraint applied to the simulation (may be NONE)
00141       @return the constraint type
00142     */
00143     openfluid::base::SimulationStatus::SchedulingConstraint OPENFLUID_GetSchedulingConstraint() const;
00144 
00145     /**
00146       Raises a time-marked warning message to the kernel. This do not stops the simulation
00147       @param[in] Msg the content of the message
00148     */
00149     virtual void OPENFLUID_RaiseWarning(const std::string& Msg);
00150 
00151     /**
00152       Raises a time-marked warning message to the kernel. This do not stops the simulation
00153       @param[in] Source the source of the message
00154       @param[in] Msg the content of the message
00155     */
00156     virtual void OPENFLUID_RaiseWarning(const std::string& Source, const std::string& Msg);
00157 
00158     /**
00159       Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
00160       @param[in] Msg the content of the message
00161     */
00162     virtual void OPENFLUID_RaiseError(const std::string& Msg);
00163 
00164     /**
00165       Raises an error message to the kernel. This stops the simulation the next time the kernel has the control
00166       @param[in] Source the source of the message
00167       @param[in] Msg the content of the message
00168     */
00169     virtual void OPENFLUID_RaiseError(const std::string& Source, const std::string& Msg);
00170 
00171     openfluid::base::StdoutAndFileOutputStream OPENFLUID_Logger;
00172 
00173     SimulationDrivenWare(WareType WType) : PluggableWare(WType),
00174         mp_SimStatus(NULL), m_PreviousTimeIndex(0), mp_SimLogger(NULL) { };
00175 
00176 
00177   public:
00178 
00179     virtual ~SimulationDrivenWare()
00180     { };
00181 
00182     void linkToSimulation(const openfluid::base::SimulationStatus* SimStatus);
00183 
00184     void linkToSimulationLogger(openfluid::base::SimulationLogger* SimLogger)
00185     {
00186       mp_SimLogger = SimLogger;
00187     };
00188 
00189     void initializeWare(const WareID_t& ID);
00190 
00191     void finalizeWare();
00192 
00193     void setPreviousTimeIndex(const openfluid::core::TimeIndex_t& TimeIndex) { m_PreviousTimeIndex = TimeIndex; };
00194 
00195 };
00196 
00197 
00198 
00199 } } // openfluid::ware
00200 
00201 
00202 
00203 #endif /* __SIMULATIONDRIVENWARE_HPP__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines