StateMachineDevicePool.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "ResDataObject.h"
  3. #include "CcosThread.h"
  4. #include "CcosLock.h"
  5. #include "MsgQueue.h"
  6. #include "LogicClient.h"
  7. //状态机调用返回状态
  8. enum CCOSSTMRET
  9. {
  10. CCOSSMRET_NULL,
  11. CCOSSMRET_SUCCESS,
  12. CCOSSMRET_TIMEOUT,
  13. CCOSSMRET_FAILED,
  14. CCOSSMRET_EXIT,
  15. CCOSSMRET_MAX
  16. };
  17. using JudgeNotifyCallback = std::function<void(string&, string&)>;
  18. //设备交互订阅池
  19. class StateMachineDevicePool : public Ccos_Thread, public CcosLock
  20. {
  21. public:
  22. StateMachineDevicePool();
  23. ~StateMachineDevicePool();
  24. void SetTopExitHandle(std::shared_ptr<LinuxEvent> hand); //设置退出事件
  25. bool SetDeviceAttributes(ResDataObject& devices, ResDataObject& attributes, string workStation = ""); //往设备池子中添加设备,并订阅的设备属性
  26. void GetAttributesInitValue(map<string, string>& initValueMap); //主动获取订阅属性的初始值
  27. bool BeginNotifyLoop(const JudgeNotifyCallback& funCallback); //开始消息循环处理
  28. bool EndNotifyLoop(); //结束消息循环处理
  29. CCOSSTMRET StateMachineAction(ResDataObject& resActions, ResDataObject& resResult, DWORD Timeout); //执行设备组的Action
  30. protected:
  31. bool Exec() override; //循环处理接口
  32. bool OnStartThread() override; //Exec之前
  33. bool OnEndThread() override; //Exec返回false之后
  34. bool OpenDevices(); //打开所有设备
  35. bool CloseDevices(); //关闭所有设备
  36. CCOSSTMRET ReadForDeviceEvents(); //轮询设备组的Notify
  37. void SplitCcosDevicePath(ResDataObject resTopic, vector<string>& resTopicParams);
  38. private:
  39. string m_strWS; //当前工作位
  40. string m_strCurTransaction; //消息追踪号
  41. JudgeNotifyCallback m_JudgeNotifyFun{ NULL }; //通知回调到上层
  42. std::shared_ptr<LinuxEvent> m_hTopExitHandle; //上层线程退出时事件
  43. atomic<bool> m_bNotifyLoop{ false }; //通知循环标记
  44. unique_ptr<LogicClient> m_pClientNotify{ nullptr }; //用于接收所有设备特定消息更新
  45. unique_ptr<LogicClient> m_pClientAction{ nullptr }; //用于调用设备动作
  46. map<string, string> m_DevPathMap; //设备加载表, 设备类型:设备路径,例:"Generator":"CCOS/DEVICE/Generator/+/+/+"
  47. list<string> m_TopicList; //属性订阅表, 设备路径+Notify+属性名,例:"CCOS/DEVICE/Generator/+/+/+/Notify/GENERATORSYNCSTATE"
  48. };