CcosFileHandle.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // CcosFileHandle.h
  2. #pragma once
  3. #define CCOSFILEHANDLE_API
  4. #define CCOSFILEHANDLE_C_API extern "C"
  5. #include <string>
  6. #include <cstdint> // 添加标准整数类型头文件
  7. #include "Definitions.h"
  8. #include "ResDataObject.h"
  9. using namespace std;
  10. // 命令响应枚举
  11. typedef enum _Cmd_Echo {
  12. CMD_ECHO_IGNORE = -1,
  13. CMD_ECHO_NOTARGET,
  14. CMD_ECHO_NG,
  15. CMD_ECHO_OK,
  16. CMD_ECHO_MAX
  17. }CMD_ECHO;
  18. // 数据包命令枚举
  19. #ifndef _Packet_Cmd
  20. typedef enum _Packet_Cmd {
  21. PACKET_CMD_NONE = -1,
  22. PACKET_CMD_OPEN,
  23. PACKET_CMD_CLOSE,
  24. PACKET_CMD_GET,
  25. PACKET_CMD_UPDATE,//更新对象
  26. PACKET_CMD_ADD,
  27. PACKET_CMD_DEL,
  28. PACKET_CMD_EXE,
  29. PACKET_CMD_DATA,
  30. PACKET_CMD_MSG,
  31. PACKET_CMD_ONLINE,//设备掉线后重新注册到Root
  32. PACKET_CMD_PART_UPDATE,//只更新对象的子节点
  33. PACKET_CMD_SET,
  34. PACKET_CMD_MAX
  35. }PACKET_CMD;
  36. #endif
  37. // 数据包命令字符串表示
  38. const string _Packet_Cmd_String[] = {
  39. "Open",
  40. "Close",
  41. "Get",
  42. "Update",
  43. "Add",
  44. "Del",
  45. "Action",
  46. "Data",
  47. "Message",
  48. "Online",
  49. "PartUpdate",
  50. "Set"
  51. };
  52. // 数据包类型枚举
  53. typedef enum _Packet_Type {
  54. PACKET_TYPE_NONE = -1,
  55. PACKET_TYPE_REQ,
  56. PACKET_TYPE_RES,
  57. PACKET_TYPE_NOTIFY,
  58. PACKET_TYPE_MAX
  59. }PACKET_TYPE;
  60. // 文件标志位枚举
  61. typedef enum _Ccos_File_Flags {
  62. IMAGE_FH = 1,
  63. ACTION = 2,
  64. NOTIFY_MSG = 4,
  65. NOTIFY_UPDATE = 8,
  66. NOTIFY_DATA = 16,
  67. NOTIFY_ACTION = 32,
  68. ALL_ACCESS = 64 - 1,
  69. ABSCRACT_ONLINE = 128
  70. }CCOS_FILE_FLAGS;
  71. // 操作同步模式枚举
  72. typedef enum _Action_Sync_Mode {
  73. ACTION_SYNC,
  74. ACTION_ASYNC,
  75. }ACTION_SYNC_MODE;
  76. // 数据包相关宏定义
  77. #define CCOS_PACK_IDX ("IDX")
  78. #define CCOS_PACK_TYPE ("TYPE")
  79. #define CCOS_PACK_TYPE_REQ ("REQUEST")
  80. #define CCOS_PACK_TYPE_RES ("RESPONSE")
  81. #define CCOS_PACK_TYPE_NOTIFY ("NOTIFY")
  82. #define CCOS_PACK_CMD ("CMD")
  83. #define CCOS_PACKET_SYNC ("SYNC")
  84. #define CCOS_PACK_HANDLE ("HANDLE")
  85. #define CCOS_PACK_HANDLE_ROUTE ("ROUTE")
  86. #define CCOS_PACK_HANDLE_FLAGS ("FLAGS")
  87. #define CCOS_PACK_HANDLE_LANG ("LANG")
  88. #define CCOS_PACKET_HANDLE_KEY ("HANDLEID")
  89. #define CCOS_PACK_HANDLE_OWNERID ("OWNERID")
  90. #define CCOS_PACK_HANDLE_DEVID ("DEVID")
  91. #define CCOS_PACK_TARGET_BUSID ("EBUSID")
  92. #define CCOS_PACK_TARGET_MACHINEID ("MACHINEID")
  93. #define CCOS_PACK_TARGET_PROCID ("PROCID")
  94. #define CCOS_PACK_TARGET_ADDR ("ADDR")
  95. #define CCOS_PACK_KEY ("KEY")
  96. #define CCOS_PACK_ACTION ("Action")
  97. #define CCOS_PACK_CONTEXT ("CONTEXT")
  98. #define CCOS_PACK_RETURN ("RET")
  99. #define CCOS_PACK_CODE ("CODE")
  100. #define CCOS_PACK_MSG ("MSG")
  101. #define CCOS_PACKET_VER ("Ver")
  102. #define CCOS_PACKET_VER_NOW ("3")
  103. #define CCOS_TOPIC ("TOPIC")
  104. #define CCOS_PUBLISH ("PUBLISH")
  105. #define CCOS_RESP_TOPIC ("RespTopic")
  106. #define CCOS_TRANSACTION ("Transaction")
  107. #define CCOS_CLIENT_ROOT_TOPIC ("CCOS/CLIENT/PLATFORM")
  108. #define CCOS_CLIENT_ID_PREFIX ("CCOS_CLIENT_")
  109. // 数据包路由方向枚举
  110. // any: 先发往本地,如果本地无目的地,再次发往Eth
  111. // Local: 仅本地
  112. // Eth: 仅远程机器
  113. typedef enum _Ccos_Packet_Route {
  114. CCOS_PACKET_ROUTE_NOTARGET = -1,//无法发送
  115. CCOS_PACKET_ROUTE_ANY,//任何可能的方向
  116. CCOS_PACKET_ROUTE_LOCAL,//仅本地机器
  117. CCOS_PACKET_ROUTE_ETH,//仅远程机器
  118. CCOS_PACKET_ROUTE_MAX
  119. }CCOS_PACKET_ROUTE;
  120. // 目标地址类
  121. class CCOSFILEHANDLE_API CcosTargetAddress {
  122. string* m_pKey;
  123. string* m_ValString;
  124. ResDataObject* m_pTargetObject;
  125. public:
  126. CcosTargetAddress(void);
  127. CcosTargetAddress(const CcosTargetAddress& tValue);
  128. virtual ~CcosTargetAddress(void);
  129. virtual const char* GetVal();
  130. bool operator ==(const CcosTargetAddress& target);
  131. CcosTargetAddress& operator = (const CcosTargetAddress& tValue);
  132. void GetResDataObject(ResDataObject& obj);
  133. bool SetResDataObject(ResDataObject& obj);
  134. virtual bool SetVal(const char* pValString);
  135. void SetKey(const char* pKey);
  136. const char* GetKey();
  137. ResDataObject& operator [](const char* pKey);
  138. void PrintOut();//测试用
  139. };
  140. // 设备文件句柄类
  141. class CCOSFILEHANDLE_API CcosDevFileHandle {
  142. string* m_pKey;
  143. string* m_ValString;
  144. ResDataObject* m_pRoute;//0:any,1:local,2:eth
  145. ResDataObject* m_pFlags;
  146. ResDataObject* m_pLang;
  147. ResDataObject* m_pHandleId;
  148. CcosTargetAddress* m_pOwner;
  149. CcosTargetAddress* m_pDev;
  150. public:
  151. CcosDevFileHandle(void);
  152. CcosDevFileHandle(const CcosDevFileHandle& tValue);
  153. virtual ~CcosDevFileHandle(void);
  154. void SetKey(const char* pKey);
  155. const char* GetKey();
  156. void GetResDataObject(ResDataObject& obj);
  157. bool SetResDataObject(ResDataObject& obj);
  158. virtual const char* GetVal();
  159. virtual bool SetVal(const char* pValString);
  160. CcosTargetAddress& GetTarget(bool Owner = true);
  161. CcosDevFileHandle& operator = (const CcosDevFileHandle& tValue);
  162. ResDataObject& operator [](const char* pKey);
  163. bool operator ==(const CcosDevFileHandle& target);
  164. void PrintOut();//测试用
  165. };