#pragma once #include "CcosLock.h" #include "ResDataObject.h" #include "ExpressionTranslation.h" #include "LinuxEvent.h" #include /*条件结构体:对应配置项中Event的每一个子项 { Generator:GENERATORSYNCSTATE = 2 } */ struct stru_Condition { string m_Key; //二元运算符左值, 设备类型:属性名 string m_Value; //二元运算符右值, 属性目标值 string m_OperatorType; //关系运算类型 atomic m_Result{ false }; //该条件判断结果 stru_Condition(){}; stru_Condition(string key, string value, string operatorType); stru_Condition(const stru_Condition& cd); stru_Condition& operator=(const stru_Condition& cd); bool CheckCondition(string& strValue); //检查条件 }; /*事件定义; 对应配置项中的Events { "Events": { "EvtExpPrep": { "Type": "External", "From": "FrameReady", "To": "FramePrepStart", "Value": "" }, "EvtExpOn": { "Type": "Conditions", "From": "FrameReady", "To": "FrameStart", "Value": "(Generator:GENERATORSYNCSTATE=2 | SynBox:GENERATORSYNCSTATE!=1) & Detector:DetectorStatus<>4,5 & Machine:MachineryReady[!]2,4" }, "EvtOffsetOn": { "Type": "Timeout", "From": "FrameReady", "To": "FrameOffset", "Value": "60000" } } } */ class ConditionEvent { private: string m_strName; //事件名称 string m_strType; //事件类型 vector m_FromList; //跳转起点 string m_strTo; //跳转目标点 string m_Value; //关系表达式 或 超时时间定义 或 空 map m_CoditionsMap; //条件查找表, [设备类型:属性名]:stru_Condition protected: atomic m_bTriggered{ false }; //事件触发标记 std::shared_ptr m_hTriggered; //事件触发通知 shared_ptr m_pExpression{ nullptr }; //表达式二叉树型结构 public: ConditionEvent(); ConditionEvent(string& name, ResDataObject* event, map* attrCountMap = nullptr); ConditionEvent(const ConditionEvent& evt); virtual ~ConditionEvent(); bool CreatTriggerHandle(bool isManual = true); //创建触发事件 std::shared_ptr GetTriggerHandle(); //返回触发通知 bool IsTriggered(); //当前是否触发 void ResetTrigger(); //重置触发事件 void SetTrigger(); //手动触发事件 string GetName(); //获取事件名 string GetType(); //获取事类型 vector GetFrom(); //获取来源点 string GetTo(); //获取目标点 map* GetCoditionsMap(); //获取条件查找表 void ShowExpression(vector>& strPrint); //打印树形表达式 bool CheckConditions(string& strKey, string& strValue, string& strFrom, string& strTo); //检查条件 bool CheckTimeout(string& strValue, string& strFrom, string& strTo); //检查超时 bool CheckExternal(string& strFrom, string& strTo); //检查直接触发 bool CaculateCondition(); //计算所有条件结果 };