ECSDKFramework.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*! \file ECSDKFramework.h */
  2. #pragma once
  3. #include "ECSDKTypes.h"
  4. namespace ECSDKFrameWork {
  5. /**
  6. * @brief The IECSDKListener class
  7. *
  8. * @note This interface provides information about the connection process,
  9. * the connection type, and so on
  10. */
  11. class EC_DLL_EXPORT IECSDKListener
  12. {
  13. public:
  14. /*!
  15. * \brief Virtual destructor.
  16. */
  17. virtual ~IECSDKListener();
  18. /**
  19. * @brief onSdkConnectStatus
  20. * @param status
  21. */
  22. virtual void onSdkConnectStatus(ECSDKConnectedStatus status, ECSDKConnectedType type) = 0;
  23. /**
  24. * @brief onLicenseAuthFail
  25. * @param errCode
  26. * @param errMsg
  27. */
  28. virtual void onLicenseAuthFail(int32_t errCode, const string& errMsg) = 0;
  29. /**
  30. * @brief onLicenseAuthSuccess
  31. * @param code
  32. * @param msg
  33. */
  34. virtual void onLicenseAuthSuccess(int32_t code, const string& msg) = 0;
  35. };
  36. /**
  37. * @class IECAccessDevice
  38. *
  39. * @brief An interface class to implement special usb device access.
  40. */
  41. class EC_DLL_EXPORT IECAccessDevice
  42. {
  43. public:
  44. virtual ~IECAccessDevice();
  45. /**
  46. * @brief Open usb device.
  47. *
  48. * @return Zero on success, others on fail.
  49. */
  50. virtual int32_t open() = 0;
  51. /**
  52. * @brief Read data from usb devices.
  53. *
  54. * @param data Read buffer.
  55. *
  56. * @param length Read size.
  57. *
  58. * @return The size of data read in bytes, zero if currently no read data available, or negative number on fail.
  59. */
  60. virtual int32_t read(void *data, uint32_t length) = 0;
  61. /**
  62. * @brief Write data into usb devices.
  63. *
  64. * @param data Write buffer.
  65. *
  66. * @param length Write size.
  67. *
  68. * @return The size of data written in bytes, negative number on fail.
  69. */
  70. virtual int32_t write(void *data, uint32_t length) = 0;
  71. /**
  72. * @brief Close usb device. Opposite to open.
  73. *
  74. * @see open
  75. */
  76. virtual void close() = 0;
  77. };
  78. /**
  79. * @class ECSDKConfig
  80. *
  81. * @brief Configure the functional interfaces of the ECSDKFramework.
  82. */
  83. class ECSDKConfigPrivate;
  84. class EC_DLL_EXPORT ECSDKConfig
  85. {
  86. public:
  87. explicit ECSDKConfig(const string& uuid, const string& version, const string& writableDir);
  88. explicit ECSDKConfig();
  89. ~ECSDKConfig();
  90. void setUUID(const string& uuid);
  91. void setVersion(const string& version);
  92. void setWorkSpace(const string& writableDir);
  93. void setCommonConfig(const string& cfgName, const string& cfgValue);
  94. void setCommonConfig(const string& cfgName, uint32_t cfgValue);
  95. void setCommonConfig(const string& cfgName, bool cfgValue);
  96. bool getCommonConfig(const string& cfgName, string& cfgValue);
  97. bool getCommonConfig(const string& cfgName, uint32_t& cfgValue);
  98. bool getCommonConfig(const string& cfgName, bool& cfgValue);
  99. inline ECSDKConfigPrivate* d_func() {
  100. return reinterpret_cast<ECSDKConfigPrivate*>(d_ptr);
  101. }
  102. private:
  103. ECSDKConfig(const ECSDKConfig &) = delete;
  104. ECSDKConfig &operator=(const ECSDKConfig &) = delete;
  105. ECSDKConfigPrivate* d_ptr;
  106. };
  107. /*!
  108. * \brief A macro used to reference ECSDKFramework instance.
  109. *
  110. * User can use this to simplify function call.
  111. */
  112. #define ecSdk (ECSDKFrameWork::ECSDKFramework::getInstance())
  113. /*!
  114. * \brief The ECSDKFramework class
  115. */
  116. class EC_DLL_EXPORT ECSDKFramework
  117. {
  118. public:
  119. /*!
  120. * \brief Singleton function.
  121. *
  122. * \return The instance of derived class.
  123. */
  124. static ECSDKFramework* getInstance();
  125. /*!
  126. * @brief Initialize ECSDKFramework environment.
  127. * After ECSDKFramework was initialized, user can call ECSDKFramework::start to communicate with the
  128. * connected phone. ECSDKFramework supports finding an connected phone(Android or iOS)
  129. * via USB cable and WiFi.
  130. *
  131. * \param cfg
  132. *
  133. * \param pListener
  134. *
  135. * \param dev This parameter usually does not require an assignment, and when the user needs to
  136. * use the eap connection mode, a read-write interface needs to be provided
  137. * \return
  138. */
  139. virtual bool initialize(ECSDKConfig* cfg, IECSDKListener* pListener, IECAccessDevice* dev = nullptr) = 0;
  140. /*!
  141. * \brief release
  142. * \return
  143. */
  144. virtual void release() = 0;
  145. /*!
  146. * \brief setECSDKLogConfig
  147. * \param cfg
  148. */
  149. virtual void setECSDKLogConfig(const ECLogConfig& cfg) = 0;
  150. /*!
  151. * \brief Start this module.
  152. *
  153. * @return ECSDK_OK on success, others on fail.
  154. *
  155. * \note After calling this interface, the ECSDKFramework establishes a connection to the phone
  156. */
  157. virtual int32_t start() = 0;
  158. /*!
  159. * \brief Stop this module.
  160. *
  161. * \note Call this interface when you don't need to connect to your phone
  162. */
  163. virtual void stop() = 0;
  164. /*!
  165. * \brief Used to get version
  166. *
  167. * @return The ECSDKFramework version in string format, etc. "0.1.0.9.7.3".
  168. */
  169. virtual const string& getECVersion() = 0;
  170. /*!
  171. * \brief Used to get version code
  172. *
  173. * @return The ECSDKFramework version code.
  174. */
  175. virtual uint32_t getECVersionCode() = 0;
  176. /**
  177. * @brief This method will enable ota network update use sandbox environment.
  178. *
  179. * @note The default environment of ota network update is production.
  180. */
  181. virtual int32_t enableSandbox() = 0;
  182. /**
  183. * @brief User need to call this interface when the network state of the vehicle changes.
  184. *
  185. * \param action
  186. *
  187. * \param netInfo
  188. *
  189. * @return ECSDK_OK on success, others on fail.
  190. */
  191. virtual int32_t notifyWifiStateChanged(ECWifiStateAction action, const ECNetWorkInfo& netInfo) = 0;
  192. /**
  193. * @brief User need to call this interface when usb device state has changed.
  194. *
  195. * \param state usb device current status.
  196. *
  197. * @return ECSDK_OK on success, others on fail.
  198. */
  199. virtual int32_t notifyDeviceStateChanged(ECDeviceState state) = 0;
  200. /**
  201. * @brief This method will configure some information to tranpsport with a phone.
  202. *
  203. * @param key referred to ECTransportInfo
  204. *
  205. * @param value the value to corresponding key.
  206. *
  207. * @note Next connection takes effect.
  208. * User just need to call this method once. The config will be always valid until next ECSDKFramework::initialize.
  209. */
  210. virtual int32_t configTransportInfo(int32_t key, int32_t value) = 0;
  211. protected:
  212. /*!
  213. * \brief Default constructor.
  214. */
  215. ECSDKFramework();
  216. /*!
  217. * \brief Destructor.
  218. */
  219. virtual ~ECSDKFramework();
  220. };
  221. }