00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00071 #ifndef __PLUGFUNCTION_HPP__
00072 #define __PLUGFUNCTION_HPP__
00073
00074 #include <string>
00075
00076 #include <boost/filesystem/path.hpp>
00077
00078 #include <openfluid/dllexport.hpp>
00079 #include <openfluid/core.hpp>
00080 #include <openfluid/base/SimStatus.hpp>
00081 #include <openfluid/base/ExecMsgs.hpp>
00082 #include <openfluid/base/EnvProperties.hpp>
00083 #include <openfluid/base/FuncSignature.hpp>
00084 #include <openfluid/base/StdoutFileOStream.hpp>
00085
00086
00087
00088
00089 #ifdef WIN32
00090 #ifdef BUILDPLUGDLL
00091 #define DLLIMPORT __declspec(dllexport)
00092 #else
00093 #define DLLIMPORT __declspec(dllimport)
00094 #endif
00095 #define CALL __stdcall
00096 #else
00097 #define DLLIMPORT
00098 #define CALL
00099 #endif
00100
00101
00102 #define STRINGIFY(x) XSTRINGIFY(x)
00103 #define XSTRINGIFY(x) #x
00104
00105
00106
00107
00111 #define PLUGFUNCTION_PROC_NAME "GetPlugFunction"
00112
00116 #define PLUGSIGNATURE_PROC_NAME "GetPlugSignature"
00117
00121 #define PLUGSDKVERSION_PROC_NAME "GetPlugSDKVersion"
00122
00123
00124
00128 #define DECLARE_PLUGIN_HOOKS \
00129 extern "C" \
00130 { \
00131 DLLIMPORT std::string GetPlugSDKVersion(); \
00132 DLLIMPORT openfluid::base::PluggableFunction* GetPlugFunction(); \
00133 DLLIMPORT openfluid::base::FunctionSignature* GetPlugSignature(); \
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00147 #define DEFINE_FUNCTION_HOOK(pluginclassname) \
00148 std::string GetPlugSDKVersion() \
00149 { \
00150 return std::string(STRINGIFY(OPENFLUID_VERSION)); \
00151 } \
00152 \
00153 openfluid::base::PluggableFunction* GetPlugFunction() \
00154 { \
00155 return new pluginclassname(); \
00156 }
00157
00158
00159
00160
00161
00162
00167 #define DECLARE_UNITS_ORDERED_LOOP(loopid) \
00168 openfluid::core::UnitsList_t::iterator _M_##loopid##_ordit;\
00169 openfluid::core::UnitsList_t* _M_##loopid##_UList;
00170
00171
00176 #define DECLARE_GLOBAL_UNITS_ORDERED_LOOP(loopid) \
00177 openfluid::core::UnitsPtrList_t::iterator _M_##loopid##_ordit;\
00178 openfluid::core::UnitsPtrList_t* _M_##loopid##_GUList;
00179
00180
00187 #define BEGIN_UNITS_ORDERED_LOOP(loopid,unitclass,unit) \
00188 if (!mp_CoreData->isUnitsClassExist(unitclass)) \
00189 throw openfluid::base::OFException("OpenFLUID framework","BEGIN_UNITS_ORDERED_LOOP","Unit class " + std::string(unitclass) + " does not exists"); \
00190 _M_##loopid##_UList = mp_CoreData->getUnits(unitclass)->getList(); \
00191 for (_M_##loopid##_ordit = _M_##loopid##_UList->begin();_M_##loopid##_ordit != _M_##loopid##_UList->end();++_M_##loopid##_ordit) \
00192 { \
00193 unit = &(*_M_##loopid##_ordit);
00194
00195
00201 #define BEGIN_GLOBAL_UNITS_ORDERED_LOOP(loopid,unit) \
00202 _M_##loopid##_GUList = mp_CoreData->getUnitsGlobally(); \
00203 for (_M_##loopid##_ordit = _M_##loopid##_GUList->begin();_M_##loopid##_ordit != _M_##loopid##_GUList->end();++_M_##loopid##_ordit) \
00204 { \
00205 unit = (*_M_##loopid##_ordit);
00206
00207
00212 #define DECLARE_UNITS_LIST_LOOP(loopid) \
00213 openfluid::core::UnitsPtrList_t::iterator _M_##loopid##_lstit;\
00214
00215
00222 #define BEGIN_UNITS_LIST_LOOP(loopid,ulist,unit) \
00223 for(_M_##loopid##_lstit=ulist->begin(); _M_##loopid##_lstit != ulist->end(); _M_##loopid##_lstit++) \
00224 { \
00225 unit = *_M_##loopid##_lstit; \
00226
00227
00231 #define DECLARE_EVENT_COLLECTION_LOOP \
00232 std::list<openfluid::core::Event*>::iterator _M_EvListiter;
00233
00239 #define BEGIN_EVENT_COLLECTION_LOOP(evlist,evobj) \
00240 for(_M_EvListiter=(evlist)->begin(); _M_EvListiter != (evlist)->end(); _M_EvListiter++) \
00241 { \
00242 evobj = *_M_EvListiter;
00243
00247 #define END_LOOP }
00248
00249
00250
00251
00252
00253
00254
00255
00256 namespace openfluid { namespace base {
00257
00258
00259
00269 class DLLEXPORT PluggableFunction
00270 {
00271
00272 private:
00273
00277 openfluid::core::CoreRepository* mp_InternalCoreData;
00278
00279
00283 openfluid::base::ExecutionMessages* mp_ExecMsgs;
00284
00285
00289 const openfluid::base::EnvironmentProperties* mp_FunctionEnv;
00290
00291
00295 openfluid::core::FuncParamsMap_t m_ParamsMap;
00296
00300 openfluid::base::FuncID_t m_FunctionID;
00301
00302
00303 static bool IsUnitIDInPtrList(const openfluid::core::UnitsPtrList_t* UnitsList,
00304 const openfluid::core::UnitID_t& ID);
00305
00306 static std::string generateDotEdge(std::string SrcClass, std::string SrcID,
00307 std::string DestClass, std::string DestID,
00308 std::string Options);
00309
00310
00311
00312 protected:
00313
00314
00318 openfluid::core::CoreRepository* mp_CoreData;
00319
00320
00328 void OPENFLUID_GetVariable(openfluid::core::Unit *UnitPtr,
00329 openfluid::core::VariableName_t VarName,
00330 openfluid::core::TimeStep_t Step,
00331 openfluid::core::ScalarValue *Value);
00332
00340 void OPENFLUID_GetVariable(openfluid::core::Unit *UnitPtr,
00341 openfluid::core::VariableName_t VarName,
00342 openfluid::core::TimeStep_t Step,
00343 openfluid::core::VectorValue *Value);
00344
00351 void OPENFLUID_GetInputData(openfluid::core::Unit *UnitPtr,
00352 openfluid::core::InputDataName_t InputName,
00353 double *Value);
00354
00361 void OPENFLUID_GetInputData(openfluid::core::Unit *UnitPtr,
00362 openfluid::core::InputDataName_t InputName,
00363 long *Value);
00364
00371 void OPENFLUID_GetInputData(openfluid::core::Unit *UnitPtr,
00372 openfluid::core::InputDataName_t InputName,
00373 std::string *Value);
00374
00381 void OPENFLUID_SetInputData(openfluid::core::Unit *UnitPtr,
00382 const openfluid::core::InputDataName_t& InputName,
00383 const double& Value);
00384
00391 void OPENFLUID_SetInputData(openfluid::core::Unit *UnitPtr,
00392 const openfluid::core::InputDataName_t& InputName,
00393 const long& Value);
00394
00401 void OPENFLUID_SetInputData(openfluid::core::Unit *UnitPtr,
00402 const openfluid::core::InputDataName_t& InputName,
00403 const std::string& Value);
00404
00405
00411 bool OPENFLUID_IsInputDataExist(openfluid::core::Unit *UnitPtr,
00412 openfluid::core::InputDataName_t InputName);
00413
00414
00415
00421 bool OPENFLUID_IsVariableExist(openfluid::core::Unit *UnitPtr,
00422 openfluid::core::VariableName_t VarName);
00423
00429 bool OPENFLUID_IsScalarVariableExist(openfluid::core::Unit *UnitPtr,
00430 openfluid::core::VariableName_t VarName);
00431
00437 bool OPENFLUID_IsVectorVariableExist(openfluid::core::Unit *UnitPtr,
00438 openfluid::core::VariableName_t VarName);
00439
00440
00447 bool OPENFLUID_IsVariableExist(openfluid::core::Unit *UnitPtr,
00448 openfluid::core::VariableName_t VarName,
00449 openfluid::core::TimeStep_t Step);
00450
00457 bool OPENFLUID_IsScalarVariableExist(openfluid::core::Unit *UnitPtr,
00458 openfluid::core::VariableName_t VarName,
00459 openfluid::core::TimeStep_t Step);
00460
00467 bool OPENFLUID_IsVectorVariableExist(openfluid::core::Unit *UnitPtr,
00468 openfluid::core::VariableName_t VarName,
00469 openfluid::core::TimeStep_t Step);
00470
00477 void OPENFLUID_AppendVariable(openfluid::core::Unit *UnitPtr,
00478 openfluid::core::VariableName_t VarName,
00479 openfluid::core::ScalarValue Value);
00480
00487 void OPENFLUID_AppendVariable(openfluid::core::Unit *UnitPtr,
00488 openfluid::core::VariableName_t VarName,
00489 openfluid::core::VectorValue& Value);
00490
00498 void OPENFLUID_SetVariable(openfluid::core::Unit *UnitPtr,
00499 openfluid::core::VariableName_t VarName,
00500 openfluid::core::TimeStep_t Step,
00501 openfluid::core::ScalarValue Value);
00502
00510 void OPENFLUID_SetVariable(openfluid::core::Unit *UnitPtr,
00511 openfluid::core::VariableName_t VarName,
00512 openfluid::core::TimeStep_t Step,
00513 openfluid::core::VectorValue Value);
00514
00521 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00522 openfluid::core::FuncParamKey_t ParamName,
00523 double *Value);
00524
00531 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00532 openfluid::core::FuncParamKey_t ParamName,
00533 long *Value);
00534
00541 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00542 openfluid::core::FuncParamKey_t ParamName,
00543 float *Value);
00544
00551 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00552 openfluid::core::FuncParamKey_t ParamName,
00553 int *Value);
00554
00561 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00562 openfluid::core::FuncParamKey_t ParamName,
00563 std::string *Value);
00564
00571 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00572 openfluid::core::FuncParamKey_t ParamName,
00573 std::vector<std::string> *Values);
00574
00575
00582 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00583 openfluid::core::FuncParamKey_t ParamName,
00584 std::vector<double> *Values);
00585
00586
00593 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00594 openfluid::core::FuncParamKey_t ParamName,
00595 std::vector<long> *Values);
00596
00597
00605 void OPENFLUID_GetEvents(openfluid::core::Unit *UnitPtr,
00606 openfluid::core::DateTime BeginDate,
00607 openfluid::core::DateTime EndDate,
00608 openfluid::core::EventsCollection* Events);
00609
00610
00616 void OPENFLUID_AppendEvent(openfluid::core::Unit *UnitPtr,
00617 openfluid::core::Event& Ev);
00618
00619
00620
00625 bool OPENFLUID_IsUnitClassExist(openfluid::core::UnitClass_t ClassName);
00626
00627
00633 bool OPENFLUID_IsUnitExist(openfluid::core::UnitClass_t ClassName,
00634 openfluid::core::UnitID_t ID);
00635
00640 void OPENFLUID_GetUnitsCount(unsigned int& UnitsCount);
00641
00648 bool OPENFLUID_GetUnitsCount(const openfluid::core::UnitClass_t ClassName,
00649 unsigned int& UnitsCount);
00650
00651
00659 bool OPENFLUID_GetUnit(const openfluid::core::UnitClass_t& ClassName,
00660 const openfluid::core::UnitID_t& ID,
00661 openfluid::core::Unit* aUnit);
00662
00663 openfluid::core::Unit* OPENFLUID_GetUnit(const openfluid::core::UnitClass_t& ClassName,
00664 const openfluid::core::UnitID_t& ID);
00665
00671 void OPENFLUID_AddUnit(openfluid::core::UnitClass_t ClassName,
00672 openfluid::core::UnitID_t ID,
00673 openfluid::core::PcsOrd_t PcsOrder);
00674
00681 void OPENFLUID_DeleteUnit(openfluid::core::UnitClass_t ClassName,
00682 openfluid::core::UnitID_t ID);
00683
00684
00693 bool OPENFLUID_AddFromToConnection(openfluid::core::UnitClass_t ClassNameFrom,
00694 openfluid::core::UnitID_t IDFrom,
00695 openfluid::core::UnitClass_t ClassNameTo,
00696 openfluid::core::UnitID_t IDTo);
00697
00704 bool OPENFLUID_AddFromToConnection(openfluid::core::Unit* FromUnit,
00705 openfluid::core::Unit* ToUnit);
00706
00715 bool OPENFLUID_RemoveFromToConnection(openfluid::core::UnitClass_t ClassNameFrom,
00716 openfluid::core::UnitID_t IDFrom,
00717 openfluid::core::UnitClass_t ClassNameTo,
00718 openfluid::core::UnitID_t IDTo);
00719
00726 bool OPENFLUID_RemoveFromToConnection(openfluid::core::Unit* FromUnit,
00727 openfluid::core::Unit* ToUnit);
00728
00729
00738 bool OPENFLUID_AddChildParentConnection(openfluid::core::UnitClass_t ClassNameChild,
00739 openfluid::core::UnitID_t IDChild,
00740 openfluid::core::UnitClass_t ClassNameParent,
00741 openfluid::core::UnitID_t IDParent);
00742
00749 bool OPENFLUID_AddChildParentConnection(openfluid::core::Unit* ChildUnit,
00750 openfluid::core::Unit* ParentUnit);
00751
00752
00761 bool OPENFLUID_RemoveChildParentConnection(openfluid::core::UnitClass_t ClassNameChild,
00762 openfluid::core::UnitID_t IDChild,
00763 openfluid::core::UnitClass_t ClassNameParent,
00764 openfluid::core::UnitID_t IDParent);
00765
00772 bool OPENFLUID_RemoveChildParentConnection(openfluid::core::Unit* ChildUnit,
00773 openfluid::core::Unit* ParentUnit);
00774
00782 bool OPENFLUID_IsUnitConnectedTo(openfluid::core::Unit* aUnit,
00783 const openfluid::core::UnitClass_t& ClassNameTo,
00784 const openfluid::core::UnitID_t& IDTo);
00785
00786
00794 bool OPENFLUID_IsUnitConnectedFrom(openfluid::core::Unit* aUnit,
00795 const openfluid::core::UnitClass_t& ClassNameFrom,
00796 const openfluid::core::UnitID_t& IDFrom);
00797
00798
00806 bool OPENFLUID_IsUnitChildOf(openfluid::core::Unit* aUnit,
00807 const openfluid::core::UnitClass_t& ClassNameParent,
00808 const openfluid::core::UnitID_t& IDParent);
00809
00810
00818 bool OPENFLUID_IsUnitParentOf(openfluid::core::Unit* aUnit,
00819 const openfluid::core::UnitClass_t& ClassNameChild,
00820 const openfluid::core::UnitID_t& IDChild);
00821
00822
00829 void OPENFLUID_BuildUnitsMatrix(const openfluid::core::UnitClass_t& UnitsClass,
00830 const unsigned int& ColsNbr,
00831 const unsigned int& RowsNbr);
00832
00833
00839 void OPENFLUID_ExportUnitsGraphAsDotFile(const std::string& Filename);
00840
00847 void OPENFLUID_RaiseWarning(std::string Sender, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00848
00854 void OPENFLUID_RaiseWarning(std::string Sender, std::string Msg);
00855
00863 void OPENFLUID_RaiseWarning(std::string Sender, std::string Source, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00864
00871 void OPENFLUID_RaiseWarning(std::string Sender, std::string Source, std::string Msg);
00872
00873
00880 void OPENFLUID_RaiseError(std::string Sender, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00881
00887 void OPENFLUID_RaiseError(std::string Sender, std::string Msg);
00888
00896 void OPENFLUID_RaiseError(std::string Sender, std::string Source, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00897
00904 void OPENFLUID_RaiseError(std::string Sender, std::string Source, std::string Msg);
00905
00906
00912 bool OPENFLUID_GetRunEnvironment(std::string Key, std::string *Value);
00913
00919 bool OPENFLUID_GetRunEnvironment(std::string Key, bool *Value);
00920
00921
00922 StdoutAndFileOutputStream OPENFLUID_Logger;
00923
00924
00925 public:
00929 PluggableFunction();
00930
00934 virtual ~PluggableFunction();
00935
00936 void setDataRepository(openfluid::core::CoreRepository* CoreData) { mp_CoreData = CoreData; mp_InternalCoreData = CoreData;};
00937
00938 void setExecutionMessages(openfluid::base::ExecutionMessages* ExecMsgs) { mp_ExecMsgs = ExecMsgs; };
00939
00940 void setFunctionEnvironment(openfluid::base::EnvironmentProperties* FuncEnv) { mp_FunctionEnv = FuncEnv; };
00941
00942 void setFunctionID(const openfluid::base::FuncID_t& FuncID) { m_FunctionID = FuncID; };
00943
00944 void initLogger();
00945
00946
00950 virtual bool initParams(openfluid::core::FuncParamsMap_t Params)=0;
00951
00955 virtual bool prepareData()=0;
00956
00960 virtual bool checkConsistency()=0;
00961
00962
00966 virtual bool initializeRun(const SimulationInfo* SimInfo)=0;
00967
00971 virtual bool runStep(const SimulationStatus* SimStatus)=0;
00972
00976 virtual bool finalizeRun(const SimulationInfo* SimInfo)=0;
00977
00978 };
00979
00980
00981 typedef PluggableFunction* (*GetPluggableFunctionProc)();
00982
00983 typedef FunctionSignature* (*GetSignatureProc)();
00984
00985 typedef std::string (*GetSDKVersionProc)();
00986
00987
00988
00989 } }
00990
00991
00992
00993 #endif
00994