iMSTK
Interactive Medical Simulation Toolkit
imstkModuleDriver.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkEventObject.h"
10 
11 namespace imstk
12 {
13 using ModuleDriverStatus = int;
14 #define ModuleDriverRunning 0
15 #define ModuleDriverPaused 1
16 #define ModuleDriverStopped 2
17 
18 class Module;
19 
25 class ModuleDriver : public EventObject, public std::enable_shared_from_this<ModuleDriver>
26 {
27 protected:
28  ModuleDriver() = default;
29 public:
30  ~ModuleDriver() override = default;
31 
32 public:
33  virtual void start() = 0;
34 
38  virtual void addModule(std::shared_ptr<Module> module)
39  {
40  m_modules.push_back(module);
41  }
42 
46  virtual void clearModules() { m_modules.clear(); }
47 
48  void requestStatus(ModuleDriverStatus status) { simState = status; }
49  ModuleDriverStatus getStatus() const { return simState; }
50 
51  std::vector<std::shared_ptr<Module>>& getModules() { return m_modules; }
52 
56  void waitForInit();
57 
58 protected:
59  std::vector<std::shared_ptr<Module>> m_modules;
60 
61  std::atomic<ModuleDriverStatus> simState = { ModuleDriverRunning };
62 };
63 }; // namespace imstk
virtual void addModule(std::shared_ptr< Module > module)
Add a module to run.
Compound Geometry.
virtual void clearModules()
Remove all modules.
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
void waitForInit()
Wait for all modules to init.
Defines the control of modules.