已合并
async work #2032
lizhihui创建于 8月18日
async work #2032
已合并
共 3 个文件变更+18-2
| @@ -54,6 +54,7 @@ enum NapiAsyncType : int { | |||
| 54 | 54 | ||
| 55 | static constexpr bool ASYNC_WORK_NEED_CALLBACK = true; | 55 | static constexpr bool ASYNC_WORK_NEED_CALLBACK = true; |
| 56 | static constexpr bool ASYNC_WORK_NO_NEED_CALLBACK = false; | 56 | static constexpr bool ASYNC_WORK_NO_NEED_CALLBACK = false; |
| 57 | +static constexpr int NAPI_QOS_USER_INTERACTIVE = 5; | ||
| 57 | 58 | ||
| 58 | struct NapiAsyncWorkRet { | 59 | struct NapiAsyncWorkRet { |
| 59 | NapiAsyncWorkRet(int errCode) : errCode(errCode) {} | 60 | NapiAsyncWorkRet(int errCode) : errCode(errCode) {} |
| @@ -78,6 +79,7 @@ public: | |||
| 78 | ~NapiAsyncWork() = default; | 79 | ~NapiAsyncWork() = default; |
| 79 | 80 | ||
| 80 | void Run(void); | 81 | void Run(void); |
| 82 | + void SetQos(int qos); | ||
| 81 | void CallFunction(int errorCode, std::shared_ptr<NapiNativeObject> object); | 83 | void CallFunction(int errorCode, std::shared_ptr<NapiNativeObject> object); |
| 82 | napi_value GetRet(void); | 84 | napi_value GetRet(void); |
| 83 | std::shared_ptr<NapiHaEventUtils> GetHaUtilsPtr(void) const; | 85 | std::shared_ptr<NapiHaEventUtils> GetHaUtilsPtr(void) const; |
| @@ -107,6 +109,7 @@ private: | |||
| 107 | std::atomic_bool triggered_ = false; // Indicates whether the asynchronous callback is called. | 109 | std::atomic_bool triggered_ = false; // Indicates whether the asynchronous callback is called. |
| 108 | std::shared_ptr<NapiHaEventUtils> haUtils_; // HA report tool, which is transferred fron the original API interface | 110 | std::shared_ptr<NapiHaEventUtils> haUtils_; // HA report tool, which is transferred fron the original API interface |
| 109 | std::vector<int32_t> validErrCodes_ {}; // Indicates valid error codes. | 111 | std::vector<int32_t> validErrCodes_ {}; // Indicates valid error codes. |
| 112 | + int qos_ = -1; | ||
| 110 | }; | 113 | }; |
| 111 | 114 | ||
| 112 | class NapiAsyncWorkFactory { | 115 | class NapiAsyncWorkFactory { |
| @@ -166,8 +166,15 @@ void NapiAsyncWork::Run(void) | |||
| 166 | delete info; | 166 | delete info; |
| 167 | return; | 167 | return; |
| 168 | } | 168 | } |
| 169 | - | 169 | + if (qos_ >= 0) { |
| 170 | - status = napi_queue_async_work(env_, info->asyncWork); | 170 | +#ifdef BLUETOOTH_API_SINCE_10 |
| 171 | + status = napi_queue_async_work_with_qos(env_, info->asyncWork, static_cast<napi_qos_t>(qos_)); | ||
| 172 | +#else | ||
| 173 | + status = napi_queue_async_work(env_, info->asyncWork); | ||
| 174 | +#endif | ||
| 175 | + } else { | ||
| 176 | + status = napi_queue_async_work(env_, info->asyncWork); | ||
| 177 | + } | ||
| 171 | if (status != napi_ok) { | 178 | if (status != napi_ok) { |
| 172 | HILOGE("napi_queue_async_work failed, status(%{public}d)", status); | 179 | HILOGE("napi_queue_async_work failed, status(%{public}d)", status); |
| 173 | napi_delete_async_work(env_, info->asyncWork); | 180 | napi_delete_async_work(env_, info->asyncWork); |
| @@ -181,6 +188,11 @@ std::shared_ptr<NapiHaEventUtils> NapiAsyncWork::GetHaUtilsPtr(void) const | |||
| 181 | return haUtils_; | 188 | return haUtils_; |
| 182 | } | 189 | } |
| 183 | 190 | ||
| 191 | +void NapiAsyncWork::SetQos(int qos) | ||
| 192 | +{ | ||
| 193 | + qos_ = qos; | ||
| 194 | +} | ||
| 195 | + | ||
| 184 | void NapiAsyncWork::TimeoutCallback(void) | 196 | void NapiAsyncWork::TimeoutCallback(void) |
| 185 | { | 197 | { |
| 186 | HILOGI("enter"); | 198 | HILOGI("enter"); |
| @@ -677,6 +677,7 @@ napi_value NapiSppClient::SppReadAsync(napi_env env, napi_callback_info info) | |||
| 677 | }; | 677 | }; |
| 678 | auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 678 | auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); |
| 679 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 679 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 680 | + asyncWork->SetQos(NAPI_QOS_USER_INTERACTIVE); | ||
| 680 | asyncWork->Run(); | 681 | asyncWork->Run(); |
| 681 | return asyncWork->GetRet(); | 682 | return asyncWork->GetRet(); |
| 682 | } | 683 | } |