1
0

CjasonCommon.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /**
  2. * @brief
  3. jason公共头文件
  4. * @version
  5. V 1.0.0
  6. * @author
  7. 王益俊
  8. * @date
  9. 创建时间: 2018-04-19\n
  10. * @note
  11. 2018-04-19 初次创建。\n
  12. * @warning
  13. * @bug
  14. */
  15. #ifndef CJASON_COMMON_H_
  16. #define CJASON_COMMON_H_
  17. #include <string>
  18. #include <vector>
  19. #include <rapidjson/document.h>
  20. #include <rapidjson/pointer.h>
  21. namespace YA
  22. {
  23. //----------------------------------------------------------------------------
  24. // 命令
  25. //----------------------------------------------------------------------------
  26. const char JASON_CMD_LOGIN[] = "login";
  27. //----------------------------------------------------------------------------
  28. // 字段
  29. //----------------------------------------------------------------------------
  30. const char JASON_FIELD_CMD[] = "cmd";
  31. //----------------------------------------------------------------------------
  32. // 版本
  33. //----------------------------------------------------------------------------
  34. const char JASON_CURRENT_VERSION[] = "1.0.0.4";
  35. /**
  36. * @brief
  37. 通用jason包结构体
  38. */
  39. struct _JS_PACK_
  40. {
  41. public:
  42. rapidjson::Document m_Doc;//jason文档对象
  43. public:
  44. _JS_PACK_()
  45. {
  46. }
  47. /**
  48. * @brief
  49. 获得命令字函数。
  50. * @param [out] std::string& Error 错误信息\n
  51. * @return 如果成功返回获得的命令字,否则返回空字符串\n
  52. * @note
  53. * @warning
  54. * @bug
  55. */
  56. std::string GetCmd( std::string& Error )
  57. {
  58. rapidjson::Value::MemberIterator itMember;
  59. itMember = m_Doc.FindMember( JASON_FIELD_CMD );
  60. if ( itMember == m_Doc.MemberEnd() )
  61. {
  62. Error = "Error,Failed to find member: ";
  63. Error += JASON_FIELD_CMD;
  64. return "";
  65. }
  66. return m_Doc[JASON_FIELD_CMD].GetString();
  67. }
  68. /**
  69. * @brief
  70. 获得成员函数。
  71. * @param [in] const std::string& MemberName 成员名称\n
  72. * @param [out] rapidjson::Value& Member 获得的成员\n
  73. * @param [out] std::string& Error 错误信息\n
  74. * @return 如果成功返回true,否则返回false\n
  75. * @note
  76. * @warning
  77. * @bug
  78. */
  79. bool GetMember( const std::string& MemberName, rapidjson::Value& Member, std::string& Error )
  80. {
  81. rapidjson::Value::MemberIterator itMember;
  82. itMember = m_Doc.FindMember( MemberName.c_str() );
  83. if ( itMember == m_Doc.MemberEnd() )
  84. {
  85. Error = "Error,Failed to find member: ";
  86. Error += MemberName;
  87. return false;
  88. }
  89. rapidjson::Document::AllocatorType allocator;
  90. Member.CopyFrom( itMember->value, allocator );
  91. return true;
  92. }
  93. /**
  94. * @brief
  95. 获得指定成员的值函数。
  96. * @param [in] const std::string& MemberName 指定成员\n
  97. * @param [in] const std::string& ValueName 值名称\n
  98. * @param [out] rapidjson::Value& Member 获得的值\n
  99. * @param [out] std::string& Error 错误信息\n
  100. * @return 如果成功返回true,否则返回false\n
  101. * @note
  102. * @warning
  103. * @bug
  104. */
  105. bool GetValue( const rapidjson::Value& Member, const std::string& ValueName, rapidjson::Value& Value, std::string& Error )
  106. {
  107. rapidjson::Value::ConstMemberIterator itValue;
  108. itValue = Member.FindMember( ValueName.c_str() );
  109. if ( itValue == Member.MemberEnd() )
  110. {
  111. char szError[256] = { 0 };
  112. sprintf( szError, "Error,Failed to find: %s", ValueName.c_str() );
  113. Error = szError;
  114. return false;
  115. }
  116. rapidjson::Document::AllocatorType allocator;
  117. Value.CopyFrom( itValue->value, allocator );
  118. return true;
  119. }
  120. /**
  121. * @brief
  122. 根据jason pointer获得指定的值函数。
  123. * @param [in] const char* JPointer 指定的jason pointer\n
  124. * @return 返回获得的值\n
  125. * @note
  126. * @warning
  127. * @bug
  128. */
  129. const rapidjson::Value* GetValueByJP( const char* JPointer )
  130. {
  131. if ( 0 == JPointer )
  132. {
  133. return 0;
  134. }
  135. return rapidjson::GetValueByPointer( m_Doc, rapidjson::Pointer( JPointer ) );
  136. }
  137. /**
  138. * @brief
  139. 获得所有成员函数。
  140. * @param 无\n
  141. * @return 返回获得的所有成员的列表\n
  142. * @note
  143. * @warning
  144. * @bug
  145. */
  146. std::vector<std::string> GetMembers()
  147. {
  148. std::vector<std::string> vMembers;
  149. for (auto& m : m_Doc.GetObject())
  150. {
  151. vMembers.push_back( m.name.GetString() );
  152. }
  153. return vMembers;
  154. }
  155. };
  156. /**
  157. * @brief
  158. 分站结构体
  159. */
  160. struct _JS_COMMON_
  161. {
  162. std::string version;//版本
  163. _JS_COMMON_()
  164. {
  165. }
  166. };
  167. /**
  168. * @brief
  169. 分站结构体
  170. */
  171. struct _JS_STATION_
  172. {
  173. int stationid;//分站ID
  174. _JS_STATION_()
  175. {
  176. stationid = 0;
  177. }
  178. };
  179. /**
  180. * @brief
  181. 卡结构体
  182. */
  183. struct _JS_CARD_
  184. {
  185. int cardid;//卡ID
  186. int cardtype;//卡类型
  187. _JS_CARD_()
  188. {
  189. cardid = 0;
  190. cardtype = 0;
  191. }
  192. };
  193. /**
  194. * @brief
  195. 呼叫结构体
  196. */
  197. struct _JS_CALL_CARD_REQ_ : public _JS_COMMON_
  198. {
  199. int call_type_id;//呼叫类型(0 全员, 1定员)
  200. int call_time_out;//呼叫时长(单位分钟)
  201. int call_level_id;//呼叫级别(0一般呼叫,1紧急呼叫)
  202. std::string user_name;//用户
  203. long long call_time_interval;//呼叫间隔
  204. std::vector<_JS_STATION_> stations;//分站列表
  205. std::vector<_JS_CARD_> cards;//呼叫的卡列表
  206. _JS_CALL_CARD_REQ_()
  207. {
  208. call_type_id = 0;
  209. call_time_out = 0;
  210. call_level_id = 0;
  211. call_time_interval = 0;
  212. }
  213. };
  214. /**
  215. * @brief
  216. 取消呼叫结构体
  217. */
  218. struct _JS_CALL_CARD_CANCEL_REQ_ : public _JS_COMMON_
  219. {
  220. int call_type_id;//呼叫类型(0 全员, 1定员)
  221. std::string user_name;//用户
  222. long long call_time;//取消时间
  223. std::vector<_JS_STATION_> stations;//分站列表
  224. std::vector<_JS_CARD_> cards;//呼叫的卡列表
  225. _JS_CALL_CARD_CANCEL_REQ_()
  226. {
  227. call_type_id = 0;
  228. call_time = 0;
  229. }
  230. };
  231. /**
  232. * @brief
  233. 数据库连接设置结构体
  234. */
  235. struct _JS_LOGIN_
  236. {
  237. std::string user_name;//用户名
  238. std::string user_password;//密码
  239. _JS_LOGIN_()
  240. {
  241. }
  242. };
  243. }
  244. #endif//CJASON_COMMON_H_