ConditionEvent.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "CcosLock.h"
  3. #include "ResDataObject.h"
  4. #include "ExpressionTranslation.h"
  5. #include "LinuxEvent.h"
  6. #include <memory>
  7. /*条件结构体:对应配置项中Event的每一个子项
  8. {
  9. Generator:GENERATORSYNCSTATE = 2
  10. }
  11. */
  12. struct stru_Condition
  13. {
  14. string m_Key; //二元运算符左值, 设备类型:属性名
  15. string m_Value; //二元运算符右值, 属性目标值
  16. string m_OperatorType; //关系运算类型
  17. atomic<bool> m_Result{ false }; //该条件判断结果
  18. stru_Condition(){};
  19. stru_Condition(string key, string value, string operatorType);
  20. stru_Condition(const stru_Condition& cd);
  21. stru_Condition& operator=(const stru_Condition& cd);
  22. bool CheckCondition(string& strValue); //检查条件
  23. };
  24. /*事件定义; 对应配置项中的Events
  25. {
  26. "Events": {
  27. "EvtExpPrep": {
  28. "Type": "External",
  29. "From": "FrameReady",
  30. "To": "FramePrepStart",
  31. "Value": ""
  32. },
  33. "EvtExpOn": {
  34. "Type": "Conditions",
  35. "From": "FrameReady",
  36. "To": "FrameStart",
  37. "Value": "(Generator:GENERATORSYNCSTATE=2 | SynBox:GENERATORSYNCSTATE!=1) & Detector:DetectorStatus<>4,5 & Machine:MachineryReady[!]2,4"
  38. },
  39. "EvtOffsetOn": {
  40. "Type": "Timeout",
  41. "From": "FrameReady",
  42. "To": "FrameOffset",
  43. "Value": "60000"
  44. }
  45. }
  46. }
  47. */
  48. class ConditionEvent
  49. {
  50. private:
  51. string m_strName; //事件名称
  52. string m_strType; //事件类型
  53. vector<string> m_FromList; //跳转起点
  54. string m_strTo; //跳转目标点
  55. string m_Value; //关系表达式 或 超时时间定义 或 空
  56. map<string, stru_Condition> m_CoditionsMap; //条件查找表, [设备类型:属性名]:stru_Condition
  57. protected:
  58. atomic<bool> m_bTriggered{ false }; //事件触发标记
  59. std::shared_ptr<LinuxEvent> m_hTriggered; //事件触发通知
  60. shared_ptr<CcosExpression> m_pExpression{ nullptr }; //表达式二叉树型结构
  61. public:
  62. ConditionEvent();
  63. ConditionEvent(string& name, ResDataObject* event, map<string, int>* attrCountMap = nullptr);
  64. ConditionEvent(const ConditionEvent& evt);
  65. virtual ~ConditionEvent();
  66. bool CreatTriggerHandle(bool isManual = true); //创建触发事件
  67. std::shared_ptr<LinuxEvent> GetTriggerHandle(); //返回触发通知
  68. bool IsTriggered(); //当前是否触发
  69. void ResetTrigger(); //重置触发事件
  70. void SetTrigger(); //手动触发事件
  71. string GetName(); //获取事件名
  72. string GetType(); //获取事类型
  73. vector<string> GetFrom(); //获取来源点
  74. string GetTo(); //获取目标点
  75. map<string, stru_Condition>* GetCoditionsMap(); //获取条件查找表
  76. void ShowExpression(vector<vector<string>>& strPrint); //打印树形表达式
  77. bool CheckConditions(string& strKey, string& strValue, string& strFrom, string& strTo); //检查条件
  78. bool CheckTimeout(string& strValue, string& strFrom, string& strTo); //检查超时
  79. bool CheckExternal(string& strFrom, string& strTo); //检查直接触发
  80. bool CaculateCondition(); //计算所有条件结果
  81. };