ECSDKToolKit.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #ifndef ECSDKTOOLKIT_H
  2. #define ECSDKTOOLKIT_H
  3. #include "ECSDKTypes.h"
  4. namespace ECSDKFrameWork {
  5. /**
  6. * @brief The ExtrasManageListener class
  7. */
  8. class EC_DLL_EXPORT IECToolKitListener
  9. {
  10. public:
  11. /**
  12. * @brief ~ExtrasManageListener
  13. */
  14. virtual ~IECToolKitListener();
  15. /**
  16. * @brief onQueryTime
  17. *
  18. * @param gmtTime GMT(UTC) time in milliseconds.
  19. *
  20. * @param localTime Local time in milliseconds.
  21. *
  22. * @param timeZone Time zone, etc. "Asia/Shanghai".
  23. */
  24. virtual void onQueryTime(uint64_t gmtTime, uint64_t localTime, const string& timeZone) {};
  25. /**
  26. * @brief onQueryGPS
  27. *
  28. * @param status Whether GPS information is valid, true means valid.
  29. *
  30. * @param longitude GPS longitude.
  31. *
  32. * @param latitude GPS latitude.
  33. */
  34. virtual void onQueryGPS(bool status, const ECGPSInfo& info) {};
  35. /**
  36. * @brief Called when bulk data is received(RESERVED).
  37. *
  38. * @param data Buffer of bulk data.
  39. *
  40. * @param length Buffer length.
  41. *
  42. * @note THIS IS A RESERVED METHOD. PLEASE IGNORE IT NOW.
  43. */
  44. virtual void onBulkDataReceived(const void *data, uint32_t length) {};
  45. /**
  46. * @brief Called when forwardToPhone result.
  47. *
  48. * @param forwardInfo the forward result.
  49. *
  50. */
  51. virtual void onForwardToPhone(const ECForwardInfo& forwardInfo) {};
  52. /**
  53. * @brief Called when GenerateQRCodeUrl result.
  54. *
  55. * @param url The url string.
  56. *
  57. */
  58. virtual void onGenerateQRCodeUrl(const string& url) {};
  59. };
  60. /**
  61. * @class ECCustomProtocol
  62. *
  63. * @brief An abstract class to send and receive custom data between HU and phone.
  64. *
  65. * @note An instantiated object of this abstract class can be gained by ECSDKToolKit::getInstance()->getCustomProtocol().
  66. */
  67. class EC_DLL_EXPORT ECCustomProtocol
  68. {
  69. public:
  70. struct ECCustomData
  71. {
  72. uint32_t cmdType; ///< the cmd type of custom data
  73. uint32_t reqSeq; ///< the request sequence of current send or reply.
  74. uint32_t rspSeq; ///< the response sequence of current send or reply.
  75. void* data; ///< the data buffer.
  76. uint32_t length; ///< the length of data buffer.
  77. ECCustomData()
  78. {
  79. cmdType = 0;
  80. reqSeq = 0;
  81. rspSeq = 0;
  82. data = nullptr;
  83. length = 0;
  84. }
  85. };
  86. /**
  87. * @class ICustomDataResponse
  88. *
  89. * @brief An interface class to implement response for a send with reply.
  90. */
  91. class ICustomDataResponse
  92. {
  93. public:
  94. /**
  95. * @brief Called when a reply from phone was received.
  96. *
  97. * @param data The custom data of reply from phone.
  98. *
  99. * @note the rspSeq of data will be non-zero, which was equal to the reqSeq of one send.
  100. */
  101. virtual void onReceive(const ECCustomData& data) {};
  102. /**
  103. * @brief Called When an error occurs for current send.
  104. *
  105. * @param reqSeq The real reqSeq of current send.
  106. *
  107. * @param errNo The error num.
  108. * -1 failed to allocate memory.
  109. * -2 failed to send to phone.
  110. * -3 the version of phone app does not support the function of custom protocol.
  111. * @param error The error description.
  112. */
  113. virtual void onError(uint32_t reqSeq, int32_t errorNo, const string& error) {};
  114. /**
  115. * @brief Called When the specified timeout time is reached.
  116. *
  117. * @param reqSeq The real reqSeq of current send.
  118. */
  119. virtual void onTimeout(uint32_t reqSeq) {};
  120. };
  121. /**
  122. * @class ICustomDataReceiver
  123. *
  124. * @brief An interface class to implement receive of custom data from phone.
  125. */
  126. class ICustomDataReceiver
  127. {
  128. public:
  129. /**
  130. * @brief Called When custom data from phone was received.
  131. *
  132. * @param data The custom data of phone.
  133. *
  134. * @note the rspSeq of data will be zero.
  135. */
  136. virtual void onReceive(const ECCustomData& data) {};
  137. };
  138. /**
  139. * @brief set a receiver to handle receive of custom data from phone.
  140. *
  141. * @param receiver The ICustomDataReceiver object.
  142. */
  143. virtual int32_t registerCustomDataReceiver(ICustomDataReceiver* receiver) = 0;
  144. /**
  145. * @brief send custom data to phone.
  146. *
  147. * @param data The custom data.
  148. *
  149. * @param timeout Timeout for corresponding reply to current send in seconds. An value of -1 indicates no timeout.
  150. *
  151. * @param responseCallback The ICustomDataResponse object.
  152. *
  153. * @note If the send has reply, then responseCallback cann't be null.
  154. *
  155. * If the send has no reply, then responseCallback should be null. ECCustomProtocol::sendCustomData(data) can be used.
  156. *
  157. * User has no need to set reqSeq and rspSeq of data. After the method is invoked, the reqSeq and rspSeq of data is set to the actual value used.
  158. */
  159. virtual int32_t sendCustomData(ECCustomData& data, int32_t timeout = -1, ICustomDataResponse* responseCallback = nullptr) = 0;
  160. /**
  161. * @brief reply custom data to phone.
  162. *
  163. * @param data The custom data.
  164. *
  165. * @param reqSeq The reqSeq of the custom data received. It will be as rspSeq of current send to phone.
  166. *
  167. * @note User has no need to set reqSeq and rspSeq of data. After the method is invoked, the reqSeq and rspSeq of data is set to the actual value used.
  168. */
  169. virtual int32_t replyCustomData(ECCustomData& data, uint32_t reqSeq) = 0;
  170. };
  171. /*
  172. * @brief The ECSDKExtrasManage class
  173. */
  174. class EC_DLL_EXPORT ECSDKToolKit
  175. {
  176. public:
  177. /**
  178. * @brief getInstance
  179. * @return
  180. */
  181. static ECSDKToolKit *getInstance();
  182. /**
  183. * @brief initialize
  184. * @param pListener
  185. * @return
  186. */
  187. virtual bool initialize(IECToolKitListener* listener = nullptr) = 0;
  188. /**
  189. * @brief release
  190. * @return
  191. */
  192. virtual void release() = 0;
  193. /**
  194. * @brief Open ftp server which forwards the local ports on HUD to the ports on the connected phone.
  195. *
  196. * @param userName Specifying the username of ftp.
  197. *
  198. * @param pwd Specifying the password of ftp.
  199. *
  200. * @return ECSDK_OK on success, others on fail.
  201. *
  202. * @note This interface shall be called only after
  203. * IECSDKListener::onSdkConnectStatus::EC_CONNECT_PHONE_SUCCEED
  204. *
  205. */
  206. virtual int32_t openFtpServer(const string& userName, const string& pwd) = 0;
  207. /**
  208. * @brief Send an request to phone for time information.
  209. *
  210. * @return ECSDK_OK on success, others on fail.
  211. */
  212. virtual int32_t queryTime() = 0;
  213. /**
  214. * @brief Send an request to phone for GPS information.
  215. *
  216. * @return ECSDK_OK on success, others on fail.
  217. *
  218. * @note The query result to see ExtrasManageListener::onQueryGPS.
  219. */
  220. virtual int32_t queryGPS() = 0;
  221. /**
  222. * @brief Send bulk data to phone(RESERVED).
  223. *
  224. * @param data Buffer of bulk data.
  225. *
  226. * @param length Buffer length.
  227. *
  228. * @return ECSDK_OK on success, others on fail.
  229. *
  230. * @note THIS IS A RESERVED METHOD. PLEASE IGNORE IT NOW.
  231. */
  232. virtual int32_t sendBulkDataToPhone(const void *data, uint32_t length) = 0;
  233. /**
  234. * @brief This method can set up forwarding of HU's port to connected phone's port when connection is via usb.
  235. *
  236. * @param in Which tell the local port and remote port which will be mapped.
  237. *
  238. * @return ECSDK_OK on success, others on fail.
  239. *
  240. * @note If the connection is via wifi, ip in forwardInfo is the connected phone's ip,
  241. * the localPort in forwardInfo is equal to the phonePort.
  242. *
  243. * If the connection is via usb, ip in forwardInfo will be 127.0.0.1,
  244. * the localPort is the real port of HU forwarded to connected phone.
  245. *
  246. * IECToolKitListener::onForwardToPhone will tell the result of forwardTophone.
  247. */
  248. virtual int32_t forwardToPhone(const ECForwardInfo& in) = 0;
  249. virtual ECCustomProtocol* getCustomProtocol() = 0;
  250. /**
  251. * @brief This method will get a url string for qr code.
  252. *
  253. * @param info The ssid and pwd of info will be encoded to url.
  254. *
  255. * @return ECSDK_OK on success, others on fail.
  256. */
  257. virtual int32_t generateQRCodeUrl(const ECQRInfo& info) = 0;
  258. protected:
  259. ECSDKToolKit();
  260. virtual ~ECSDKToolKit();
  261. };
  262. }
  263. #endif // ECSDKTOOLKIT_H