ifw-fcf  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
deviceFacade.hpp
Go to the documentation of this file.
1 
9 #ifndef FCF_DEVMGR_COMMON_DEVICE_FACADE_HPP_
10 #define FCF_DEVMGR_COMMON_DEVICE_FACADE_HPP_
11 
12 // System headers
13 #include <list>
14 
15 // Local headers
16 #include <rad/smAdapter.hpp>
17 #include <rad/topicPub.hpp>
18 #include <rad/anyEvent.hpp>
19 #include <rad/activity.hpp>
20 
21 #include <fcf/common/dispatcher.hpp>
23 #include <fcf/devmgr/common/events.rad.hpp>
24 
25 namespace fcf {
26  namespace devmgr {
27  namespace common {
28 
29  class Config;
30  class IDevice;
31 
39  class DeviceFacade {
40  public:
49  DeviceFacade(rad::SMAdapter& sm,
50  IConfig& config,
51  fcf::common::Dispatcher<>& failure,
52  fcf::common::Dispatcher<>& normal);
53 
57  virtual ~DeviceFacade();
58 
63  virtual bool Init(rad::SMAdapter& sm, rad::ThreadActivity* activity);
64 
72  virtual bool Enable(rad::SMAdapter& sm, rad::ThreadActivity* activity);
73 
81  virtual bool Recover(rad::SMAdapter& sm, rad::ThreadActivity* activity);
86  virtual bool Disable();
87 
109  virtual bool Setup(const std::any& payload, rad::ThreadActivity* activity);
114  virtual void Stop();
115 
120  virtual void Reset();
121 
128  virtual void Status(const std::any& payload, std::string& buffer);
129 
130 
135  virtual void Simulate(rad::AnyEvent const& last_event);
136 
141  virtual void StopSim(rad::AnyEvent const& last_event);
142 
147  virtual void Ignore(rad::AnyEvent const& last_event);
148 
153  virtual void StopIgn(rad::AnyEvent const& last_event);
154 
159  virtual void HwReset(rad::AnyEvent const& last_event);
160 
165  virtual void HwInit(rad::AnyEvent const& last_event);
166 
171  virtual void HwEnable(rad::AnyEvent const& last_event);
172 
177  virtual void HwDisable(rad::AnyEvent const& last_event);
178 
183  virtual std::string DevNames();
184 
195  virtual void BeginAcq(rad::AnyEvent const& last_event);
196 
212  virtual void EndAcq(rad::AnyEvent const& last_event);
213 
214 
222  void TriggerInternalEvent(rad::SMAdapter& sm, rad::UniqueEvent&& e);
223 
230  void AddDevice(std::shared_ptr<IDevice> device);
231 
235  void ClearDevices();
236 
241  fcf::common::Dispatcher<>& GetFailureCB();
242 
247  fcf::common::Dispatcher<>& GetNormalCB();
248 
253  const int GetNumDevices();
254 
255  private:
256 
257  DeviceFacade(const DeviceFacade&) = delete;
258  DeviceFacade& operator= (const DeviceFacade&) = delete;
259 
268  void InitSync(rad::ThreadActivity* activity,
269  std::chrono::system_clock::time_point start_time,
270  bool& stopped,
271  bool& timeout);
272 
281  void EnableSync(rad::ThreadActivity* activity,
282  std::chrono::system_clock::time_point start_time,
283  bool& stopped,
284  bool& timeout);
285 
291  void DeviceFailureCB();
292 
299  void DeviceNormalCB();
300 
301  void CheckDeviceName(const std::vector<std::string>& devices) const;
302 
303  std::vector<std::shared_ptr<IDevice> > m_devices;
304  std::vector<std::string> m_device_names;
305  boost::asio::io_service m_ios;
306  rad::SMAdapter& m_sm;
307  IConfig& m_config;
308  std::string m_dp_filename;
309 
313  fcf::common::Dispatcher<> m_failure;
314 
318  fcf::common::Dispatcher<> m_normal;
319  };
320  }
321  }
322 } // namespace devmgr::Common
323 
324 #endif // FCF_DEVMGR_COMMON_DEVICE_FACADE_HPP_
Device class header file.
virtual ~DeviceFacade()
~DeviceFacade
Definition: deviceFacade.cpp:62
virtual void HwDisable(rad::AnyEvent const &last_event)
Disable hardware.
Definition: deviceFacade.cpp:599
virtual void Reset()
Reset devices.
Definition: deviceFacade.cpp:470
virtual void Simulate(rad::AnyEvent const &last_event)
Simulate devices managed by the server.
Definition: deviceFacade.cpp:497
virtual void Stop()
Abort all devices managed by the devmgr.
Definition: deviceFacade.cpp:460
void ClearDevices()
Empty internal device map.
Definition: deviceFacade.cpp:684
virtual bool Recover(rad::SMAdapter &sm, rad::ThreadActivity *activity)
Recover all devices managed by the devmgr.
Definition: deviceFacade.cpp:242
Definition: deviceFacade.hpp:39
void AddDevice(std::shared_ptr< IDevice > device)
Add a device instance to be managed by the facade.
Definition: deviceFacade.cpp:678
virtual bool Enable(rad::SMAdapter &sm, rad::ThreadActivity *activity)
Enable all devices managed by the devmgr.
Definition: deviceFacade.cpp:113
virtual void StopIgn(rad::AnyEvent const &last_event)
Stop ignoring devices managed by the server.
Definition: deviceFacade.cpp:542
virtual bool Disable()
Disable all devices managed by the devmgr.
Definition: deviceFacade.cpp:346
virtual void HwInit(rad::AnyEvent const &last_event)
Init hardware.
Definition: deviceFacade.cpp:571
const int GetNumDevices()
Get the number of devices.
Definition: deviceFacade.cpp:729
virtual void StopSim(rad::AnyEvent const &last_event)
Stop simulating devices managed by the server.
Definition: deviceFacade.cpp:512
void TriggerInternalEvent(rad::SMAdapter &sm, rad::UniqueEvent &&e)
Trigger an internal event.
Definition: deviceFacade.cpp:672
virtual void Ignore(rad::AnyEvent const &last_event)
Ignore devices managed by the server.
Definition: deviceFacade.cpp:527
virtual void BeginAcq(rad::AnyEvent const &last_event)
Begin Acquisition.
Definition: deviceFacade.cpp:613
fcf::common::Dispatcher & GetFailureCB()
Get reference to failure CB.
Definition: deviceFacade.cpp:691
virtual bool Init(rad::SMAdapter &sm, rad::ThreadActivity *activity)
Init all devices managed by the devmgr.
Definition: deviceFacade.cpp:66
Definition: iConfig.hpp:22
fcf::common::Dispatcher & GetNormalCB()
Get reference to normal CB.
Definition: deviceFacade.cpp:696
virtual void EndAcq(rad::AnyEvent const &last_event)
End Acquisition.
Definition: deviceFacade.cpp:650
virtual bool Setup(const std::any &payload, rad::ThreadActivity *activity)
Executes a setup message.
Definition: deviceFacade.cpp:374
virtual void Status(const std::any &payload, std::string &buffer)
Get status from devices.
Definition: deviceFacade.cpp:482
virtual void HwEnable(rad::AnyEvent const &last_event)
Enable hardware.
Definition: deviceFacade.cpp:585
virtual void HwReset(rad::AnyEvent const &last_event)
Reset hardware.
Definition: deviceFacade.cpp:557
virtual std::string DevNames()
Get list of managed devices.
Definition: deviceFacade.cpp:924
DeviceFacade(rad::SMAdapter &sm, IConfig &config, fcf::common::Dispatcher<> &failure, fcf::common::Dispatcher<> &normal)
Definition: deviceFacade.cpp:43