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 _M_##loopid##_UList = mp_CoreData->getUnits(unitclass)->getList(); \
00189 if (_M_##loopid##_UList != NULL) \
00190 { \
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 { \
00203 _M_##loopid##_GUList = mp_CoreData->getUnitsGlobally(); \
00204 for (_M_##loopid##_ordit = _M_##loopid##_GUList->begin();_M_##loopid##_ordit != _M_##loopid##_GUList->end();++_M_##loopid##_ordit) \
00205 { \
00206 unit = (*_M_##loopid##_ordit);
00207
00208
00213 #define DECLARE_UNITS_LIST_LOOP(loopid) \
00214 openfluid::core::UnitsPtrList_t::iterator _M_##loopid##_lstit;\
00215
00216
00223 #define BEGIN_UNITS_LIST_LOOP(loopid,ulist,unit) \
00224 if ((ulist) != NULL) \
00225 { \
00226 for(_M_##loopid##_lstit=ulist->begin(); _M_##loopid##_lstit != ulist->end(); _M_##loopid##_lstit++) \
00227 { \
00228 unit = *_M_##loopid##_lstit; \
00229
00230
00234 #define DECLARE_EVENT_COLLECTION_LOOP \
00235 std::list<openfluid::core::Event*>::iterator _M_EvListiter;
00236
00242 #define BEGIN_EVENT_COLLECTION_LOOP(evlist,evobj) \
00243 { \
00244 for(_M_EvListiter=(evlist)->begin(); _M_EvListiter != (evlist)->end(); _M_EvListiter++) \
00245 { \
00246 evobj = *_M_EvListiter;
00247
00251 #define END_LOOP \
00252 } \
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262 namespace openfluid { namespace base {
00263
00264
00265
00275 class DLLEXPORT PluggableFunction
00276 {
00277
00278 private:
00279
00283 openfluid::core::CoreRepository* mp_InternalCoreData;
00284
00285
00289 openfluid::base::ExecutionMessages* mp_ExecMsgs;
00290
00291
00295 const openfluid::base::EnvironmentProperties* mp_FunctionEnv;
00296
00297
00301 openfluid::core::FuncParamsMap_t m_ParamsMap;
00302
00306 openfluid::base::FuncID_t m_FunctionID;
00307
00308
00309 static bool IsUnitIDInPtrList(const openfluid::core::UnitsPtrList_t* UnitsList,
00310 const openfluid::core::UnitID_t& ID);
00311
00312 static std::string generateDotEdge(std::string SrcClass, std::string SrcID,
00313 std::string DestClass, std::string DestID,
00314 std::string Options);
00315
00316
00317
00318 protected:
00319
00320
00324 openfluid::core::CoreRepository* mp_CoreData;
00325
00326
00334 void OPENFLUID_GetVariable(openfluid::core::Unit *UnitPtr,
00335 openfluid::core::VariableName_t VarName,
00336 openfluid::core::TimeStep_t Step,
00337 openfluid::core::ScalarValue *Value);
00338
00346 void OPENFLUID_GetVariable(openfluid::core::Unit *UnitPtr,
00347 openfluid::core::VariableName_t VarName,
00348 openfluid::core::TimeStep_t Step,
00349 openfluid::core::VectorValue *Value);
00350
00357 void OPENFLUID_GetInputData(openfluid::core::Unit *UnitPtr,
00358 openfluid::core::InputDataName_t InputName,
00359 double *Value);
00360
00367 void OPENFLUID_GetInputData(openfluid::core::Unit *UnitPtr,
00368 openfluid::core::InputDataName_t InputName,
00369 long *Value);
00370
00377 void OPENFLUID_GetInputData(openfluid::core::Unit *UnitPtr,
00378 openfluid::core::InputDataName_t InputName,
00379 std::string *Value);
00380
00387 void OPENFLUID_SetInputData(openfluid::core::Unit *UnitPtr,
00388 const openfluid::core::InputDataName_t& InputName,
00389 const double& Value);
00390
00397 void OPENFLUID_SetInputData(openfluid::core::Unit *UnitPtr,
00398 const openfluid::core::InputDataName_t& InputName,
00399 const long& Value);
00400
00407 void OPENFLUID_SetInputData(openfluid::core::Unit *UnitPtr,
00408 const openfluid::core::InputDataName_t& InputName,
00409 const std::string& Value);
00410
00411
00417 bool OPENFLUID_IsInputDataExist(openfluid::core::Unit *UnitPtr,
00418 openfluid::core::InputDataName_t InputName);
00419
00420
00421
00427 bool OPENFLUID_IsVariableExist(openfluid::core::Unit *UnitPtr,
00428 openfluid::core::VariableName_t VarName);
00429
00435 bool OPENFLUID_IsScalarVariableExist(openfluid::core::Unit *UnitPtr,
00436 openfluid::core::VariableName_t VarName);
00437
00443 bool OPENFLUID_IsVectorVariableExist(openfluid::core::Unit *UnitPtr,
00444 openfluid::core::VariableName_t VarName);
00445
00446
00453 bool OPENFLUID_IsVariableExist(openfluid::core::Unit *UnitPtr,
00454 openfluid::core::VariableName_t VarName,
00455 openfluid::core::TimeStep_t Step);
00456
00463 bool OPENFLUID_IsScalarVariableExist(openfluid::core::Unit *UnitPtr,
00464 openfluid::core::VariableName_t VarName,
00465 openfluid::core::TimeStep_t Step);
00466
00473 bool OPENFLUID_IsVectorVariableExist(openfluid::core::Unit *UnitPtr,
00474 openfluid::core::VariableName_t VarName,
00475 openfluid::core::TimeStep_t Step);
00476
00483 void OPENFLUID_AppendVariable(openfluid::core::Unit *UnitPtr,
00484 openfluid::core::VariableName_t VarName,
00485 openfluid::core::ScalarValue Value);
00486
00493 void OPENFLUID_AppendVariable(openfluid::core::Unit *UnitPtr,
00494 openfluid::core::VariableName_t VarName,
00495 openfluid::core::VectorValue& Value);
00496
00504 void OPENFLUID_SetVariable(openfluid::core::Unit *UnitPtr,
00505 openfluid::core::VariableName_t VarName,
00506 openfluid::core::TimeStep_t Step,
00507 openfluid::core::ScalarValue Value);
00508
00516 void OPENFLUID_SetVariable(openfluid::core::Unit *UnitPtr,
00517 openfluid::core::VariableName_t VarName,
00518 openfluid::core::TimeStep_t Step,
00519 openfluid::core::VectorValue Value);
00520
00527 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00528 openfluid::core::FuncParamKey_t ParamName,
00529 double *Value);
00530
00537 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00538 openfluid::core::FuncParamKey_t ParamName,
00539 long *Value);
00540
00547 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00548 openfluid::core::FuncParamKey_t ParamName,
00549 float *Value);
00550
00557 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00558 openfluid::core::FuncParamKey_t ParamName,
00559 int *Value);
00560
00567 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00568 openfluid::core::FuncParamKey_t ParamName,
00569 std::string *Value);
00570
00577 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00578 openfluid::core::FuncParamKey_t ParamName,
00579 std::vector<std::string> *Values);
00580
00581
00588 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00589 openfluid::core::FuncParamKey_t ParamName,
00590 std::vector<double> *Values);
00591
00592
00599 bool OPENFLUID_GetFunctionParameter(openfluid::core::FuncParamsMap_t Params,
00600 openfluid::core::FuncParamKey_t ParamName,
00601 std::vector<long> *Values);
00602
00603
00611 void OPENFLUID_GetEvents(openfluid::core::Unit *UnitPtr,
00612 openfluid::core::DateTime BeginDate,
00613 openfluid::core::DateTime EndDate,
00614 openfluid::core::EventsCollection* Events);
00615
00616
00622 void OPENFLUID_AppendEvent(openfluid::core::Unit *UnitPtr,
00623 openfluid::core::Event& Ev);
00624
00625
00626
00631 bool OPENFLUID_IsUnitClassExist(openfluid::core::UnitClass_t ClassName);
00632
00633
00639 bool OPENFLUID_IsUnitExist(openfluid::core::UnitClass_t ClassName,
00640 openfluid::core::UnitID_t ID);
00641
00646 void OPENFLUID_GetUnitsCount(unsigned int& UnitsCount);
00647
00654 bool OPENFLUID_GetUnitsCount(const openfluid::core::UnitClass_t ClassName,
00655 unsigned int& UnitsCount);
00656
00657
00665 bool OPENFLUID_GetUnit(const openfluid::core::UnitClass_t& ClassName,
00666 const openfluid::core::UnitID_t& ID,
00667 openfluid::core::Unit* aUnit);
00668
00669 openfluid::core::Unit* OPENFLUID_GetUnit(const openfluid::core::UnitClass_t& ClassName,
00670 const openfluid::core::UnitID_t& ID);
00671
00677 void OPENFLUID_AddUnit(openfluid::core::UnitClass_t ClassName,
00678 openfluid::core::UnitID_t ID,
00679 openfluid::core::PcsOrd_t PcsOrder);
00680
00687 void OPENFLUID_DeleteUnit(openfluid::core::UnitClass_t ClassName,
00688 openfluid::core::UnitID_t ID);
00689
00690
00699 bool OPENFLUID_AddFromToConnection(openfluid::core::UnitClass_t ClassNameFrom,
00700 openfluid::core::UnitID_t IDFrom,
00701 openfluid::core::UnitClass_t ClassNameTo,
00702 openfluid::core::UnitID_t IDTo);
00703
00710 bool OPENFLUID_AddFromToConnection(openfluid::core::Unit* FromUnit,
00711 openfluid::core::Unit* ToUnit);
00712
00721 bool OPENFLUID_RemoveFromToConnection(openfluid::core::UnitClass_t ClassNameFrom,
00722 openfluid::core::UnitID_t IDFrom,
00723 openfluid::core::UnitClass_t ClassNameTo,
00724 openfluid::core::UnitID_t IDTo);
00725
00732 bool OPENFLUID_RemoveFromToConnection(openfluid::core::Unit* FromUnit,
00733 openfluid::core::Unit* ToUnit);
00734
00735
00744 bool OPENFLUID_AddChildParentConnection(openfluid::core::UnitClass_t ClassNameChild,
00745 openfluid::core::UnitID_t IDChild,
00746 openfluid::core::UnitClass_t ClassNameParent,
00747 openfluid::core::UnitID_t IDParent);
00748
00755 bool OPENFLUID_AddChildParentConnection(openfluid::core::Unit* ChildUnit,
00756 openfluid::core::Unit* ParentUnit);
00757
00758
00767 bool OPENFLUID_RemoveChildParentConnection(openfluid::core::UnitClass_t ClassNameChild,
00768 openfluid::core::UnitID_t IDChild,
00769 openfluid::core::UnitClass_t ClassNameParent,
00770 openfluid::core::UnitID_t IDParent);
00771
00778 bool OPENFLUID_RemoveChildParentConnection(openfluid::core::Unit* ChildUnit,
00779 openfluid::core::Unit* ParentUnit);
00780
00788 bool OPENFLUID_IsUnitConnectedTo(openfluid::core::Unit* aUnit,
00789 const openfluid::core::UnitClass_t& ClassNameTo,
00790 const openfluid::core::UnitID_t& IDTo);
00791
00792
00800 bool OPENFLUID_IsUnitConnectedFrom(openfluid::core::Unit* aUnit,
00801 const openfluid::core::UnitClass_t& ClassNameFrom,
00802 const openfluid::core::UnitID_t& IDFrom);
00803
00804
00812 bool OPENFLUID_IsUnitChildOf(openfluid::core::Unit* aUnit,
00813 const openfluid::core::UnitClass_t& ClassNameParent,
00814 const openfluid::core::UnitID_t& IDParent);
00815
00816
00824 bool OPENFLUID_IsUnitParentOf(openfluid::core::Unit* aUnit,
00825 const openfluid::core::UnitClass_t& ClassNameChild,
00826 const openfluid::core::UnitID_t& IDChild);
00827
00828
00835 void OPENFLUID_BuildUnitsMatrix(const openfluid::core::UnitClass_t& UnitsClass,
00836 const unsigned int& ColsNbr,
00837 const unsigned int& RowsNbr);
00838
00839
00845 void OPENFLUID_ExportUnitsGraphAsDotFile(const std::string& Filename);
00846
00853 void OPENFLUID_RaiseWarning(std::string Sender, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00854
00860 void OPENFLUID_RaiseWarning(std::string Sender, std::string Msg);
00861
00869 void OPENFLUID_RaiseWarning(std::string Sender, std::string Source, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00870
00877 void OPENFLUID_RaiseWarning(std::string Sender, std::string Source, std::string Msg);
00878
00879
00886 void OPENFLUID_RaiseError(std::string Sender, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00887
00893 void OPENFLUID_RaiseError(std::string Sender, std::string Msg);
00894
00902 void OPENFLUID_RaiseError(std::string Sender, std::string Source, openfluid::core::TimeStep_t TimeStep, std::string Msg);
00903
00910 void OPENFLUID_RaiseError(std::string Sender, std::string Source, std::string Msg);
00911
00912
00918 bool OPENFLUID_GetRunEnvironment(std::string Key, std::string *Value);
00919
00925 bool OPENFLUID_GetRunEnvironment(std::string Key, bool *Value);
00926
00927
00928 StdoutAndFileOutputStream OPENFLUID_Logger;
00929
00930
00931 public:
00935 PluggableFunction();
00936
00940 virtual ~PluggableFunction();
00941
00942 void setDataRepository(openfluid::core::CoreRepository* CoreData) { mp_CoreData = CoreData; mp_InternalCoreData = CoreData;};
00943
00944 void setExecutionMessages(openfluid::base::ExecutionMessages* ExecMsgs) { mp_ExecMsgs = ExecMsgs; };
00945
00946 void setFunctionEnvironment(openfluid::base::EnvironmentProperties* FuncEnv) { mp_FunctionEnv = FuncEnv; };
00947
00948 void setFunctionID(const openfluid::base::FuncID_t& FuncID) { m_FunctionID = FuncID; };
00949
00950 void initLogger();
00951
00952
00956 virtual bool initParams(openfluid::core::FuncParamsMap_t Params)=0;
00957
00961 virtual bool prepareData()=0;
00962
00966 virtual bool checkConsistency()=0;
00967
00968
00972 virtual bool initializeRun(const SimulationInfo* SimInfo)=0;
00973
00977 virtual bool runStep(const SimulationStatus* SimStatus)=0;
00978
00982 virtual bool finalizeRun(const SimulationInfo* SimInfo)=0;
00983
00984 };
00985
00986
00987 typedef PluggableFunction* (*GetPluggableFunctionProc)();
00988
00989 typedef FunctionSignature* (*GetSignatureProc)();
00990
00991 typedef std::string (*GetSDKVersionProc)();
00992
00993
00994
00995 } }
00996
00997
00998
00999 #endif
01000