123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #pragma once
- #include "CcosLock.h"
- #include "ResDataObject.h"
- #include "ExpressionTranslation.h"
- #include "LinuxEvent.h"
- #include <memory>
- /*条件结构体:对应配置项中Event的每一个子项
- {
- Generator:GENERATORSYNCSTATE = 2
- }
- */
- struct stru_Condition
- {
- string m_Key; //二元运算符左值, 设备类型:属性名
- string m_Value; //二元运算符右值, 属性目标值
- string m_OperatorType; //关系运算类型
- atomic<bool> 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<string> m_FromList; //跳转起点
- string m_strTo; //跳转目标点
- string m_Value; //关系表达式 或 超时时间定义 或 空
- map<string, stru_Condition> m_CoditionsMap; //条件查找表, [设备类型:属性名]:stru_Condition
- protected:
- atomic<bool> m_bTriggered{ false }; //事件触发标记
- std::shared_ptr<LinuxEvent> m_hTriggered; //事件触发通知
- shared_ptr<CcosExpression> m_pExpression{ nullptr }; //表达式二叉树型结构
- public:
- ConditionEvent();
- ConditionEvent(string& name, ResDataObject* event, map<string, int>* attrCountMap = nullptr);
- ConditionEvent(const ConditionEvent& evt);
- virtual ~ConditionEvent();
- bool CreatTriggerHandle(bool isManual = true); //创建触发事件
- std::shared_ptr<LinuxEvent> GetTriggerHandle(); //返回触发通知
- bool IsTriggered(); //当前是否触发
- void ResetTrigger(); //重置触发事件
- void SetTrigger(); //手动触发事件
- string GetName(); //获取事件名
- string GetType(); //获取事类型
- vector<string> GetFrom(); //获取来源点
- string GetTo(); //获取目标点
- map<string, stru_Condition>* GetCoditionsMap(); //获取条件查找表
- void ShowExpression(vector<vector<string>>& 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(); //计算所有条件结果
- };
|