123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #pragma once
- #include "ResDataObject.h"
- #include "CcosThread.h"
- #include "CcosLock.h"
- #include "MsgQueue.h"
- #include "LogicClient.h"
- //状态机调用返回状态
- enum CCOSSTMRET
- {
- CCOSSMRET_NULL,
- CCOSSMRET_SUCCESS,
- CCOSSMRET_TIMEOUT,
- CCOSSMRET_FAILED,
- CCOSSMRET_EXIT,
- CCOSSMRET_MAX
- };
- using JudgeNotifyCallback = std::function<void(string&, string&)>;
- //设备交互订阅池
- class StateMachineDevicePool : public Ccos_Thread, public CcosLock
- {
- public:
- StateMachineDevicePool();
- ~StateMachineDevicePool();
- void SetTopExitHandle(std::shared_ptr<LinuxEvent> hand); //设置退出事件
- bool SetDeviceAttributes(ResDataObject& devices, ResDataObject& attributes, string workStation = ""); //往设备池子中添加设备,并订阅的设备属性
- void GetAttributesInitValue(map<string, string>& initValueMap); //主动获取订阅属性的初始值
- bool BeginNotifyLoop(const JudgeNotifyCallback& funCallback); //开始消息循环处理
- bool EndNotifyLoop(); //结束消息循环处理
- CCOSSTMRET StateMachineAction(ResDataObject& resActions, ResDataObject& resResult, DWORD Timeout); //执行设备组的Action
- protected:
- bool Exec() override; //循环处理接口
- bool OnStartThread() override; //Exec之前
- bool OnEndThread() override; //Exec返回false之后
- bool OpenDevices(); //打开所有设备
- bool CloseDevices(); //关闭所有设备
- CCOSSTMRET ReadForDeviceEvents(); //轮询设备组的Notify
- void SplitCcosDevicePath(ResDataObject resTopic, vector<string>& resTopicParams);
- private:
- string m_strWS; //当前工作位
- string m_strCurTransaction; //消息追踪号
- JudgeNotifyCallback m_JudgeNotifyFun{ NULL }; //通知回调到上层
- std::shared_ptr<LinuxEvent> m_hTopExitHandle; //上层线程退出时事件
- atomic<bool> m_bNotifyLoop{ false }; //通知循环标记
-
- unique_ptr<LogicClient> m_pClientNotify{ nullptr }; //用于接收所有设备特定消息更新
- unique_ptr<LogicClient> m_pClientAction{ nullptr }; //用于调用设备动作
- map<string, string> m_DevPathMap; //设备加载表, 设备类型:设备路径,例:"Generator":"CCOS/DEVICE/Generator/+/+/+"
- list<string> m_TopicList; //属性订阅表, 设备路径+Notify+属性名,例:"CCOS/DEVICE/Generator/+/+/+/Notify/GENERATORSYNCSTATE"
- };
|