PhysiologyEngineThunk.h
1 /* Distributed under the Apache License, Version 2.0.
2  See accompanying NOTICE file for details.*/
3 
4 #pragma once
5 
6 #include "cdm/CommonDefs.h"
7 // CDM Features in use
8 #include "cdm/PhysiologyEngine.h"
9 #include "cdm/engine/SEEventManager.h"
10 #include "cdm/utils/ScopedMutex.h"
11 
16 class CDM_DECL PhysiologyEngineThunk : public LoggerForward, public SEEventHandler
17 {
18 public:
19  PhysiologyEngineThunk(const std::string& dataDir = "./");
20  virtual ~PhysiologyEngineThunk();
21 
22  virtual void Clear();
23 
24  //virtual void SetConfigurationOverride(std::string const& config)=0; // Not Implemented
25 
26  bool SerializeFromFile(std::string const& filename, std::string const& data_requests, eSerializationFormat data_requests_format);
27  bool SerializeToFile(std::string const& filename);
28 
29  bool SerializeFromString(std::string const& state, std::string const& data_requests, eSerializationFormat format);
30  std::string SerializeToString(eSerializationFormat format);
31 
32  bool InitializeEngine(std::string const& patient_configuration, std::string const& data_requests, eSerializationFormat format);
33 
34  std::string GetInitialPatient(eSerializationFormat format);
35  std::string GetConditions(eSerializationFormat format);
36 
37  void LogToConsole(bool b);
38  void KeepLogMessages(bool keep);// Set this to true if you are going to pull messages from the engine
39  void SetLogFilename(std::string const& logfile);// Set to empty if no log file is wanted
40  std::string PullLogMessages(eSerializationFormat format);
41  void SetLoggerForward(LoggerForward* lf) { m_ForwardLogs = lf; }
42 
43  void KeepEventChanges(bool keep);
44  std::string PullEvents(eSerializationFormat format);
45  std::string PullActiveEvents(eSerializationFormat format);
46  std::string GetPatientAssessment(int type, eSerializationFormat format);
47  void SetEventHandler(SEEventHandler* eh) { m_ForwardEvents = eh; }
48 
49  bool ProcessActions(std::string const& actions, eSerializationFormat format);
50  std::string PullActiveActions(eSerializationFormat format);
51 
52  bool AdvanceTimeStep();
53  double GetTimeStep(std::string const& unit);
54 
55  size_t DataLength() const;
56  double* PullDataPtr();
57  void PullData(std::vector<double>& data);
58 
59  void ForwardDebug(const std::string& msg) override;
60  void ForwardInfo(const std::string& msg) override;
61  void ForwardWarning(const std::string& msg) override;
62  void ForwardError(const std::string& msg) override;
63  void ForwardFatal(const std::string& msg) override;
64 
65  void HandleEvent(eEvent type, bool active, const SEScalarTime* time = nullptr) override;
66 
67 protected:
68  virtual void AllocateEngine() = 0;
69  virtual void SetupDefaultDataRequests();
70  virtual bool SetupRequests();
71 
72  std::unique_ptr<PhysiologyEngine> m_engine;
73  SESubstanceManager* m_subMgr = nullptr;
74 
75  bool m_keepLogMsgs = false;
76  bool m_keepEventChanges = false;
77  LoggerForward* m_ForwardLogs=nullptr;
78  SEEventHandler* m_ForwardEvents=nullptr;
79 
81  std::string m_dataDir="./";
82  std::vector<const SEEventChange*> m_events;
83  std::vector<const SEActiveEvent*> m_activeEvents;
84  size_t m_length=0;
85  double* m_requestedData = nullptr;
86  std::vector<double> m_requestedValues;
87 };
Definition: Logger.h:136
Definition: Logger.h:60
virtual void ForwardFatal(std::string const &)
Definition: Logger.h:67
virtual void ForwardDebug(std::string const &)
Definition: Logger.h:63
virtual void ForwardWarning(std::string const &)
Definition: Logger.h:65
virtual void ForwardError(std::string const &)
Definition: Logger.h:66
virtual void ForwardInfo(std::string const &)
Definition: Logger.h:64
Definition: PhysiologyEngineThunk.h:17
void SetEventHandler(SEEventHandler *eh)
Definition: PhysiologyEngineThunk.h:47
std::vector< const SEEventChange * > m_events
Definition: PhysiologyEngineThunk.h:82
LogMessages m_logMsgs
Definition: PhysiologyEngineThunk.h:80
std::vector< const SEActiveEvent * > m_activeEvents
Definition: PhysiologyEngineThunk.h:83
std::unique_ptr< PhysiologyEngine > m_engine
Definition: PhysiologyEngineThunk.h:72
std::vector< double > m_requestedValues
Definition: PhysiologyEngineThunk.h:86
void SetLoggerForward(LoggerForward *lf)
Definition: PhysiologyEngineThunk.h:41
virtual void AllocateEngine()=0
Definition: SEEventManager.h:73
virtual void HandleEvent(eEvent e, bool active, const SEScalarTime *simTime=nullptr)=0
Definition: SEScalarTime.h:28
Definition: SESubstanceManager.h:9

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.