已开启
增加接口HA打点 #1980
zyjjjjjjjjjjjjjjjjj创建于 7月8日
增加接口HA打点 #1980
已开启
共 27 个文件变更+604-171
| @@ -22,6 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | + | ||
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | 28 | ||
| @@ -36,9 +37,11 @@ public: | |||
| 36 | NapiEventSubscribeModule(std::vector<std::string> validEventNameVec, const char *moduleName); | 37 | NapiEventSubscribeModule(std::vector<std::string> validEventNameVec, const char *moduleName); |
| 37 | ~NapiEventSubscribeModule() = default; | 38 | ~NapiEventSubscribeModule() = default; |
| 38 | 39 | ||
| 39 | - napi_status Register(napi_env env, napi_callback_info info); | 40 | + napi_status Register(napi_env env, napi_callback_info info, |
| 41 | + const std::shared_ptr<NapiHaEventUtils> &haUtils = nullptr); | ||
| 40 | napi_status RegisterWithName(napi_env env, napi_callback_info info, std::string name); | 42 | napi_status RegisterWithName(napi_env env, napi_callback_info info, std::string name); |
| 41 | - napi_status Deregister(napi_env env, napi_callback_info info); | 43 | + napi_status Deregister(napi_env env, napi_callback_info info, |
| 44 | + const std::shared_ptr<NapiHaEventUtils> &haUtils = nullptr); | ||
| 42 | napi_status DeregisterWithName(napi_env env, napi_callback_info info, std::string name); | 45 | napi_status DeregisterWithName(napi_env env, napi_callback_info info, std::string name); |
| 43 | void PublishEvent(std::string eventName, const std::shared_ptr<NapiNativeObject> &nativeObject); | 46 | void PublishEvent(std::string eventName, const std::shared_ptr<NapiNativeObject> &nativeObject); |
| 44 | void RegisterCallback(napi_env env, std::string name, napi_value callback); | 47 | void RegisterCallback(napi_env env, std::string name, napi_value callback); |
| @@ -18,9 +18,13 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | + | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 25 | +// 拼接 BT_MODULE_NAME 与方法名,得到 HA 打点 api_name。 | ||
| 26 | + | ||
| 27 | + | ||
| 24 | namespace OHOS { | 28 | namespace OHOS { |
| 25 | namespace Bluetooth { | 29 | namespace Bluetooth { |
| 26 | 30 | ||
| @@ -30,6 +34,19 @@ public: | |||
| 30 | ~NapiHaEventUtils(); | 34 | ~NapiHaEventUtils(); |
| 31 | void WriteErrCode(const int32_t errCode); | 35 | void WriteErrCode(const int32_t errCode); |
| 32 | static void WriteErrCode(napi_env env, const int32_t errCode); | 36 | static void WriteErrCode(napi_env env, const int32_t errCode); |
| 37 | + void AddEventParam(const std::string &key, const std::string &value); | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * @brief 从 on/off 类 JS 接口的 argv[0] 解析事件名,写入 HA event 的 "event_name" 字段。 | ||
| 41 | + * 用于在 haUtils 析构上报时区分 on/off 调用的具体事件类型。 | ||
| 42 | + * @note 必须在 observer_->Register(env, info) 之前调用,确保能读到原始 JS 入参。 | ||
| 43 | + */ | ||
| 44 | + void CaptureSubscribeEventName(napi_env env, napi_callback_info info); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * @brief 在 HA event 中附加 profile 标识,用于在同一 api_name 下区分不同子模块的调用。 | ||
| 48 | + */ | ||
| 49 | + void SetProfile(const std::string &profile); | ||
| 33 | 50 | ||
| 34 | private: | 51 | private: |
| 35 | NapiHaEventUtils() = delete; | 52 | NapiHaEventUtils() = delete; |
| @@ -46,6 +63,8 @@ private: | |||
| 46 | napi_env env_; | 63 | napi_env env_; |
| 47 | std::string apiName_; | 64 | std::string apiName_; |
| 48 | int64_t beginTime_; | 65 | int64_t beginTime_; |
| 66 | + int32_t callTimes_ = 0; | ||
| 67 | + std::map<std::string, std::string> customParams_; | ||
| 49 | }; | 68 | }; |
| 50 | 69 | ||
| 51 | } // namespace Bluetooth | 70 | } // namespace Bluetooth |
| @@ -158,8 +158,11 @@ napi_value NapiA2dpSource::A2dpSourceConstructor(napi_env env, napi_callback_inf | |||
| 158 | 158 | ||
| 159 | napi_value NapiA2dpSource::On(napi_env env, napi_callback_info info) | 159 | napi_value NapiA2dpSource::On(napi_env env, napi_callback_info info) |
| 160 | { | 160 | { |
| 161 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 162 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 163 | + haUtils->SetProfile("a2dpSource"); | ||
| 161 | if (observer_) { | 164 | if (observer_) { |
| 162 | - auto status = observer_->eventSubscribe_.Register(env, info); | 165 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 163 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 166 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 164 | } | 167 | } |
| 165 | 168 | ||
| @@ -173,8 +176,11 @@ napi_value NapiA2dpSource::On(napi_env env, napi_callback_info info) | |||
| 173 | 176 | ||
| 174 | napi_value NapiA2dpSource::Off(napi_env env, napi_callback_info info) | 177 | napi_value NapiA2dpSource::Off(napi_env env, napi_callback_info info) |
| 175 | { | 178 | { |
| 179 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 180 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 181 | + haUtils->SetProfile("a2dpSource"); | ||
| 176 | if (observer_) { | 182 | if (observer_) { |
| 177 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 183 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 178 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 184 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 179 | } | 185 | } |
| 180 | return NapiGetUndefinedRet(env); | 186 | return NapiGetUndefinedRet(env); |
| @@ -182,6 +188,7 @@ napi_value NapiA2dpSource::Off(napi_env env, napi_callback_info info) | |||
| 182 | 188 | ||
| 183 | napi_value NapiA2dpSource::GetPlayingState(napi_env env, napi_callback_info info) | 189 | napi_value NapiA2dpSource::GetPlayingState(napi_env env, napi_callback_info info) |
| 184 | { | 190 | { |
| 191 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getPlayingState)); | ||
| 185 | HILOGD("start"); | 192 | HILOGD("start"); |
| 186 | int state = PlayingState::STATE_NOT_PLAYING; | 193 | int state = PlayingState::STATE_NOT_PLAYING; |
| 187 | napi_value ret = nullptr; | 194 | napi_value ret = nullptr; |
| @@ -203,6 +210,7 @@ napi_value NapiA2dpSource::GetPlayingState(napi_env env, napi_callback_info info | |||
| 203 | 210 | ||
| 204 | napi_value NapiA2dpSource::Connect(napi_env env, napi_callback_info info) | 211 | napi_value NapiA2dpSource::Connect(napi_env env, napi_callback_info info) |
| 205 | { | 212 | { |
| 213 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 206 | HILOGD("start"); | 214 | HILOGD("start"); |
| 207 | std::string remoteAddr{}; | 215 | std::string remoteAddr{}; |
| 208 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 216 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -219,6 +227,7 @@ napi_value NapiA2dpSource::Connect(napi_env env, napi_callback_info info) | |||
| 219 | 227 | ||
| 220 | napi_value NapiA2dpSource::Disconnect(napi_env env, napi_callback_info info) | 228 | napi_value NapiA2dpSource::Disconnect(napi_env env, napi_callback_info info) |
| 221 | { | 229 | { |
| 230 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 222 | HILOGD("start"); | 231 | HILOGD("start"); |
| 223 | std::string remoteAddr{}; | 232 | std::string remoteAddr{}; |
| 224 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 233 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -369,6 +378,7 @@ napi_value NapiA2dpSource::A2dpPropertyValueInit(napi_env env, napi_value export | |||
| 369 | 378 | ||
| 370 | napi_value NapiA2dpSource::GetConnectionDevices(napi_env env, napi_callback_info info) | 379 | napi_value NapiA2dpSource::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 371 | { | 380 | { |
| 381 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 372 | HILOGI("enter"); | 382 | HILOGI("enter"); |
| 373 | napi_value ret = nullptr; | 383 | napi_value ret = nullptr; |
| 374 | napi_create_array(env, &ret); | 384 | napi_create_array(env, &ret); |
| @@ -389,6 +399,7 @@ napi_value NapiA2dpSource::GetConnectionDevices(napi_env env, napi_callback_info | |||
| 389 | 399 | ||
| 390 | napi_value NapiA2dpSource::GetDeviceState(napi_env env, napi_callback_info info) | 400 | napi_value NapiA2dpSource::GetDeviceState(napi_env env, napi_callback_info info) |
| 391 | { | 401 | { |
| 402 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 392 | HILOGD("enter"); | 403 | HILOGD("enter"); |
| 393 | 404 | ||
| 394 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 405 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| @@ -442,6 +453,7 @@ napi_value NapiA2dpSource::DefineCreateProfile(napi_env env, napi_value exports) | |||
| 442 | 453 | ||
| 443 | napi_value NapiA2dpSource::CreateA2dpSrcProfile(napi_env env, napi_callback_info info) | 454 | napi_value NapiA2dpSource::CreateA2dpSrcProfile(napi_env env, napi_callback_info info) |
| 444 | { | 455 | { |
| 456 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createA2dpSrcProfile)); | ||
| 445 | napi_value profile; | 457 | napi_value profile; |
| 446 | napi_value constructor = nullptr; | 458 | napi_value constructor = nullptr; |
| 447 | napi_get_reference_value(env, g_napiProfile, &constructor); | 459 | napi_get_reference_value(env, g_napiProfile, &constructor); |
| @@ -451,6 +463,8 @@ napi_value NapiA2dpSource::CreateA2dpSrcProfile(napi_env env, napi_callback_info | |||
| 451 | 463 | ||
| 452 | napi_value NapiA2dpSource::SetConnectionStrategy(napi_env env, napi_callback_info info) | 464 | napi_value NapiA2dpSource::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 453 | { | 465 | { |
| 466 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 467 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 454 | HILOGD("start"); | 468 | HILOGD("start"); |
| 455 | std::string remoteAddr{}; | 469 | std::string remoteAddr{}; |
| 456 | int32_t strategy = 0; | 470 | int32_t strategy = 0; |
| @@ -465,7 +479,7 @@ napi_value NapiA2dpSource::SetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 465 | HILOGI("err: %{public}d", err); | 479 | HILOGI("err: %{public}d", err); |
| 466 | return NapiAsyncWorkRet(err); | 480 | return NapiAsyncWorkRet(err); |
| 467 | }; | 481 | }; |
| 468 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 482 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 469 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 483 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 470 | asyncWork->Run(); | 484 | asyncWork->Run(); |
| 471 | return asyncWork->GetRet(); | 485 | return asyncWork->GetRet(); |
| @@ -473,6 +487,8 @@ napi_value NapiA2dpSource::SetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 473 | 487 | ||
| 474 | napi_value NapiA2dpSource::GetConnectionStrategy(napi_env env, napi_callback_info info) | 488 | napi_value NapiA2dpSource::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 475 | { | 489 | { |
| 490 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 491 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 476 | HILOGD("start"); | 492 | HILOGD("start"); |
| 477 | std::string remoteAddr{}; | 493 | std::string remoteAddr{}; |
| 478 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 494 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -488,7 +504,7 @@ napi_value NapiA2dpSource::GetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 488 | auto object = std::make_shared<NapiNativeInt>(strategy); | 504 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 489 | return NapiAsyncWorkRet(err, object); | 505 | return NapiAsyncWorkRet(err, object); |
| 490 | }; | 506 | }; |
| 491 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 507 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 492 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 508 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 493 | asyncWork->Run(); | 509 | asyncWork->Run(); |
| 494 | return asyncWork->GetRet(); | 510 | return asyncWork->GetRet(); |
| @@ -496,6 +512,7 @@ napi_value NapiA2dpSource::GetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 496 | 512 | ||
| 497 | napi_value NapiA2dpSource::GetConnectionState(napi_env env, napi_callback_info info) | 513 | napi_value NapiA2dpSource::GetConnectionState(napi_env env, napi_callback_info info) |
| 498 | { | 514 | { |
| 515 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 499 | return GetDeviceState(env, info); | 516 | return GetDeviceState(env, info); |
| 500 | } | 517 | } |
| 501 | napi_value NapiA2dpSource::GetConnectedDevices(napi_env env, napi_callback_info info) | 518 | napi_value NapiA2dpSource::GetConnectedDevices(napi_env env, napi_callback_info info) |
| @@ -505,6 +522,8 @@ napi_value NapiA2dpSource::GetConnectedDevices(napi_env env, napi_callback_info | |||
| 505 | 522 | ||
| 506 | napi_value NapiA2dpSource::IsAbsoluteVolumeSupported(napi_env env, napi_callback_info info) | 523 | napi_value NapiA2dpSource::IsAbsoluteVolumeSupported(napi_env env, napi_callback_info info) |
| 507 | { | 524 | { |
| 525 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 526 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(isAbsoluteVolumeSupported)); | ||
| 508 | HILOGD("start"); | 527 | HILOGD("start"); |
| 509 | std::string remoteAddr{}; | 528 | std::string remoteAddr{}; |
| 510 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 529 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -519,7 +538,7 @@ napi_value NapiA2dpSource::IsAbsoluteVolumeSupported(napi_env env, napi_callback | |||
| 519 | } | 538 | } |
| 520 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(true)); | 539 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(true)); |
| 521 | }; | 540 | }; |
| 522 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 541 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 523 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 542 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 524 | asyncWork->Run(); | 543 | asyncWork->Run(); |
| 525 | return asyncWork->GetRet(); | 544 | return asyncWork->GetRet(); |
| @@ -527,6 +546,8 @@ napi_value NapiA2dpSource::IsAbsoluteVolumeSupported(napi_env env, napi_callback | |||
| 527 | 546 | ||
| 528 | napi_value NapiA2dpSource::IsAbsoluteVolumeEnabled(napi_env env, napi_callback_info info) | 547 | napi_value NapiA2dpSource::IsAbsoluteVolumeEnabled(napi_env env, napi_callback_info info) |
| 529 | { | 548 | { |
| 549 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 550 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(isAbsoluteVolumeEnabled)); | ||
| 530 | HILOGD("start"); | 551 | HILOGD("start"); |
| 531 | std::string remoteAddr{}; | 552 | std::string remoteAddr{}; |
| 532 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 553 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -541,7 +562,7 @@ napi_value NapiA2dpSource::IsAbsoluteVolumeEnabled(napi_env env, napi_callback_i | |||
| 541 | } | 562 | } |
| 542 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(false)); | 563 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(false)); |
| 543 | }; | 564 | }; |
| 544 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 565 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 545 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 566 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 546 | asyncWork->Run(); | 567 | asyncWork->Run(); |
| 547 | return asyncWork->GetRet(); | 568 | return asyncWork->GetRet(); |
| @@ -549,6 +570,8 @@ napi_value NapiA2dpSource::IsAbsoluteVolumeEnabled(napi_env env, napi_callback_i | |||
| 549 | 570 | ||
| 550 | napi_value NapiA2dpSource::EnableAbsoluteVolume(napi_env env, napi_callback_info info) | 571 | napi_value NapiA2dpSource::EnableAbsoluteVolume(napi_env env, napi_callback_info info) |
| 551 | { | 572 | { |
| 573 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 574 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(enableAbsoluteVolume)); | ||
| 552 | HILOGD("start"); | 575 | HILOGD("start"); |
| 553 | std::string remoteAddr{}; | 576 | std::string remoteAddr{}; |
| 554 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 577 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -560,7 +583,7 @@ napi_value NapiA2dpSource::EnableAbsoluteVolume(napi_env env, napi_callback_info | |||
| 560 | int32_t err = AvrcpTarget::GetProfile()->SetDeviceAbsVolumeAbility(remoteDevice, ability); | 583 | int32_t err = AvrcpTarget::GetProfile()->SetDeviceAbsVolumeAbility(remoteDevice, ability); |
| 561 | return NapiAsyncWorkRet(err); | 584 | return NapiAsyncWorkRet(err); |
| 562 | }; | 585 | }; |
| 563 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 586 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 564 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 587 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 565 | asyncWork->Run(); | 588 | asyncWork->Run(); |
| 566 | return asyncWork->GetRet(); | 589 | return asyncWork->GetRet(); |
| @@ -568,6 +591,8 @@ napi_value NapiA2dpSource::EnableAbsoluteVolume(napi_env env, napi_callback_info | |||
| 568 | 591 | ||
| 569 | napi_value NapiA2dpSource::DisableAbsoluteVolume(napi_env env, napi_callback_info info) | 592 | napi_value NapiA2dpSource::DisableAbsoluteVolume(napi_env env, napi_callback_info info) |
| 570 | { | 593 | { |
| 594 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 595 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(disableAbsoluteVolume)); | ||
| 571 | HILOGD("start"); | 596 | HILOGD("start"); |
| 572 | std::string remoteAddr{}; | 597 | std::string remoteAddr{}; |
| 573 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 598 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -579,7 +604,7 @@ napi_value NapiA2dpSource::DisableAbsoluteVolume(napi_env env, napi_callback_inf | |||
| 579 | int32_t err = AvrcpTarget::GetProfile()->SetDeviceAbsVolumeAbility(remoteDevice, ability); | 604 | int32_t err = AvrcpTarget::GetProfile()->SetDeviceAbsVolumeAbility(remoteDevice, ability); |
| 580 | return NapiAsyncWorkRet(err); | 605 | return NapiAsyncWorkRet(err); |
| 581 | }; | 606 | }; |
| 582 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 607 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 583 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 608 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 584 | asyncWork->Run(); | 609 | asyncWork->Run(); |
| 585 | return asyncWork->GetRet(); | 610 | return asyncWork->GetRet(); |
| @@ -996,6 +1021,7 @@ static napi_status CheckSetCodecPreferenceParam(napi_env env, napi_callback_info | |||
| 996 | 1021 | ||
| 997 | napi_value NapiA2dpSource::SetCurrentCodecInfo(napi_env env, napi_callback_info info) | 1022 | napi_value NapiA2dpSource::SetCurrentCodecInfo(napi_env env, napi_callback_info info) |
| 998 | { | 1023 | { |
| 1024 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setCurrentCodecInfo)); | ||
| 999 | std::string remoteAddr{}; | 1025 | std::string remoteAddr{}; |
| 1000 | A2dpCodecInfo a2dpCodecInfo; | 1026 | A2dpCodecInfo a2dpCodecInfo; |
| 1001 | auto status = CheckSetCodecPreferenceParam(env, info, remoteAddr, a2dpCodecInfo); | 1027 | auto status = CheckSetCodecPreferenceParam(env, info, remoteAddr, a2dpCodecInfo); |
| @@ -1010,6 +1036,7 @@ napi_value NapiA2dpSource::SetCurrentCodecInfo(napi_env env, napi_callback_info | |||
| 1010 | 1036 | ||
| 1011 | napi_value NapiA2dpSource::GetCurrentCodecInfo(napi_env env, napi_callback_info info) | 1037 | napi_value NapiA2dpSource::GetCurrentCodecInfo(napi_env env, napi_callback_info info) |
| 1012 | { | 1038 | { |
| 1039 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getCurrentCodecInfo)); | ||
| 1013 | HILOGI("start"); | 1040 | HILOGI("start"); |
| 1014 | napi_value ret = nullptr; | 1041 | napi_value ret = nullptr; |
| 1015 | napi_create_object(env, &ret); | 1042 | napi_create_object(env, &ret); |
| @@ -1029,6 +1056,7 @@ napi_value NapiA2dpSource::GetCurrentCodecInfo(napi_env env, napi_callback_info | |||
| 1029 | 1056 | ||
| 1030 | napi_value NapiA2dpSource::GetCurrentFullCodecInfo(napi_env env, napi_callback_info info) | 1057 | napi_value NapiA2dpSource::GetCurrentFullCodecInfo(napi_env env, napi_callback_info info) |
| 1031 | { | 1058 | { |
| 1059 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getCurrentFullCodecInfo)); | ||
| 1032 | HILOGI("start"); | 1060 | HILOGI("start"); |
| 1033 | napi_value ret = nullptr; | 1061 | napi_value ret = nullptr; |
| 1034 | napi_create_array(env, &ret); | 1062 | napi_create_array(env, &ret); |
| @@ -1047,6 +1075,8 @@ napi_value NapiA2dpSource::GetCurrentFullCodecInfo(napi_env env, napi_callback_i | |||
| 1047 | 1075 | ||
| 1048 | napi_value NapiA2dpSource::EnableAutoPlay(napi_env env, napi_callback_info info) | 1076 | napi_value NapiA2dpSource::EnableAutoPlay(napi_env env, napi_callback_info info) |
| 1049 | { | 1077 | { |
| 1078 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1079 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(enableAutoPlay)); | ||
| 1050 | std::string deviceId = INVALID_MAC_ADDRESS; | 1080 | std::string deviceId = INVALID_MAC_ADDRESS; |
| 1051 | auto status = CheckDeivceIdParam(env, info, deviceId); | 1081 | auto status = CheckDeivceIdParam(env, info, deviceId); |
| 1052 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status, BT_ERR_INVALID_PARAM); | 1082 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status, BT_ERR_INVALID_PARAM); |
| @@ -1058,7 +1088,7 @@ napi_value NapiA2dpSource::EnableAutoPlay(napi_env env, napi_callback_info info) | |||
| 1058 | HILOGI("err: %{public}d", err); | 1088 | HILOGI("err: %{public}d", err); |
| 1059 | return NapiAsyncWorkRet(err); | 1089 | return NapiAsyncWorkRet(err); |
| 1060 | }; | 1090 | }; |
| 1061 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1091 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1062 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1092 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1063 | asyncWork->Run(); | 1093 | asyncWork->Run(); |
| 1064 | return asyncWork->GetRet(); | 1094 | return asyncWork->GetRet(); |
| @@ -1085,6 +1115,8 @@ static napi_status CheckDisableAutoPlayParam(napi_env env, napi_callback_info in | |||
| 1085 | 1115 | ||
| 1086 | napi_value NapiA2dpSource::DisableAutoPlay(napi_env env, napi_callback_info info) | 1116 | napi_value NapiA2dpSource::DisableAutoPlay(napi_env env, napi_callback_info info) |
| 1087 | { | 1117 | { |
| 1118 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1119 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(disableAutoPlay)); | ||
| 1088 | std::string deviceId = INVALID_MAC_ADDRESS; | 1120 | std::string deviceId = INVALID_MAC_ADDRESS; |
| 1089 | int duration = 0; | 1121 | int duration = 0; |
| 1090 | auto status = CheckDisableAutoPlayParam(env, info, deviceId, duration); | 1122 | auto status = CheckDisableAutoPlayParam(env, info, deviceId, duration); |
| @@ -1097,7 +1129,7 @@ napi_value NapiA2dpSource::DisableAutoPlay(napi_env env, napi_callback_info info | |||
| 1097 | HILOGI("err: %{public}d", err); | 1129 | HILOGI("err: %{public}d", err); |
| 1098 | return NapiAsyncWorkRet(err); | 1130 | return NapiAsyncWorkRet(err); |
| 1099 | }; | 1131 | }; |
| 1100 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1132 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1101 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1133 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1102 | asyncWork->Run(); | 1134 | asyncWork->Run(); |
| 1103 | return asyncWork->GetRet(); | 1135 | return asyncWork->GetRet(); |
| @@ -1105,6 +1137,8 @@ napi_value NapiA2dpSource::DisableAutoPlay(napi_env env, napi_callback_info info | |||
| 1105 | 1137 | ||
| 1106 | napi_value NapiA2dpSource::GetAutoPlayDisabledDuration(napi_env env, napi_callback_info info) | 1138 | napi_value NapiA2dpSource::GetAutoPlayDisabledDuration(napi_env env, napi_callback_info info) |
| 1107 | { | 1139 | { |
| 1140 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1141 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getAutoPlayDisabledDuration)); | ||
| 1108 | std::string deviceId = INVALID_MAC_ADDRESS; | 1142 | std::string deviceId = INVALID_MAC_ADDRESS; |
| 1109 | auto status = CheckDeivceIdParam(env, info, deviceId); | 1143 | auto status = CheckDeivceIdParam(env, info, deviceId); |
| 1110 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status, BT_ERR_INVALID_PARAM); | 1144 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status, BT_ERR_INVALID_PARAM); |
| @@ -1118,7 +1152,7 @@ napi_value NapiA2dpSource::GetAutoPlayDisabledDuration(napi_env env, napi_callba | |||
| 1118 | auto object = std::make_shared<NapiNativeInt>(duration); | 1152 | auto object = std::make_shared<NapiNativeInt>(duration); |
| 1119 | return NapiAsyncWorkRet(err, object); | 1153 | return NapiAsyncWorkRet(err, object); |
| 1120 | }; | 1154 | }; |
| 1121 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1155 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1122 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1156 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1123 | asyncWork->Run(); | 1157 | asyncWork->Run(); |
| 1124 | return asyncWork->GetRet(); | 1158 | return asyncWork->GetRet(); |
| @@ -28,6 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | + | ||
| 31 | 32 | ||
| 32 | namespace OHOS { | 33 | namespace OHOS { |
| 33 | namespace Bluetooth { | 34 | namespace Bluetooth { |
| @@ -80,7 +81,7 @@ napi_value NapiAccess::EnableBluetooth(napi_env env, napi_callback_info info) | |||
| 80 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 81 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 81 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INTERNAL_ERROR | 82 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INTERNAL_ERROR |
| 82 | }; | 83 | }; |
| 83 | - NAPI_BT_CONTEXT(env, "access.EnableBluetooth", validErrCodes); | 84 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(EnableBluetooth), validErrCodes); |
| 84 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 85 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 85 | int32_t ret = host->EnableBle(); | 86 | int32_t ret = host->EnableBle(); |
| 86 | // if return value is a specified error code, sync interface does not process. | 87 | // if return value is a specified error code, sync interface does not process. |
| @@ -93,12 +94,14 @@ napi_value NapiAccess::EnableBluetooth(napi_env env, napi_callback_info info) | |||
| 93 | 94 | ||
| 94 | napi_value NapiAccess::RestrictBluetooth(napi_env env, napi_callback_info info) | 95 | napi_value NapiAccess::RestrictBluetooth(napi_env env, napi_callback_info info) |
| 95 | { | 96 | { |
| 97 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 98 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(restrictBluetooth)); | ||
| 96 | HILOGI("enter"); | 99 | HILOGI("enter"); |
| 97 | auto func = []() { | 100 | auto func = []() { |
| 98 | int32_t ret = BluetoothHost::GetDefaultHost().RestrictBluetooth(); | 101 | int32_t ret = BluetoothHost::GetDefaultHost().RestrictBluetooth(); |
| 99 | return NapiAsyncWorkRet(ret); | 102 | return NapiAsyncWorkRet(ret); |
| 100 | }; | 103 | }; |
| 101 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 104 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 102 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 105 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 103 | asyncWork->Run(); | 106 | asyncWork->Run(); |
| 104 | return asyncWork->GetRet(); | 107 | return asyncWork->GetRet(); |
| @@ -106,6 +109,7 @@ napi_value NapiAccess::RestrictBluetooth(napi_env env, napi_callback_info info) | |||
| 106 | 109 | ||
| 107 | napi_value NapiAccess::DisableBluetooth(napi_env env, napi_callback_info info) | 110 | napi_value NapiAccess::DisableBluetooth(napi_env env, napi_callback_info info) |
| 108 | { | 111 | { |
| 112 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disableBluetooth)); | ||
| 109 | HILOGI("enter"); | 113 | HILOGI("enter"); |
| 110 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 114 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 111 | int ret = host->DisableBt(); | 115 | int ret = host->DisableBt(); |
| @@ -115,6 +119,7 @@ napi_value NapiAccess::DisableBluetooth(napi_env env, napi_callback_info info) | |||
| 115 | 119 | ||
| 116 | napi_value NapiAccess::GetState(napi_env env, napi_callback_info info) | 120 | napi_value NapiAccess::GetState(napi_env env, napi_callback_info info) |
| 117 | { | 121 | { |
| 122 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getState)); | ||
| 118 | HILOGD("enter"); | 123 | HILOGD("enter"); |
| 119 | int32_t state = static_cast<int>(BluetoothHost::GetDefaultHost().GetBluetoothState()); | 124 | int32_t state = static_cast<int>(BluetoothHost::GetDefaultHost().GetBluetoothState()); |
| 120 | napi_value result = nullptr; | 125 | napi_value result = nullptr; |
| @@ -164,8 +169,10 @@ napi_value NapiAccess::DialogTypeInit(napi_env env) | |||
| 164 | 169 | ||
| 165 | napi_value NapiAccess::RegisterAccessObserver(napi_env env, napi_callback_info info) | 170 | napi_value NapiAccess::RegisterAccessObserver(napi_env env, napi_callback_info info) |
| 166 | { | 171 | { |
| 172 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 173 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 167 | if (g_bluetoothAccessObserver) { | 174 | if (g_bluetoothAccessObserver) { |
| 168 | - auto status = g_bluetoothAccessObserver->eventSubscribe_.Register(env, info); | 175 | + auto status = g_bluetoothAccessObserver->eventSubscribe_.Register(env, info, haUtils); |
| 169 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 176 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 170 | } | 177 | } |
| 171 | return NapiGetUndefinedRet(env); | 178 | return NapiGetUndefinedRet(env); |
| @@ -173,8 +180,10 @@ napi_value NapiAccess::RegisterAccessObserver(napi_env env, napi_callback_info i | |||
| 173 | 180 | ||
| 174 | napi_value NapiAccess::DeregisterAccessObserver(napi_env env, napi_callback_info info) | 181 | napi_value NapiAccess::DeregisterAccessObserver(napi_env env, napi_callback_info info) |
| 175 | { | 182 | { |
| 183 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 184 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 176 | if (g_bluetoothAccessObserver) { | 185 | if (g_bluetoothAccessObserver) { |
| 177 | - auto status = g_bluetoothAccessObserver->eventSubscribe_.Deregister(env, info); | 186 | + auto status = g_bluetoothAccessObserver->eventSubscribe_.Deregister(env, info, haUtils); |
| 178 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 187 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 179 | } | 188 | } |
| 180 | return NapiGetUndefinedRet(env); | 189 | return NapiGetUndefinedRet(env); |
| @@ -183,13 +192,15 @@ napi_value NapiAccess::DeregisterAccessObserver(napi_env env, napi_callback_info | |||
| 183 | 192 | ||
| 184 | napi_value NapiAccess::FactoryReset(napi_env env, napi_callback_info info) | 193 | napi_value NapiAccess::FactoryReset(napi_env env, napi_callback_info info) |
| 185 | { | 194 | { |
| 195 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 196 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(factoryReset)); | ||
| 186 | HILOGD("enter"); | 197 | HILOGD("enter"); |
| 187 | auto func = []() { | 198 | auto func = []() { |
| 188 | int32_t ret = BluetoothHost::GetDefaultHost().BluetoothFactoryReset(); | 199 | int32_t ret = BluetoothHost::GetDefaultHost().BluetoothFactoryReset(); |
| 189 | HILOGI("factoryReset ret: %{public}d", ret); | 200 | HILOGI("factoryReset ret: %{public}d", ret); |
| 190 | return NapiAsyncWorkRet(ret); | 201 | return NapiAsyncWorkRet(ret); |
| 191 | }; | 202 | }; |
| 192 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 203 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 193 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 204 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 194 | asyncWork->Run(); | 205 | asyncWork->Run(); |
| 195 | return asyncWork->GetRet(); | 206 | return asyncWork->GetRet(); |
| @@ -197,6 +208,7 @@ napi_value NapiAccess::FactoryReset(napi_env env, napi_callback_info info) | |||
| 197 | 208 | ||
| 198 | napi_value NapiAccess::GetLocalAddress(napi_env env, napi_callback_info info) | 209 | napi_value NapiAccess::GetLocalAddress(napi_env env, napi_callback_info info) |
| 199 | { | 210 | { |
| 211 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getLocalAddress)); | ||
| 200 | napi_value result = nullptr; | 212 | napi_value result = nullptr; |
| 201 | HILOGI("enter"); | 213 | HILOGI("enter"); |
| 202 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 214 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| @@ -222,6 +234,7 @@ bool CheckConvertUuid(napi_env env, napi_callback_info info, std::string &outUui | |||
| 222 | 234 | ||
| 223 | napi_value NapiAccess::ConvertUuid(napi_env env, napi_callback_info info) | 235 | napi_value NapiAccess::ConvertUuid(napi_env env, napi_callback_info info) |
| 224 | { | 236 | { |
| 237 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(convertUuid)); | ||
| 225 | std::string inputUuid = ""; | 238 | std::string inputUuid = ""; |
| 226 | auto status = CheckConvertUuid(env, info, inputUuid); | 239 | auto status = CheckConvertUuid(env, info, inputUuid); |
| 227 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status, BT_ERR_INVALID_PARAM); | 240 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status, BT_ERR_INVALID_PARAM); |
| @@ -245,6 +258,8 @@ napi_value NapiAccess::ConvertUuid(napi_env env, napi_callback_info info) | |||
| 245 | 258 | ||
| 246 | napi_value NapiAccess::AddPersistentDeviceId(napi_env env, napi_callback_info info) | 259 | napi_value NapiAccess::AddPersistentDeviceId(napi_env env, napi_callback_info info) |
| 247 | { | 260 | { |
| 261 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 262 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(addPersistentDeviceId)); | ||
| 248 | std::string deviceId = ""; | 263 | std::string deviceId = ""; |
| 249 | auto status = CheckDeviceAddressParam(env, info, deviceId); | 264 | auto status = CheckDeviceAddressParam(env, info, deviceId); |
| 250 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 265 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -257,7 +272,7 @@ napi_value NapiAccess::AddPersistentDeviceId(napi_env env, napi_callback_info in | |||
| 257 | HILOGI("AddPersistentDeviceId ret: %{public}d", ret); | 272 | HILOGI("AddPersistentDeviceId ret: %{public}d", ret); |
| 258 | return NapiAsyncWorkRet(ret); | 273 | return NapiAsyncWorkRet(ret); |
| 259 | }; | 274 | }; |
| 260 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 275 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 261 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 276 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 262 | asyncWork->Run(); | 277 | asyncWork->Run(); |
| 263 | return asyncWork->GetRet(); | 278 | return asyncWork->GetRet(); |
| @@ -265,6 +280,8 @@ napi_value NapiAccess::AddPersistentDeviceId(napi_env env, napi_callback_info in | |||
| 265 | 280 | ||
| 266 | napi_value NapiAccess::DeletePersistentDeviceId(napi_env env, napi_callback_info info) | 281 | napi_value NapiAccess::DeletePersistentDeviceId(napi_env env, napi_callback_info info) |
| 267 | { | 282 | { |
| 283 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 284 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(deletePersistentDeviceId)); | ||
| 268 | std::string deviceId = ""; | 285 | std::string deviceId = ""; |
| 269 | auto status = CheckDeviceAddressParam(env, info, deviceId); | 286 | auto status = CheckDeviceAddressParam(env, info, deviceId); |
| 270 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 287 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -277,7 +294,7 @@ napi_value NapiAccess::DeletePersistentDeviceId(napi_env env, napi_callback_info | |||
| 277 | HILOGI("DeletePersistentDeviceId ret: %{public}d", ret); | 294 | HILOGI("DeletePersistentDeviceId ret: %{public}d", ret); |
| 278 | return NapiAsyncWorkRet(ret); | 295 | return NapiAsyncWorkRet(ret); |
| 279 | }; | 296 | }; |
| 280 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 297 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 281 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 298 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 282 | asyncWork->Run(); | 299 | asyncWork->Run(); |
| 283 | return asyncWork->GetRet(); | 300 | return asyncWork->GetRet(); |
| @@ -285,6 +302,7 @@ napi_value NapiAccess::DeletePersistentDeviceId(napi_env env, napi_callback_info | |||
| 285 | 302 | ||
| 286 | napi_value NapiAccess::GetPersistentDeviceIds(napi_env env, napi_callback_info info) | 303 | napi_value NapiAccess::GetPersistentDeviceIds(napi_env env, napi_callback_info info) |
| 287 | { | 304 | { |
| 305 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getPersistentDeviceIds)); | ||
| 288 | bool isValid = false; | 306 | bool isValid = false; |
| 289 | std::vector<std::string> deviceIdVec; | 307 | std::vector<std::string> deviceIdVec; |
| 290 | int32_t ret = BluetoothHost::GetDefaultHost().ProcessRandomDeviceIdCommand( | 308 | int32_t ret = BluetoothHost::GetDefaultHost().ProcessRandomDeviceIdCommand( |
| @@ -298,6 +316,7 @@ napi_value NapiAccess::GetPersistentDeviceIds(napi_env env, napi_callback_info i | |||
| 298 | 316 | ||
| 299 | napi_value NapiAccess::isValidRandomDeviceId(napi_env env, napi_callback_info info) | 317 | napi_value NapiAccess::isValidRandomDeviceId(napi_env env, napi_callback_info info) |
| 300 | { | 318 | { |
| 319 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(isValidRandomDeviceId)); | ||
| 301 | std::string deviceId = ""; | 320 | std::string deviceId = ""; |
| 302 | auto status = CheckDeviceAddressParam(env, info, deviceId); | 321 | auto status = CheckDeviceAddressParam(env, info, deviceId); |
| 303 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 322 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -320,7 +339,7 @@ napi_value NapiAccess::EnableBluetoothAsync(napi_env env, napi_callback_info inf | |||
| 320 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, | 339 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, |
| 321 | BT_ERR_DIALOG_FOR_USER_NOT_RESPOND, BT_ERR_DIALOG_FOR_USER_REFUSE, BT_ERR_INTERNAL_ERROR | 340 | BT_ERR_DIALOG_FOR_USER_NOT_RESPOND, BT_ERR_DIALOG_FOR_USER_REFUSE, BT_ERR_INTERNAL_ERROR |
| 322 | }; | 341 | }; |
| 323 | - NAPI_BT_CONTEXT(env, "access.EnableBluetoothAsync", validErrCodes); | 342 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(EnableBluetoothAsync), validErrCodes); |
| 324 | auto func = []() { | 343 | auto func = []() { |
| 325 | bool isAsync = true; | 344 | bool isAsync = true; |
| 326 | int32_t ret = BluetoothHost::GetDefaultHost().EnableBle("", isAsync); | 345 | int32_t ret = BluetoothHost::GetDefaultHost().EnableBle("", isAsync); |
| @@ -335,6 +354,8 @@ napi_value NapiAccess::EnableBluetoothAsync(napi_env env, napi_callback_info inf | |||
| 335 | 354 | ||
| 336 | napi_value NapiAccess::DisableBluetoothAsync(napi_env env, napi_callback_info info) | 355 | napi_value NapiAccess::DisableBluetoothAsync(napi_env env, napi_callback_info info) |
| 337 | { | 356 | { |
| 357 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 358 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(disableBluetoothAsync)); | ||
| 338 | HILOGI("enter"); | 359 | HILOGI("enter"); |
| 339 | auto func = []() { | 360 | auto func = []() { |
| 340 | bool isAsync = true; | 361 | bool isAsync = true; |
| @@ -342,7 +363,7 @@ napi_value NapiAccess::DisableBluetoothAsync(napi_env env, napi_callback_info in | |||
| 342 | HILOGI("DisableBluetoothAsync ret: %{public}d", ret); | 363 | HILOGI("DisableBluetoothAsync ret: %{public}d", ret); |
| 343 | return NapiAsyncWorkRet(ret); | 364 | return NapiAsyncWorkRet(ret); |
| 344 | }; | 365 | }; |
| 345 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 366 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 346 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 367 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 347 | asyncWork->Run(); | 368 | asyncWork->Run(); |
| 348 | return asyncWork->GetRet(); | 369 | return asyncWork->GetRet(); |
| @@ -350,6 +371,7 @@ napi_value NapiAccess::DisableBluetoothAsync(napi_env env, napi_callback_info in | |||
| 350 | 371 | ||
| 351 | napi_value NapiAccess::IsBluetoothSupported(napi_env env, napi_callback_info info) | 372 | napi_value NapiAccess::IsBluetoothSupported(napi_env env, napi_callback_info info) |
| 352 | { | 373 | { |
| 374 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(isBluetoothSupported)); | ||
| 353 | bool isSupported = BluetoothHost::GetDefaultHost().IsBluetoothSupported(); | 375 | bool isSupported = BluetoothHost::GetDefaultHost().IsBluetoothSupported(); |
| 354 | napi_value result = nullptr; | 376 | napi_value result = nullptr; |
| 355 | napi_get_boolean(env, isSupported, &result); | 377 | napi_get_boolean(env, isSupported, &result); |
| @@ -376,6 +398,8 @@ napi_status ParseNotifyDialogResultParams(napi_env env, napi_value object, | |||
| 376 | 398 | ||
| 377 | napi_value NapiAccess::NotifyDialogResult(napi_env env, napi_callback_info info) | 399 | napi_value NapiAccess::NotifyDialogResult(napi_env env, napi_callback_info info) |
| 378 | { | 400 | { |
| 401 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 402 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(notifyDialogResult)); | ||
| 379 | HILOGI("enter"); | 403 | HILOGI("enter"); |
| 380 | size_t argc = ARGS_SIZE_ONE; | 404 | size_t argc = ARGS_SIZE_ONE; |
| 381 | napi_value argv[ARGS_SIZE_ONE] = {nullptr}; | 405 | napi_value argv[ARGS_SIZE_ONE] = {nullptr}; |
| @@ -394,7 +418,7 @@ napi_value NapiAccess::NotifyDialogResult(napi_env env, napi_callback_info info) | |||
| 394 | HILOGI("NotifyDialogResult err: %{public}d", ret); | 418 | HILOGI("NotifyDialogResult err: %{public}d", ret); |
| 395 | return NapiAsyncWorkRet(ret); | 419 | return NapiAsyncWorkRet(ret); |
| 396 | }; | 420 | }; |
| 397 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 421 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 398 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 422 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 399 | asyncWork->Run(); | 423 | asyncWork->Run(); |
| 400 | return asyncWork->GetRet(); | 424 | return asyncWork->GetRet(); |
| @@ -52,6 +52,8 @@ void NapiBluetoothAudioManager::DefineSystemWearDetectionInterface(napi_env env, | |||
| 52 | 52 | ||
| 53 | napi_value NapiBluetoothAudioManager::EnableWearDetection(napi_env env, napi_callback_info info) | 53 | napi_value NapiBluetoothAudioManager::EnableWearDetection(napi_env env, napi_callback_info info) |
| 54 | { | 54 | { |
| 55 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 56 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(enableWearDetection)); | ||
| 55 | HILOGD("start"); | 57 | HILOGD("start"); |
| 56 | std::string remoteAddr{}; | 58 | std::string remoteAddr{}; |
| 57 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 59 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -62,7 +64,7 @@ napi_value NapiBluetoothAudioManager::EnableWearDetection(napi_env env, napi_cal | |||
| 62 | int32_t err = wd.EnableWearDetection(remoteAddr); | 64 | int32_t err = wd.EnableWearDetection(remoteAddr); |
| 63 | return NapiAsyncWorkRet(err); | 65 | return NapiAsyncWorkRet(err); |
| 64 | }; | 66 | }; |
| 65 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 67 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 66 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 68 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 67 | asyncWork->Run(); | 69 | asyncWork->Run(); |
| 68 | return asyncWork->GetRet(); | 70 | return asyncWork->GetRet(); |
| @@ -70,6 +72,8 @@ napi_value NapiBluetoothAudioManager::EnableWearDetection(napi_env env, napi_cal | |||
| 70 | 72 | ||
| 71 | napi_value NapiBluetoothAudioManager::DisableWearDetection(napi_env env, napi_callback_info info) | 73 | napi_value NapiBluetoothAudioManager::DisableWearDetection(napi_env env, napi_callback_info info) |
| 72 | { | 74 | { |
| 75 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 76 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(disableWearDetection)); | ||
| 73 | HILOGD("start"); | 77 | HILOGD("start"); |
| 74 | std::string remoteAddr{}; | 78 | std::string remoteAddr{}; |
| 75 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 79 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -80,7 +84,7 @@ napi_value NapiBluetoothAudioManager::DisableWearDetection(napi_env env, napi_ca | |||
| 80 | int32_t err = wd.DisableWearDetection(remoteAddr); | 84 | int32_t err = wd.DisableWearDetection(remoteAddr); |
| 81 | return NapiAsyncWorkRet(err); | 85 | return NapiAsyncWorkRet(err); |
| 82 | }; | 86 | }; |
| 83 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 87 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 84 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 88 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 85 | asyncWork->Run(); | 89 | asyncWork->Run(); |
| 86 | return asyncWork->GetRet(); | 90 | return asyncWork->GetRet(); |
| @@ -88,6 +92,8 @@ napi_value NapiBluetoothAudioManager::DisableWearDetection(napi_env env, napi_ca | |||
| 88 | 92 | ||
| 89 | napi_value NapiBluetoothAudioManager::IsWearDetectionEnabled(napi_env env, napi_callback_info info) | 93 | napi_value NapiBluetoothAudioManager::IsWearDetectionEnabled(napi_env env, napi_callback_info info) |
| 90 | { | 94 | { |
| 95 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 96 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(isWearDetectionEnabled)); | ||
| 91 | HILOGD("start"); | 97 | HILOGD("start"); |
| 92 | std::string remoteAddr{}; | 98 | std::string remoteAddr{}; |
| 93 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 99 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -102,7 +108,7 @@ napi_value NapiBluetoothAudioManager::IsWearDetectionEnabled(napi_env env, napi_ | |||
| 102 | } | 108 | } |
| 103 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(false)); | 109 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(false)); |
| 104 | }; | 110 | }; |
| 105 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 111 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 106 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 112 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 107 | asyncWork->Run(); | 113 | asyncWork->Run(); |
| 108 | return asyncWork->GetRet(); | 114 | return asyncWork->GetRet(); |
| @@ -110,6 +116,8 @@ napi_value NapiBluetoothAudioManager::IsWearDetectionEnabled(napi_env env, napi_ | |||
| 110 | 116 | ||
| 111 | napi_value NapiBluetoothAudioManager::IsWearDetectionSupported(napi_env env, napi_callback_info info) | 117 | napi_value NapiBluetoothAudioManager::IsWearDetectionSupported(napi_env env, napi_callback_info info) |
| 112 | { | 118 | { |
| 119 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 120 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(isWearDetectionSupported)); | ||
| 113 | HILOGI("enter"); | 121 | HILOGI("enter"); |
| 114 | std::string remoteAddr{}; | 122 | std::string remoteAddr{}; |
| 115 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 123 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -123,7 +131,7 @@ napi_value NapiBluetoothAudioManager::IsWearDetectionSupported(napi_env env, nap | |||
| 123 | HILOGI("isSupported: %{public}d", isSupported); | 131 | HILOGI("isSupported: %{public}d", isSupported); |
| 124 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(isSupported)); | 132 | return NapiAsyncWorkRet(err, std::make_shared<NapiNativeBool>(isSupported)); |
| 125 | }; | 133 | }; |
| 126 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 134 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 127 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 135 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 128 | asyncWork->Run(); | 136 | asyncWork->Run(); |
| 129 | return asyncWork->GetRet(); | 137 | return asyncWork->GetRet(); |
| @@ -62,7 +62,7 @@ napi_value NapiBas::IsBasSupported(napi_env env, napi_callback_info info) | |||
| 62 | BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, | 62 | BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, |
| 63 | BT_ERR_INTERNAL_ERROR | 63 | BT_ERR_INTERNAL_ERROR |
| 64 | }; | 64 | }; |
| 65 | - NAPI_BT_CONTEXT(env, "bas.IsBasSupported", validErrCodes); | 65 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(IsBasSupported), validErrCodes); |
| 66 | bool isSupported = false; | 66 | bool isSupported = false; |
| 67 | int32_t ret = BluetoothBasHost::GetProfile()->IsBasSupported(isSupported); | 67 | int32_t ret = BluetoothBasHost::GetProfile()->IsBasSupported(isSupported); |
| 68 | NAPI_BT_ASSERT_ERR_NUM_RETURN_VERIFY(env, ret == BT_NO_ERROR, ret); | 68 | NAPI_BT_ASSERT_ERR_NUM_RETURN_VERIFY(env, ret == BT_NO_ERROR, ret); |
| @@ -79,7 +79,7 @@ napi_value NapiBas::GetRemoteDeviceBatteryInfo(napi_env env, napi_callback_info | |||
| 79 | BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, | 79 | BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, |
| 80 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_GATT_CONNECTION_NOT_ESTABILISHED | 80 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_GATT_CONNECTION_NOT_ESTABILISHED |
| 81 | }; | 81 | }; |
| 82 | - NAPI_BT_CONTEXT(env, "bas.GetRemoteDeviceBatteryInfo", validErrCodes); | 82 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GetRemoteDeviceBatteryInfo), validErrCodes); |
| 83 | BluetoothAddress deviceId; | 83 | BluetoothAddress deviceId; |
| 84 | auto status = ParseGetRemoteDeviceBatteryInfoParams(env, info, deviceId); | 84 | auto status = ParseGetRemoteDeviceBatteryInfoParams(env, info, deviceId); |
| 85 | NAPI_BT_ASSERT_ERR_NUM_RETURN_VERIFY(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 85 | NAPI_BT_ASSERT_ERR_NUM_RETURN_VERIFY(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -139,7 +139,7 @@ napi_value NapiBas::OnBatteryChange(napi_env env, napi_callback_info info) | |||
| 139 | BT_ERR_PERMISSION_FAILED, BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, | 139 | BT_ERR_PERMISSION_FAILED, BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, |
| 140 | BT_ERR_API_NOT_SUPPORT, BT_ERR_INTERNAL_ERROR | 140 | BT_ERR_API_NOT_SUPPORT, BT_ERR_INTERNAL_ERROR |
| 141 | }; | 141 | }; |
| 142 | - NAPI_BT_CONTEXT(env, "bas.OnBatteryChange", validErrCodes); | 142 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(OnBatteryChange), validErrCodes); |
| 143 | 143 | ||
| 144 | auto status = g_basObserver->eventSubscribe_.RegisterWithName(env, info, | 144 | auto status = g_basObserver->eventSubscribe_.RegisterWithName(env, info, |
| 145 | STR_BT_BAS_CALLBACK_BATTERY_LEVEL_CHANGE); | 145 | STR_BT_BAS_CALLBACK_BATTERY_LEVEL_CHANGE); |
| @@ -170,7 +170,7 @@ napi_value NapiBas::OffBatteryChange(napi_env env, napi_callback_info info) | |||
| 170 | BT_ERR_PERMISSION_FAILED, BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, | 170 | BT_ERR_PERMISSION_FAILED, BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, |
| 171 | BT_ERR_API_NOT_SUPPORT, BT_ERR_INTERNAL_ERROR | 171 | BT_ERR_API_NOT_SUPPORT, BT_ERR_INTERNAL_ERROR |
| 172 | }; | 172 | }; |
| 173 | - NAPI_BT_CONTEXT(env, "bas.OffBatteryChange", validErrCodes); | 173 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(OffBatteryChange), validErrCodes); |
| 174 | 174 | ||
| 175 | auto status = g_basObserver->eventSubscribe_.DeregisterWithName(env, info, | 175 | auto status = g_basObserver->eventSubscribe_.DeregisterWithName(env, info, |
| 176 | STR_BT_BAS_CALLBACK_BATTERY_LEVEL_CHANGE); | 176 | STR_BT_BAS_CALLBACK_BATTERY_LEVEL_CHANGE); |
| @@ -116,6 +116,7 @@ bool ParseScanParameters(napi_env env, napi_value arg, ScanOptions &info) | |||
| 116 | 116 | ||
| 117 | napi_value SysStartBLEScan(napi_env env, napi_callback_info info) | 117 | napi_value SysStartBLEScan(napi_env env, napi_callback_info info) |
| 118 | { | 118 | { |
| 119 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(startBLEScan)); | ||
| 119 | size_t argc = ARGS_SIZE_ONE; | 120 | size_t argc = ARGS_SIZE_ONE; |
| 120 | napi_value argv[] = {nullptr}; | 121 | napi_value argv[] = {nullptr}; |
| 121 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); | 122 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); |
| @@ -176,6 +177,8 @@ void SysStopBLEScanComplete(napi_env env, napi_status status, void *data) | |||
| 176 | 177 | ||
| 177 | napi_value SysStopBLEScan(napi_env env, napi_callback_info info) | 178 | napi_value SysStopBLEScan(napi_env env, napi_callback_info info) |
| 178 | { | 179 | { |
| 180 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 181 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(stopBLEScan)); | ||
| 179 | size_t argc = ARGS_SIZE_ONE; | 182 | size_t argc = ARGS_SIZE_ONE; |
| 180 | napi_value argv[] = {nullptr}; | 183 | napi_value argv[] = {nullptr}; |
| 181 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); | 184 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); |
| @@ -238,6 +241,7 @@ bool ParseDeviceFoundParameters(napi_env env, napi_value arg) | |||
| 238 | 241 | ||
| 239 | napi_value SysSubscribeBLEFound(napi_env env, napi_callback_info info) | 242 | napi_value SysSubscribeBLEFound(napi_env env, napi_callback_info info) |
| 240 | { | 243 | { |
| 244 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(subscribeBLEFound)); | ||
| 241 | size_t argc = ARGS_SIZE_ONE; | 245 | size_t argc = ARGS_SIZE_ONE; |
| 242 | napi_value argv[] = {nullptr}; | 246 | napi_value argv[] = {nullptr}; |
| 243 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); | 247 | NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); |
| @@ -258,6 +262,7 @@ napi_value SysSubscribeBLEFound(napi_env env, napi_callback_info info) | |||
| 258 | 262 | ||
| 259 | napi_value SysUnsubscribeBLEFound(napi_env env, napi_callback_info info) | 263 | napi_value SysUnsubscribeBLEFound(napi_env env, napi_callback_info info) |
| 260 | { | 264 | { |
| 265 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(unsubscribeBLEFound)); | ||
| 261 | UnregisterSysBLEObserver(env, REGISTER_SYS_BLE_FIND_DEVICE_TYPE); | 266 | UnregisterSysBLEObserver(env, REGISTER_SYS_BLE_FIND_DEVICE_TYPE); |
| 262 | return NapiGetNull(env); | 267 | return NapiGetNull(env); |
| 263 | } | 268 | } |
| @@ -302,11 +307,12 @@ static napi_status NapiBluetoothBleOnOffExecute(napi_env env, napi_callback_info | |||
| 302 | 307 | ||
| 303 | static napi_value On(napi_env env, napi_callback_info info) | 308 | static napi_value On(napi_env env, napi_callback_info info) |
| 304 | { | 309 | { |
| 310 | + std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 305 | auto bleCentralManagerFunc = [](napi_env env, napi_callback_info info) { | 311 | auto bleCentralManagerFunc = [](napi_env env, napi_callback_info info) { |
| 306 | return NapiBluetoothBleCentralManagerCallback::GetInstance().eventSubscribe_.Register(env, info); | 312 | return NapiBluetoothBleCentralManagerCallback::GetInstance().eventSubscribe_.Register(env, info); |
| 307 | }; | 313 | }; |
| 308 | - auto bleAdvertiserFunc = [](napi_env env, napi_callback_info info) { | 314 | + auto bleAdvertiserFunc = [haUtils](napi_env env, napi_callback_info info) { |
| 309 | - return g_eventSubscribe->Register(env, info); | 315 | + return g_eventSubscribe->Register(env, info, haUtils); |
| 310 | }; | 316 | }; |
| 311 | 317 | ||
| 312 | auto status = NapiBluetoothBleOnOffExecute(env, info, bleCentralManagerFunc, bleAdvertiserFunc); | 318 | auto status = NapiBluetoothBleOnOffExecute(env, info, bleCentralManagerFunc, bleAdvertiserFunc); |
| @@ -316,11 +322,12 @@ static napi_value On(napi_env env, napi_callback_info info) | |||
| 316 | 322 | ||
| 317 | static napi_value Off(napi_env env, napi_callback_info info) | 323 | static napi_value Off(napi_env env, napi_callback_info info) |
| 318 | { | 324 | { |
| 325 | + std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 319 | auto bleCentralManagerFunc = [](napi_env env, napi_callback_info info) { | 326 | auto bleCentralManagerFunc = [](napi_env env, napi_callback_info info) { |
| 320 | return NapiBluetoothBleCentralManagerCallback::GetInstance().eventSubscribe_.Deregister(env, info); | 327 | return NapiBluetoothBleCentralManagerCallback::GetInstance().eventSubscribe_.Deregister(env, info); |
| 321 | }; | 328 | }; |
| 322 | - auto bleAdvertiserFunc = [](napi_env env, napi_callback_info info) { | 329 | + auto bleAdvertiserFunc = [haUtils](napi_env env, napi_callback_info info) { |
| 323 | - return g_eventSubscribe->Deregister(env, info); | 330 | + return g_eventSubscribe->Deregister(env, info, haUtils); |
| 324 | }; | 331 | }; |
| 325 | 332 | ||
| 326 | auto status = NapiBluetoothBleOnOffExecute(env, info, bleCentralManagerFunc, bleAdvertiserFunc); | 333 | auto status = NapiBluetoothBleOnOffExecute(env, info, bleCentralManagerFunc, bleAdvertiserFunc); |
| @@ -486,7 +493,7 @@ static napi_status ParseScanEnhanceModeParameters( | |||
| 486 | HILOGI("Scan timeout is %{public}d", timeout); | 493 | HILOGI("Scan timeout is %{public}d", timeout); |
| 487 | params.scanEnhanceMode.timeout = timeout; | 494 | params.scanEnhanceMode.timeout = timeout; |
| 488 | } | 495 | } |
| 489 | - | 496 | + |
| 490 | if (IsValidBleScanEnhanceMode(params.scanEnhanceMode)) { | 497 | if (IsValidBleScanEnhanceMode(params.scanEnhanceMode)) { |
| 491 | return napi_ok; | 498 | return napi_ok; |
| 492 | } else { | 499 | } else { |
| @@ -537,7 +544,7 @@ static napi_status ParseScanParameters( | |||
| 537 | // Default value of params is ScanReportMode::NORMAL. | 544 | // Default value of params is ScanReportMode::NORMAL. |
| 538 | ConvertScanReportMode(params, scanReportMode); | 545 | ConvertScanReportMode(params, scanReportMode); |
| 539 | } | 546 | } |
| 540 | - | 547 | + |
| 541 | bool isExtended = false; | 548 | bool isExtended = false; |
| 542 | NAPI_BT_CALL_RETURN(ParseBooleanParams(env, scanArg, "isExtended", exist, isExtended)); | 549 | NAPI_BT_CALL_RETURN(ParseBooleanParams(env, scanArg, "isExtended", exist, isExtended)); |
| 543 | if (exist) { | 550 | if (exist) { |
| @@ -870,7 +877,7 @@ napi_value StartBLEScan(napi_env env, napi_callback_info info) | |||
| 870 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 877 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 871 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 878 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 872 | }; | 879 | }; |
| 873 | - NAPI_BT_CONTEXT(env, "ble.StartBLEScan", validErrCodes); | 880 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(StartBLEScan), validErrCodes); |
| 874 | std::vector<BleScanFilter> scanfilters; | 881 | std::vector<BleScanFilter> scanfilters; |
| 875 | BleScanSettings settings; | 882 | BleScanSettings settings; |
| 876 | auto status = CheckBleScanParams(env, info, scanfilters, settings); | 883 | auto status = CheckBleScanParams(env, info, scanfilters, settings); |
| @@ -889,7 +896,7 @@ napi_value StartBLEScan(napi_env env, napi_callback_info info) | |||
| 889 | napi_value StopBLEScan(napi_env env, napi_callback_info info) | 896 | napi_value StopBLEScan(napi_env env, napi_callback_info info) |
| 890 | { | 897 | { |
| 891 | HILOGD("enter"); | 898 | HILOGD("enter"); |
| 892 | - NapiHaEventUtils haUtils(env, "ble.StopBLEScan"); | 899 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(StopBLEScan)); |
| 893 | auto status = CheckEmptyParam(env, info); | 900 | auto status = CheckEmptyParam(env, info); |
| 894 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 901 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 895 | 902 | ||
| @@ -1097,7 +1104,8 @@ napi_status CheckAdvertisingData(napi_env env, napi_callback_info info, BleAdver | |||
| 1097 | napi_value StartAdvertising(napi_env env, napi_callback_info info) | 1104 | napi_value StartAdvertising(napi_env env, napi_callback_info info) |
| 1098 | { | 1105 | { |
| 1099 | HILOGI("enter"); | 1106 | HILOGI("enter"); |
| 1100 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, "ble.StartAdvertising"); | 1107 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 1108 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(StartAdvertising)); | ||
| 1101 | size_t argc = ARGS_SIZE_THREE; | 1109 | size_t argc = ARGS_SIZE_THREE; |
| 1102 | napi_value argv[ARGS_SIZE_THREE] = {nullptr}; | 1110 | napi_value argv[ARGS_SIZE_THREE] = {nullptr}; |
| 1103 | napi_value thisVar = nullptr; | 1111 | napi_value thisVar = nullptr; |
| @@ -1178,7 +1186,8 @@ napi_status CheckAdvertisingEnableParams(napi_env env, napi_callback_info info, | |||
| 1178 | napi_value EnableAdvertising(napi_env env, napi_callback_info info) | 1186 | napi_value EnableAdvertising(napi_env env, napi_callback_info info) |
| 1179 | { | 1187 | { |
| 1180 | HILOGI("enter"); | 1188 | HILOGI("enter"); |
| 1181 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, "ble.EnableAdvertising"); | 1189 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 1190 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(EnableAdvertising)); | ||
| 1182 | uint32_t advHandle = 0xFF; | 1191 | uint32_t advHandle = 0xFF; |
| 1183 | uint16_t duration = 0; | 1192 | uint16_t duration = 0; |
| 1184 | std::shared_ptr<BleAdvertiseCallback> baseCallback; | 1193 | std::shared_ptr<BleAdvertiseCallback> baseCallback; |
| @@ -1236,7 +1245,8 @@ napi_status CheckAdvertisingDisableParams(napi_env env, napi_callback_info info, | |||
| 1236 | napi_value DisableAdvertising(napi_env env, napi_callback_info info) | 1245 | napi_value DisableAdvertising(napi_env env, napi_callback_info info) |
| 1237 | { | 1246 | { |
| 1238 | HILOGI("enter"); | 1247 | HILOGI("enter"); |
| 1239 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, "ble.DisableAdvertising"); | 1248 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 1249 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(DisableAdvertising)); | ||
| 1240 | uint32_t advHandle = 0xFF; | 1250 | uint32_t advHandle = 0xFF; |
| 1241 | std::shared_ptr<BleAdvertiseCallback> baseCallback; | 1251 | std::shared_ptr<BleAdvertiseCallback> baseCallback; |
| 1242 | auto status = CheckAdvertisingDisableParams(env, info, advHandle, baseCallback); | 1252 | auto status = CheckAdvertisingDisableParams(env, info, advHandle, baseCallback); |
| @@ -1316,7 +1326,8 @@ napi_value ProcessStopAdvertisingAsyncWork(napi_env env, napi_callback_info info | |||
| 1316 | napi_value StopAdvertising(napi_env env, napi_callback_info info) | 1326 | napi_value StopAdvertising(napi_env env, napi_callback_info info) |
| 1317 | { | 1327 | { |
| 1318 | HILOGD("enter"); | 1328 | HILOGD("enter"); |
| 1319 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, "ble.StopAdvertising"); | 1329 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 1330 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(StopAdvertising)); | ||
| 1320 | size_t argc = ARGS_SIZE_TWO; | 1331 | size_t argc = ARGS_SIZE_TWO; |
| 1321 | napi_value argv[ARGS_SIZE_TWO] = {nullptr}; | 1332 | napi_value argv[ARGS_SIZE_TWO] = {nullptr}; |
| 1322 | napi_value thisVar = nullptr; | 1333 | napi_value thisVar = nullptr; |
| @@ -1402,6 +1413,7 @@ int32_t GetConnectedDevicesWithoutParam(napi_env env, napi_value &result) | |||
| 1402 | 1413 | ||
| 1403 | napi_value GetConnectedBLEDevices(napi_env env, napi_callback_info info) | 1414 | napi_value GetConnectedBLEDevices(napi_env env, napi_callback_info info) |
| 1404 | { | 1415 | { |
| 1416 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectedBLEDevices)); | ||
| 1405 | HILOGD("enter"); | 1417 | HILOGD("enter"); |
| 1406 | napi_value result = nullptr; | 1418 | napi_value result = nullptr; |
| 1407 | napi_create_array(env, &result); | 1419 | napi_create_array(env, &result); |
| @@ -103,7 +103,7 @@ napi_value NapiBleScanner::StartScan(napi_env env, napi_callback_info info) | |||
| 103 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_BLE_SCAN_NO_RESOURCE, | 103 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_BLE_SCAN_NO_RESOURCE, |
| 104 | BT_ERR_INTERNAL_ERROR, BT_ERR_BLE_SCAN_ALREADY_STARTED | 104 | BT_ERR_INTERNAL_ERROR, BT_ERR_BLE_SCAN_ALREADY_STARTED |
| 105 | }; | 105 | }; |
| 106 | - NAPI_BT_CONTEXT(env, "ble.BleScanner.StartScan", validErrCodes); | 106 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(BleScannerStartScan), validErrCodes); |
| 107 | std::vector<BleScanFilter> scanFilters; | 107 | std::vector<BleScanFilter> scanFilters; |
| 108 | BleScanSettings settings; | 108 | BleScanSettings settings; |
| 109 | auto status = CheckBleScanParams(env, info, scanFilters, settings); | 109 | auto status = CheckBleScanParams(env, info, scanFilters, settings); |
| @@ -137,7 +137,8 @@ napi_value NapiBleScanner::StartScan(napi_env env, napi_callback_info info) | |||
| 137 | napi_value NapiBleScanner::StopScan(napi_env env, napi_callback_info info) | 137 | napi_value NapiBleScanner::StopScan(napi_env env, napi_callback_info info) |
| 138 | { | 138 | { |
| 139 | HILOGI("enter"); | 139 | HILOGI("enter"); |
| 140 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, "ble.BleScanner.StopScan"); | 140 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 141 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(BleScannerStopScan)); | ||
| 141 | auto status = CheckEmptyParam(env, info); | 142 | auto status = CheckEmptyParam(env, info); |
| 142 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 143 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 143 | 144 | ||
| @@ -167,9 +168,11 @@ napi_value NapiBleScanner::StopScan(napi_env env, napi_callback_info info) | |||
| 167 | 168 | ||
| 168 | napi_value NapiBleScanner::On(napi_env env, napi_callback_info info) | 169 | napi_value NapiBleScanner::On(napi_env env, napi_callback_info info) |
| 169 | { | 170 | { |
| 171 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 172 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 170 | NapiBleScanner *napiBleScanner = NapiGetBleScanner(env, info); | 173 | NapiBleScanner *napiBleScanner = NapiGetBleScanner(env, info); |
| 171 | if (napiBleScanner && napiBleScanner->GetCallback()) { | 174 | if (napiBleScanner && napiBleScanner->GetCallback()) { |
| 172 | - auto status = napiBleScanner->GetCallback()->eventSubscribe_.Register(env, info); | 175 | + auto status = napiBleScanner->GetCallback()->eventSubscribe_.Register(env, info, haUtils); |
| 173 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 176 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 174 | } | 177 | } |
| 175 | return NapiGetUndefinedRet(env); | 178 | return NapiGetUndefinedRet(env); |
| @@ -177,9 +180,11 @@ napi_value NapiBleScanner::On(napi_env env, napi_callback_info info) | |||
| 177 | 180 | ||
| 178 | napi_value NapiBleScanner::Off(napi_env env, napi_callback_info info) | 181 | napi_value NapiBleScanner::Off(napi_env env, napi_callback_info info) |
| 179 | { | 182 | { |
| 183 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 184 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 180 | NapiBleScanner *napiBleScanner = NapiGetBleScanner(env, info); | 185 | NapiBleScanner *napiBleScanner = NapiGetBleScanner(env, info); |
| 181 | if (napiBleScanner && napiBleScanner->GetCallback()) { | 186 | if (napiBleScanner && napiBleScanner->GetCallback()) { |
| 182 | - auto status = napiBleScanner->GetCallback()->eventSubscribe_.Deregister(env, info); | 187 | + auto status = napiBleScanner->GetCallback()->eventSubscribe_.Deregister(env, info, haUtils); |
| 183 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 188 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 184 | } | 189 | } |
| 185 | return NapiGetUndefinedRet(env); | 190 | return NapiGetUndefinedRet(env); |
| @@ -316,9 +316,11 @@ static GattDescriptor *GetGattcDescriptor(const std::shared_ptr<GattClient> &cli | |||
| 316 | 316 | ||
| 317 | napi_value NapiGattClient::On(napi_env env, napi_callback_info info) | 317 | napi_value NapiGattClient::On(napi_env env, napi_callback_info info) |
| 318 | { | 318 | { |
| 319 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 320 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 319 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); | 321 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); |
| 320 | if (napiGattClient && napiGattClient->GetCallback()) { | 322 | if (napiGattClient && napiGattClient->GetCallback()) { |
| 321 | - auto status = napiGattClient->GetCallback()->eventSubscribe_.Register(env, info); | 323 | + auto status = napiGattClient->GetCallback()->eventSubscribe_.Register(env, info, haUtils); |
| 322 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 324 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 323 | } | 325 | } |
| 324 | return NapiGetUndefinedRet(env); | 326 | return NapiGetUndefinedRet(env); |
| @@ -326,9 +328,11 @@ napi_value NapiGattClient::On(napi_env env, napi_callback_info info) | |||
| 326 | 328 | ||
| 327 | napi_value NapiGattClient::Off(napi_env env, napi_callback_info info) | 329 | napi_value NapiGattClient::Off(napi_env env, napi_callback_info info) |
| 328 | { | 330 | { |
| 331 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 332 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 329 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); | 333 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); |
| 330 | if (napiGattClient && napiGattClient->GetCallback()) { | 334 | if (napiGattClient && napiGattClient->GetCallback()) { |
| 331 | - auto status = napiGattClient->GetCallback()->eventSubscribe_.Deregister(env, info); | 335 | + auto status = napiGattClient->GetCallback()->eventSubscribe_.Deregister(env, info, haUtils); |
| 332 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 336 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 333 | } | 337 | } |
| 334 | return NapiGetUndefinedRet(env); | 338 | return NapiGetUndefinedRet(env); |
| @@ -336,6 +340,7 @@ napi_value NapiGattClient::Off(napi_env env, napi_callback_info info) | |||
| 336 | 340 | ||
| 337 | napi_value NapiGattClient::OnBlePhyUpdate(napi_env env, napi_callback_info info) | 341 | napi_value NapiGattClient::OnBlePhyUpdate(napi_env env, napi_callback_info info) |
| 338 | { | 342 | { |
| 343 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onBlePhyUpdate)); | ||
| 339 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); | 344 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); |
| 340 | if (napiGattClient && napiGattClient->GetCallback()) { | 345 | if (napiGattClient && napiGattClient->GetCallback()) { |
| 341 | auto status = napiGattClient->GetCallback()->eventSubscribe_.RegisterWithName(env, info, | 346 | auto status = napiGattClient->GetCallback()->eventSubscribe_.RegisterWithName(env, info, |
| @@ -347,6 +352,7 @@ napi_value NapiGattClient::OnBlePhyUpdate(napi_env env, napi_callback_info info) | |||
| 347 | 352 | ||
| 348 | napi_value NapiGattClient::OffBlePhyUpdate(napi_env env, napi_callback_info info) | 353 | napi_value NapiGattClient::OffBlePhyUpdate(napi_env env, napi_callback_info info) |
| 349 | { | 354 | { |
| 355 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offBlePhyUpdate)); | ||
| 350 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); | 356 | NapiGattClient *napiGattClient = NapiGetGattClient(env, info); |
| 351 | if (napiGattClient && napiGattClient->GetCallback()) { | 357 | if (napiGattClient && napiGattClient->GetCallback()) { |
| 352 | auto status = napiGattClient->GetCallback()->eventSubscribe_.DeregisterWithName(env, info, | 358 | auto status = napiGattClient->GetCallback()->eventSubscribe_.DeregisterWithName(env, info, |
| @@ -372,7 +378,7 @@ static napi_status CheckGattClientNoArgc(napi_env env, napi_callback_info info, | |||
| 372 | napi_value NapiGattClient::Connect(napi_env env, napi_callback_info info) | 378 | napi_value NapiGattClient::Connect(napi_env env, napi_callback_info info) |
| 373 | { | 379 | { |
| 374 | HILOGI("enter"); | 380 | HILOGI("enter"); |
| 375 | - NapiHaEventUtils haUtils(env, "ble.GattClientDevice.Connect"); | 381 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(GattClientDeviceConnect)); |
| 376 | NapiGattClient *gattClient = nullptr; | 382 | NapiGattClient *gattClient = nullptr; |
| 377 | auto status = CheckGattClientNoArgc(env, info, &gattClient); | 383 | auto status = CheckGattClientNoArgc(env, info, &gattClient); |
| 378 | NAPI_BT_ASSERT_RETURN_FALSE(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 384 | NAPI_BT_ASSERT_RETURN_FALSE(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -390,7 +396,7 @@ napi_value NapiGattClient::Connect(napi_env env, napi_callback_info info) | |||
| 390 | napi_value NapiGattClient::Disconnect(napi_env env, napi_callback_info info) | 396 | napi_value NapiGattClient::Disconnect(napi_env env, napi_callback_info info) |
| 391 | { | 397 | { |
| 392 | HILOGI("enter"); | 398 | HILOGI("enter"); |
| 393 | - NapiHaEventUtils haUtils(env, "ble.GattClientDevice.Disconnect"); | 399 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(GattClientDeviceDisconnect)); |
| 394 | NapiGattClient* gattClient = nullptr; | 400 | NapiGattClient* gattClient = nullptr; |
| 395 | auto status = CheckGattClientNoArgc(env, info, &gattClient); | 401 | auto status = CheckGattClientNoArgc(env, info, &gattClient); |
| 396 | NAPI_BT_ASSERT_RETURN_FALSE(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 402 | NAPI_BT_ASSERT_RETURN_FALSE(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -429,6 +435,8 @@ static napi_status ParseGattClientReadCharacteristicValue(napi_env env, napi_cal | |||
| 429 | 435 | ||
| 430 | napi_value NapiGattClient::ReadCharacteristicValue(napi_env env, napi_callback_info info) | 436 | napi_value NapiGattClient::ReadCharacteristicValue(napi_env env, napi_callback_info info) |
| 431 | { | 437 | { |
| 438 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 439 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(readCharacteristicValue)); | ||
| 432 | HILOGI("enter"); | 440 | HILOGI("enter"); |
| 433 | NapiGattClient *client = nullptr; | 441 | NapiGattClient *client = nullptr; |
| 434 | GattCharacteristic *character = nullptr; | 442 | GattCharacteristic *character = nullptr; |
| @@ -448,7 +456,7 @@ napi_value NapiGattClient::ReadCharacteristicValue(napi_env env, napi_callback_i | |||
| 448 | } | 456 | } |
| 449 | return NapiAsyncWorkRet(ret); | 457 | return NapiAsyncWorkRet(ret); |
| 450 | }; | 458 | }; |
| 451 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 459 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 452 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 460 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 453 | bool success = client->GetCallback()->asyncWorkMap_.TryPush(NapiAsyncType::GATT_CLIENT_READ_CHARACTER, asyncWork); | 461 | bool success = client->GetCallback()->asyncWorkMap_.TryPush(NapiAsyncType::GATT_CLIENT_READ_CHARACTER, asyncWork); |
| 454 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); | 462 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); |
| @@ -483,6 +491,8 @@ static napi_status ParseGattClientReadDescriptorValue(napi_env env, napi_callbac | |||
| 483 | 491 | ||
| 484 | napi_value NapiGattClient::ReadDescriptorValue(napi_env env, napi_callback_info info) | 492 | napi_value NapiGattClient::ReadDescriptorValue(napi_env env, napi_callback_info info) |
| 485 | { | 493 | { |
| 494 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 495 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(readDescriptorValue)); | ||
| 486 | HILOGI("enter"); | 496 | HILOGI("enter"); |
| 487 | NapiGattClient *client = nullptr; | 497 | NapiGattClient *client = nullptr; |
| 488 | GattDescriptor *descriptor = nullptr; | 498 | GattDescriptor *descriptor = nullptr; |
| @@ -502,7 +512,7 @@ napi_value NapiGattClient::ReadDescriptorValue(napi_env env, napi_callback_info | |||
| 502 | } | 512 | } |
| 503 | return NapiAsyncWorkRet(ret); | 513 | return NapiAsyncWorkRet(ret); |
| 504 | }; | 514 | }; |
| 505 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 515 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 506 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 516 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 507 | bool success = client->GetCallback()->asyncWorkMap_.TryPush(NapiAsyncType::GATT_CLIENT_READ_DESCRIPTOR, asyncWork); | 517 | bool success = client->GetCallback()->asyncWorkMap_.TryPush(NapiAsyncType::GATT_CLIENT_READ_DESCRIPTOR, asyncWork); |
| 508 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); | 518 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); |
| @@ -526,6 +536,7 @@ static napi_status ParseGattClientGetConnectState( | |||
| 526 | 536 | ||
| 527 | napi_value NapiGattClient::GetConnectedState(napi_env env, napi_callback_info info) | 537 | napi_value NapiGattClient::GetConnectedState(napi_env env, napi_callback_info info) |
| 528 | { | 538 | { |
| 539 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectedState)); | ||
| 529 | NapiGattClient *client = nullptr; | 540 | NapiGattClient *client = nullptr; |
| 530 | auto status = ParseGattClientGetConnectState(env, info, &client); | 541 | auto status = ParseGattClientGetConnectState(env, info, &client); |
| 531 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 542 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -582,6 +593,8 @@ int ConvertToPrior(int connectionParam) | |||
| 582 | 593 | ||
| 583 | napi_value NapiGattClient::UpdateConnectionParam(napi_env env, napi_callback_info info) | 594 | napi_value NapiGattClient::UpdateConnectionParam(napi_env env, napi_callback_info info) |
| 584 | { | 595 | { |
| 596 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 597 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(updateConnectionParam)); | ||
| 585 | HILOGD("enter"); | 598 | HILOGD("enter"); |
| 586 | int connectionParam = -1; | 599 | int connectionParam = -1; |
| 587 | NapiGattClient *client = nullptr; | 600 | NapiGattClient *client = nullptr; |
| @@ -595,7 +608,7 @@ napi_value NapiGattClient::UpdateConnectionParam(napi_env env, napi_callback_inf | |||
| 595 | return NapiAsyncWorkRet(ret); | 608 | return NapiAsyncWorkRet(ret); |
| 596 | }; | 609 | }; |
| 597 | 610 | ||
| 598 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 611 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 599 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 612 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 600 | bool success = client->GetCallback()->asyncWorkMap_.TryPush( | 613 | bool success = client->GetCallback()->asyncWorkMap_.TryPush( |
| 601 | NapiAsyncType::GATT_CLIENT_UPDATE_CONNECTION_PRIORITY, asyncWork); | 614 | NapiAsyncType::GATT_CLIENT_UPDATE_CONNECTION_PRIORITY, asyncWork); |
| @@ -625,7 +638,7 @@ napi_value NapiGattClient::GetServices(napi_env env, napi_callback_info info) | |||
| 625 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 638 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 626 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INTERNAL_ERROR, | 639 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INTERNAL_ERROR, |
| 627 | }; | 640 | }; |
| 628 | - NAPI_BT_CONTEXT(env, "ble.GattClientDevice.GetServices", validErrCodes); | 641 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattClientDeviceGetServices), validErrCodes); |
| 629 | NapiGattClient *client = nullptr; | 642 | NapiGattClient *client = nullptr; |
| 630 | auto status = ParseGattClientGetServices(env, info, &client); | 643 | auto status = ParseGattClientGetServices(env, info, &client); |
| 631 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok && client, BT_ERR_INVALID_PARAM); | 644 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok && client, BT_ERR_INVALID_PARAM); |
| @@ -653,6 +666,7 @@ napi_value NapiGattClient::GetServices(napi_env env, napi_callback_info info) | |||
| 653 | 666 | ||
| 654 | napi_value NapiGattClient::Close(napi_env env, napi_callback_info info) | 667 | napi_value NapiGattClient::Close(napi_env env, napi_callback_info info) |
| 655 | { | 668 | { |
| 669 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(close)); | ||
| 656 | HILOGI("enter"); | 670 | HILOGI("enter"); |
| 657 | NapiGattClient* gattClient = nullptr; | 671 | NapiGattClient* gattClient = nullptr; |
| 658 | auto status = CheckGattClientNoArgc(env, info, &gattClient); | 672 | auto status = CheckGattClientNoArgc(env, info, &gattClient); |
| @@ -687,6 +701,7 @@ static napi_status CheckSetBLEMtuSize(napi_env env, napi_callback_info info, | |||
| 687 | 701 | ||
| 688 | napi_value NapiGattClient::SetBLEMtuSize(napi_env env, napi_callback_info info) | 702 | napi_value NapiGattClient::SetBLEMtuSize(napi_env env, napi_callback_info info) |
| 689 | { | 703 | { |
| 704 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setBLEMtuSize)); | ||
| 690 | HILOGI("enter"); | 705 | HILOGI("enter"); |
| 691 | NapiGattClient* gattClient = nullptr; | 706 | NapiGattClient* gattClient = nullptr; |
| 692 | int32_t mtuSize = 0; | 707 | int32_t mtuSize = 0; |
| @@ -709,7 +724,7 @@ napi_value NapiGattClient::SetBLEMtu(napi_env env, napi_callback_info info) | |||
| 709 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 724 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 710 | BT_ERR_OPERATION_BUSY, BT_ERR_INTERNAL_ERROR, BT_ERR_GATT_CONNECTION_NOT_ESTABILISHED, | 725 | BT_ERR_OPERATION_BUSY, BT_ERR_INTERNAL_ERROR, BT_ERR_GATT_CONNECTION_NOT_ESTABILISHED, |
| 711 | }; | 726 | }; |
| 712 | - NAPI_BT_CONTEXT(env, "ble.GattClientDevice.SetBLEMtu", validErrCodes); | 727 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattClientDeviceSetBLEMtu), validErrCodes); |
| 713 | 728 | ||
| 714 | NapiGattClient* gattClient = nullptr; | 729 | NapiGattClient* gattClient = nullptr; |
| 715 | int32_t mtuSize = 0; | 730 | int32_t mtuSize = 0; |
| @@ -754,6 +769,8 @@ static napi_status ParseGattClientReadRssiValue(napi_env env, napi_callback_info | |||
| 754 | 769 | ||
| 755 | napi_value NapiGattClient::GetRssiValue(napi_env env, napi_callback_info info) | 770 | napi_value NapiGattClient::GetRssiValue(napi_env env, napi_callback_info info) |
| 756 | { | 771 | { |
| 772 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 773 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getRssiValue)); | ||
| 757 | HILOGI("enter"); | 774 | HILOGI("enter"); |
| 758 | NapiGattClient *napiGattClient = nullptr; | 775 | NapiGattClient *napiGattClient = nullptr; |
| 759 | auto status = ParseGattClientReadRssiValue(env, info, &napiGattClient); | 776 | auto status = ParseGattClientReadRssiValue(env, info, &napiGattClient); |
| @@ -768,7 +785,7 @@ napi_value NapiGattClient::GetRssiValue(napi_env env, napi_callback_info info) | |||
| 768 | } | 785 | } |
| 769 | return NapiAsyncWorkRet(ret); | 786 | return NapiAsyncWorkRet(ret); |
| 770 | }; | 787 | }; |
| 771 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 788 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 772 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 789 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 773 | bool success = napiGattClient->GetCallback()->asyncWorkMap_.TryPush(GATT_CLIENT_READ_REMOTE_RSSI_VALUE, asyncWork); | 790 | bool success = napiGattClient->GetCallback()->asyncWorkMap_.TryPush(GATT_CLIENT_READ_REMOTE_RSSI_VALUE, asyncWork); |
| 774 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); | 791 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); |
| @@ -788,6 +805,8 @@ static napi_status CheckGattClientGetDeviceName(napi_env env, napi_callback_info | |||
| 788 | 805 | ||
| 789 | napi_value NapiGattClient::GetDeviceName(napi_env env, napi_callback_info info) | 806 | napi_value NapiGattClient::GetDeviceName(napi_env env, napi_callback_info info) |
| 790 | { | 807 | { |
| 808 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 809 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getDeviceName)); | ||
| 791 | HILOGD("start"); | 810 | HILOGD("start"); |
| 792 | 811 | ||
| 793 | auto status = CheckGattClientGetDeviceName(env, info); | 812 | auto status = CheckGattClientGetDeviceName(env, info); |
| @@ -806,7 +825,7 @@ napi_value NapiGattClient::GetDeviceName(napi_env env, napi_callback_info info) | |||
| 806 | auto object = std::make_shared<NapiNativeString>(deviceName); | 825 | auto object = std::make_shared<NapiNativeString>(deviceName); |
| 807 | return NapiAsyncWorkRet(err, object); | 826 | return NapiAsyncWorkRet(err, object); |
| 808 | }; | 827 | }; |
| 809 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 828 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 810 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 829 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 811 | asyncWork->Run(); | 830 | asyncWork->Run(); |
| 812 | return asyncWork->GetRet(); | 831 | return asyncWork->GetRet(); |
| @@ -909,6 +928,7 @@ napi_value NapiGattClient::WriteCharacteristicValueCommon(napi_env env, napi_cal | |||
| 909 | 928 | ||
| 910 | napi_value NapiGattClient::WriteCharacteristicValueEx(napi_env env, napi_callback_info info) | 929 | napi_value NapiGattClient::WriteCharacteristicValueEx(napi_env env, napi_callback_info info) |
| 911 | { | 930 | { |
| 931 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(writeCharacteristicValue)); | ||
| 912 | HILOGI("enter"); | 932 | HILOGI("enter"); |
| 913 | std::vector<int32_t> validErrCodes = { | 933 | std::vector<int32_t> validErrCodes = { |
| 914 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 934 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| @@ -917,12 +937,13 @@ napi_value NapiGattClient::WriteCharacteristicValueEx(napi_env env, napi_callbac | |||
| 917 | BT_ERR_GATT_CONNECTION_NOT_ENCRYPTED, BT_ERR_GATT_CONNECTION_NOT_AUTHENTICATED, | 937 | BT_ERR_GATT_CONNECTION_NOT_ENCRYPTED, BT_ERR_GATT_CONNECTION_NOT_AUTHENTICATED, |
| 918 | BT_ERR_GATT_CONNECTION_NOT_AUTHORIZED | 938 | BT_ERR_GATT_CONNECTION_NOT_AUTHORIZED |
| 919 | }; | 939 | }; |
| 920 | - std::string apiName = "ble.GattClientDevice.WriteCharacteristicValueEx"; | 940 | + std::string apiName = BT_HA_API_NAME(GattClientDeviceWriteCharacteristicValueEx); |
| 921 | return WriteCharacteristicValueCommon(env, info, false, apiName, validErrCodes); | 941 | return WriteCharacteristicValueCommon(env, info, false, apiName, validErrCodes); |
| 922 | } | 942 | } |
| 923 | 943 | ||
| 924 | napi_value NapiGattClient::WriteCharacteristicValueWithContext(napi_env env, napi_callback_info info) | 944 | napi_value NapiGattClient::WriteCharacteristicValueWithContext(napi_env env, napi_callback_info info) |
| 925 | { | 945 | { |
| 946 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(writeCharacteristicValueWithContext)); | ||
| 926 | HILOGI("enter"); | 947 | HILOGI("enter"); |
| 927 | std::vector<int32_t> validErrCodes = { | 948 | std::vector<int32_t> validErrCodes = { |
| 928 | BT_ERR_PERMISSION_FAILED, BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 949 | BT_ERR_PERMISSION_FAILED, BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| @@ -931,7 +952,7 @@ napi_value NapiGattClient::WriteCharacteristicValueWithContext(napi_env env, nap | |||
| 931 | BT_ERR_GATT_CONNECTION_NOT_ENCRYPTED, BT_ERR_GATT_CONNECTION_NOT_AUTHENTICATED, | 952 | BT_ERR_GATT_CONNECTION_NOT_ENCRYPTED, BT_ERR_GATT_CONNECTION_NOT_AUTHENTICATED, |
| 932 | BT_ERR_GATT_CONNECTION_NOT_AUTHORIZED | 953 | BT_ERR_GATT_CONNECTION_NOT_AUTHORIZED |
| 933 | }; | 954 | }; |
| 934 | - std::string apiName = "ble.GattClientDevice.WriteCharacteristicValueWithContext"; | 955 | + std::string apiName = BT_HA_API_NAME(GattClientDeviceWriteCharacteristicValueWithContext); |
| 935 | return WriteCharacteristicValueCommon(env, info, true, apiName, validErrCodes); | 956 | return WriteCharacteristicValueCommon(env, info, true, apiName, validErrCodes); |
| 936 | } | 957 | } |
| 937 | 958 | ||
| @@ -958,6 +979,8 @@ static napi_status CheckWriteDescriptorValueEx(napi_env env, napi_callback_info | |||
| 958 | 979 | ||
| 959 | napi_value NapiGattClient::WriteDescriptorValueEx(napi_env env, napi_callback_info info) | 980 | napi_value NapiGattClient::WriteDescriptorValueEx(napi_env env, napi_callback_info info) |
| 960 | { | 981 | { |
| 982 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 983 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(writeDescriptorValue)); | ||
| 961 | HILOGI("enter"); | 984 | HILOGI("enter"); |
| 962 | NapiGattClient* client = nullptr; | 985 | NapiGattClient* client = nullptr; |
| 963 | GattDescriptor* descriptor = nullptr; | 986 | GattDescriptor* descriptor = nullptr; |
| @@ -977,7 +1000,7 @@ napi_value NapiGattClient::WriteDescriptorValueEx(napi_env env, napi_callback_in | |||
| 977 | } | 1000 | } |
| 978 | return NapiAsyncWorkRet(ret); | 1001 | return NapiAsyncWorkRet(ret); |
| 979 | }; | 1002 | }; |
| 980 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 1003 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 981 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1004 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 982 | bool success = client->GetCallback()->asyncWorkMap_.TryPush(GATT_CLIENT_WRITE_DESCRIPTOR, asyncWork); | 1005 | bool success = client->GetCallback()->asyncWorkMap_.TryPush(GATT_CLIENT_WRITE_DESCRIPTOR, asyncWork); |
| 983 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); | 1006 | NAPI_BT_ASSERT_RETURN_UNDEF(env, success, BT_ERR_INTERNAL_ERROR); |
| @@ -1052,15 +1075,17 @@ static napi_value setCharacteristicChangeInner(napi_env env, napi_callback_info | |||
| 1052 | 1075 | ||
| 1053 | napi_value NapiGattClient::setCharacteristicChangeNotification(napi_env env, napi_callback_info info) | 1076 | napi_value NapiGattClient::setCharacteristicChangeNotification(napi_env env, napi_callback_info info) |
| 1054 | { | 1077 | { |
| 1078 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setCharacteristicChangeNotification)); | ||
| 1055 | HILOGI("enter"); | 1079 | HILOGI("enter"); |
| 1056 | - std::string apiName = "ble.GattClientDevice.setCharacteristicChangeNotification"; | 1080 | + std::string apiName = BT_HA_API_NAME(GattClientDeviceSetCharacteristicChangeNotification); |
| 1057 | return setCharacteristicChangeInner(env, info, true, apiName); | 1081 | return setCharacteristicChangeInner(env, info, true, apiName); |
| 1058 | } | 1082 | } |
| 1059 | 1083 | ||
| 1060 | napi_value NapiGattClient::setCharacteristicChangeIndication(napi_env env, napi_callback_info info) | 1084 | napi_value NapiGattClient::setCharacteristicChangeIndication(napi_env env, napi_callback_info info) |
| 1061 | { | 1085 | { |
| 1086 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setCharacteristicChangeIndication)); | ||
| 1062 | HILOGI("enter"); | 1087 | HILOGI("enter"); |
| 1063 | - std::string apiName = "ble.GattClientDevice.setCharacteristicChangeIndication"; | 1088 | + std::string apiName = BT_HA_API_NAME(GattClientDeviceSetCharacteristicChangeIndication); |
| 1064 | return setCharacteristicChangeInner(env, info, false, apiName); | 1089 | return setCharacteristicChangeInner(env, info, false, apiName); |
| 1065 | } | 1090 | } |
| 1066 | 1091 | ||
| @@ -1081,9 +1106,10 @@ static napi_status ParseSetPhyValue(napi_env env, napi_callback_info info, | |||
| 1081 | return napi_ok; | 1106 | return napi_ok; |
| 1082 | } | 1107 | } |
| 1083 | 1108 | ||
| 1084 | - | ||
| 1085 | napi_value NapiGattClient::SetPhy(napi_env env, napi_callback_info info) | 1109 | napi_value NapiGattClient::SetPhy(napi_env env, napi_callback_info info) |
| 1086 | { | 1110 | { |
| 1111 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1112 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setPhy)); | ||
| 1087 | HILOGI("enter"); | 1113 | HILOGI("enter"); |
| 1088 | BlePhyInfo phyValue(static_cast<int32_t>(BLE_PHY_1M), static_cast<int32_t>(BLE_PHY_1M), | 1114 | BlePhyInfo phyValue(static_cast<int32_t>(BLE_PHY_1M), static_cast<int32_t>(BLE_PHY_1M), |
| 1089 | BLE_PHY_CODED_NO_PREFERRED); | 1115 | BLE_PHY_CODED_NO_PREFERRED); |
| @@ -1100,7 +1126,7 @@ napi_value NapiGattClient::SetPhy(napi_env env, napi_callback_info info) | |||
| 1100 | return NapiAsyncWorkRet(ret); | 1126 | return NapiAsyncWorkRet(ret); |
| 1101 | }; | 1127 | }; |
| 1102 | 1128 | ||
| 1103 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 1129 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 1104 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1130 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1105 | bool success = client->GetCallback()->asyncWorkMap_.TryPush( | 1131 | bool success = client->GetCallback()->asyncWorkMap_.TryPush( |
| 1106 | NapiAsyncType::GATT_CLIENT_SET_PHY, asyncWork); | 1132 | NapiAsyncType::GATT_CLIENT_SET_PHY, asyncWork); |
| @@ -1111,6 +1137,8 @@ napi_value NapiGattClient::SetPhy(napi_env env, napi_callback_info info) | |||
| 1111 | 1137 | ||
| 1112 | napi_value NapiGattClient::ReadPhy(napi_env env, napi_callback_info info) | 1138 | napi_value NapiGattClient::ReadPhy(napi_env env, napi_callback_info info) |
| 1113 | { | 1139 | { |
| 1140 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1141 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(readPhy)); | ||
| 1114 | HILOGI("enter"); | 1142 | HILOGI("enter"); |
| 1115 | NapiGattClient *client = nullptr; | 1143 | NapiGattClient *client = nullptr; |
| 1116 | auto status = CheckGattClientNoArgc(env, info, &client); | 1144 | auto status = CheckGattClientNoArgc(env, info, &client); |
| @@ -1124,7 +1152,7 @@ napi_value NapiGattClient::ReadPhy(napi_env env, napi_callback_info info) | |||
| 1124 | return NapiAsyncWorkRet(ret); | 1152 | return NapiAsyncWorkRet(ret); |
| 1125 | }; | 1153 | }; |
| 1126 | 1154 | ||
| 1127 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 1155 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 1128 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1156 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1129 | bool success = client->GetCallback()->asyncWorkMap_.TryPush( | 1157 | bool success = client->GetCallback()->asyncWorkMap_.TryPush( |
| 1130 | NapiAsyncType::GATT_CLIENT_READ_PHY, asyncWork); | 1158 | NapiAsyncType::GATT_CLIENT_READ_PHY, asyncWork); |
| @@ -1166,7 +1194,7 @@ napi_value NapiGattClient::WriteCharacteristicValue(napi_env env, napi_callback_ | |||
| 1166 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 1194 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 1167 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_GATT_WRITE_NOT_PERMITTED, BT_ERR_INTERNAL_ERROR, | 1195 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_GATT_WRITE_NOT_PERMITTED, BT_ERR_INTERNAL_ERROR, |
| 1168 | }; | 1196 | }; |
| 1169 | - NAPI_BT_CONTEXT(env, "bluetoothmanager.GattClientDevice.WriteCharacteristicValue", validErrCodes); | 1197 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattClientDeviceWriteCharacteristicValue), validErrCodes); |
| 1170 | GattCharacteristic* characteristic = nullptr; | 1198 | GattCharacteristic* characteristic = nullptr; |
| 1171 | NapiGattClient* gattClient = nullptr; | 1199 | NapiGattClient* gattClient = nullptr; |
| 1172 | 1200 | ||
| @@ -1206,6 +1234,7 @@ static napi_status CheckWriteDescriptorValue(napi_env env, napi_callback_info in | |||
| 1206 | 1234 | ||
| 1207 | napi_value NapiGattClient::WriteDescriptorValue(napi_env env, napi_callback_info info) | 1235 | napi_value NapiGattClient::WriteDescriptorValue(napi_env env, napi_callback_info info) |
| 1208 | { | 1236 | { |
| 1237 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(writeDescriptorValue)); | ||
| 1209 | HILOGI("enter"); | 1238 | HILOGI("enter"); |
| 1210 | GattDescriptor* descriptor = nullptr; | 1239 | GattDescriptor* descriptor = nullptr; |
| 1211 | NapiGattClient* gattClient = nullptr; | 1240 | NapiGattClient* gattClient = nullptr; |
| @@ -1248,6 +1277,7 @@ static napi_status CheckSetNotifyCharacteristicChanged(napi_env env, napi_callba | |||
| 1248 | 1277 | ||
| 1249 | napi_value NapiGattClient::SetNotifyCharacteristicChanged(napi_env env, napi_callback_info info) | 1278 | napi_value NapiGattClient::SetNotifyCharacteristicChanged(napi_env env, napi_callback_info info) |
| 1250 | { | 1279 | { |
| 1280 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setNotifyCharacteristicChanged)); | ||
| 1251 | HILOGI("enter"); | 1281 | HILOGI("enter"); |
| 1252 | GattCharacteristic* characteristic = nullptr; | 1282 | GattCharacteristic* characteristic = nullptr; |
| 1253 | bool enableNotify = false; | 1283 | bool enableNotify = false; |
| @@ -27,6 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | + | ||
| 30 | 31 | ||
| 31 | namespace OHOS { | 32 | namespace OHOS { |
| 32 | namespace Bluetooth { | 33 | namespace Bluetooth { |
| @@ -129,9 +130,11 @@ static NapiGattServer *NapiGetGattServer(napi_env env, napi_callback_info info) | |||
| 129 | 130 | ||
| 130 | napi_value NapiGattServer::On(napi_env env, napi_callback_info info) | 131 | napi_value NapiGattServer::On(napi_env env, napi_callback_info info) |
| 131 | { | 132 | { |
| 133 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 134 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 132 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); | 135 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); |
| 133 | if (napiGattServer && napiGattServer->GetCallback()) { | 136 | if (napiGattServer && napiGattServer->GetCallback()) { |
| 134 | - auto status = napiGattServer->GetCallback()->eventSubscribe_.Register(env, info); | 137 | + auto status = napiGattServer->GetCallback()->eventSubscribe_.Register(env, info, haUtils); |
| 135 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 138 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 136 | } | 139 | } |
| 137 | return NapiGetUndefinedRet(env); | 140 | return NapiGetUndefinedRet(env); |
| @@ -139,9 +142,11 @@ napi_value NapiGattServer::On(napi_env env, napi_callback_info info) | |||
| 139 | 142 | ||
| 140 | napi_value NapiGattServer::Off(napi_env env, napi_callback_info info) | 143 | napi_value NapiGattServer::Off(napi_env env, napi_callback_info info) |
| 141 | { | 144 | { |
| 145 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 146 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 142 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); | 147 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); |
| 143 | if (napiGattServer && napiGattServer->GetCallback()) { | 148 | if (napiGattServer && napiGattServer->GetCallback()) { |
| 144 | - auto status = napiGattServer->GetCallback()->eventSubscribe_.Deregister(env, info); | 149 | + auto status = napiGattServer->GetCallback()->eventSubscribe_.Deregister(env, info, haUtils); |
| 145 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 150 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 146 | } | 151 | } |
| 147 | return NapiGetUndefinedRet(env); | 152 | return NapiGetUndefinedRet(env); |
| @@ -149,6 +154,7 @@ napi_value NapiGattServer::Off(napi_env env, napi_callback_info info) | |||
| 149 | 154 | ||
| 150 | napi_value NapiGattServer::OnBlePhyUpdate(napi_env env, napi_callback_info info) | 155 | napi_value NapiGattServer::OnBlePhyUpdate(napi_env env, napi_callback_info info) |
| 151 | { | 156 | { |
| 157 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onBlePhyUpdate)); | ||
| 152 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); | 158 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); |
| 153 | if (napiGattServer && napiGattServer->GetCallback()) { | 159 | if (napiGattServer && napiGattServer->GetCallback()) { |
| 154 | auto status = napiGattServer->GetCallback()->eventSubscribe_.RegisterWithName(env, info, | 160 | auto status = napiGattServer->GetCallback()->eventSubscribe_.RegisterWithName(env, info, |
| @@ -160,6 +166,7 @@ napi_value NapiGattServer::OnBlePhyUpdate(napi_env env, napi_callback_info info) | |||
| 160 | 166 | ||
| 161 | napi_value NapiGattServer::OffBlePhyUpdate(napi_env env, napi_callback_info info) | 167 | napi_value NapiGattServer::OffBlePhyUpdate(napi_env env, napi_callback_info info) |
| 162 | { | 168 | { |
| 169 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offBlePhyUpdate)); | ||
| 163 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); | 170 | NapiGattServer *napiGattServer = NapiGetGattServer(env, info); |
| 164 | if (napiGattServer && napiGattServer->GetCallback()) { | 171 | if (napiGattServer && napiGattServer->GetCallback()) { |
| 165 | auto status = napiGattServer->GetCallback()->eventSubscribe_.DeregisterWithName(env, info, | 172 | auto status = napiGattServer->GetCallback()->eventSubscribe_.DeregisterWithName(env, info, |
| @@ -207,6 +214,7 @@ static napi_status CheckGattsAddService(napi_env env, napi_callback_info info, s | |||
| 207 | 214 | ||
| 208 | napi_value NapiGattServer::AddService(napi_env env, napi_callback_info info) | 215 | napi_value NapiGattServer::AddService(napi_env env, napi_callback_info info) |
| 209 | { | 216 | { |
| 217 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(addService)); | ||
| 210 | HILOGI("enter"); | 218 | HILOGI("enter"); |
| 211 | std::shared_ptr<GattServer> server {nullptr}; | 219 | std::shared_ptr<GattServer> server {nullptr}; |
| 212 | std::unique_ptr<GattService> gattService {nullptr}; | 220 | std::unique_ptr<GattService> gattService {nullptr}; |
| @@ -233,6 +241,7 @@ static napi_status CheckGattsEmptyParam(napi_env env, napi_callback_info info, s | |||
| 233 | 241 | ||
| 234 | napi_value NapiGattServer::Close(napi_env env, napi_callback_info info) | 242 | napi_value NapiGattServer::Close(napi_env env, napi_callback_info info) |
| 235 | { | 243 | { |
| 244 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(close)); | ||
| 236 | HILOGI("enter"); | 245 | HILOGI("enter"); |
| 237 | std::shared_ptr<GattServer> server {nullptr}; | 246 | std::shared_ptr<GattServer> server {nullptr}; |
| 238 | auto status = CheckGattsEmptyParam(env, info, server); | 247 | auto status = CheckGattsEmptyParam(env, info, server); |
| @@ -264,6 +273,7 @@ static napi_status CheckGattsServiceUuid(napi_env env, napi_callback_info info, | |||
| 264 | 273 | ||
| 265 | napi_value NapiGattServer::RemoveGattService(napi_env env, napi_callback_info info) | 274 | napi_value NapiGattServer::RemoveGattService(napi_env env, napi_callback_info info) |
| 266 | { | 275 | { |
| 276 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(removeService)); | ||
| 267 | HILOGI("enter"); | 277 | HILOGI("enter"); |
| 268 | std::shared_ptr<GattServer> server {nullptr}; | 278 | std::shared_ptr<GattServer> server {nullptr}; |
| 269 | UUID serviceUuid; | 279 | UUID serviceUuid; |
| @@ -292,7 +302,7 @@ napi_value NapiGattServer::GetService(napi_env env, napi_callback_info info) | |||
| 292 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 302 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 293 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR, BT_ERR_GATT_SERVICE_NOT_FOUND | 303 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR, BT_ERR_GATT_SERVICE_NOT_FOUND |
| 294 | }; | 304 | }; |
| 295 | - NAPI_BT_CONTEXT(env, "ble.GattServer.GetService", validErrCodes); | 305 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattServerGetService), validErrCodes); |
| 296 | std::shared_ptr<GattServer> server {nullptr}; | 306 | std::shared_ptr<GattServer> server {nullptr}; |
| 297 | UUID serviceUuid; | 307 | UUID serviceUuid; |
| 298 | auto status = CheckGattsServiceUuid(env, info, server, serviceUuid); | 308 | auto status = CheckGattsServiceUuid(env, info, server, serviceUuid); |
| @@ -314,6 +324,7 @@ napi_value NapiGattServer::GetService(napi_env env, napi_callback_info info) | |||
| 314 | 324 | ||
| 315 | napi_value NapiGattServer::GetServices(napi_env env, napi_callback_info info) | 325 | napi_value NapiGattServer::GetServices(napi_env env, napi_callback_info info) |
| 316 | { | 326 | { |
| 327 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getServices)); | ||
| 317 | HILOGI("enter"); | 328 | HILOGI("enter"); |
| 318 | std::shared_ptr<GattServer> server {nullptr}; | 329 | std::shared_ptr<GattServer> server {nullptr}; |
| 319 | auto status = CheckGattsEmptyParam(env, info, server); | 330 | auto status = CheckGattsEmptyParam(env, info, server); |
| @@ -351,6 +362,7 @@ static napi_status CheckGattsSendRsp(napi_env env, napi_callback_info info, std: | |||
| 351 | 362 | ||
| 352 | napi_value NapiGattServer::SendResponse(napi_env env, napi_callback_info info) | 363 | napi_value NapiGattServer::SendResponse(napi_env env, napi_callback_info info) |
| 353 | { | 364 | { |
| 365 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(sendResponse)); | ||
| 354 | HILOGI("enter"); | 366 | HILOGI("enter"); |
| 355 | std::shared_ptr<GattServer> server {nullptr}; | 367 | std::shared_ptr<GattServer> server {nullptr}; |
| 356 | NapiGattsServerResponse rsp; | 368 | NapiGattsServerResponse rsp; |
| @@ -387,6 +399,7 @@ static napi_status ParseGattServerGetConnectState( | |||
| 387 | 399 | ||
| 388 | napi_value NapiGattServer::GetConnectedState(napi_env env, napi_callback_info info) | 400 | napi_value NapiGattServer::GetConnectedState(napi_env env, napi_callback_info info) |
| 389 | { | 401 | { |
| 402 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectedState)); | ||
| 390 | HILOGI("enter"); | 403 | HILOGI("enter"); |
| 391 | std::string deviceId; | 404 | std::string deviceId; |
| 392 | NapiGattServer *server = nullptr; | 405 | NapiGattServer *server = nullptr; |
| @@ -449,7 +462,7 @@ napi_value NapiGattServer::NotifyCharacteristicChangedEx(napi_env env, napi_call | |||
| 449 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 462 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 450 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 463 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 451 | }; | 464 | }; |
| 452 | - NAPI_BT_CONTEXT(env, "ble.GattServer.NotifyCharacteristicChangedEx", validErrCodes); | 465 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattServerNotifyCharacteristicChangedEx), validErrCodes); |
| 453 | NapiGattServer* napiServer = nullptr; | 466 | NapiGattServer* napiServer = nullptr; |
| 454 | std::string deviceId {}; | 467 | std::string deviceId {}; |
| 455 | NapiNotifyCharacteristic notifyCharacter; | 468 | NapiNotifyCharacteristic notifyCharacter; |
| @@ -504,9 +517,10 @@ static napi_status ParseSetPhyValue(napi_env env, napi_callback_info info, std:: | |||
| 504 | return napi_ok; | 517 | return napi_ok; |
| 505 | } | 518 | } |
| 506 | 519 | ||
| 507 | - | ||
| 508 | napi_value NapiGattServer::SetPhy(napi_env env, napi_callback_info info) | 520 | napi_value NapiGattServer::SetPhy(napi_env env, napi_callback_info info) |
| 509 | { | 521 | { |
| 522 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 523 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setPhy)); | ||
| 510 | HILOGI("enter"); | 524 | HILOGI("enter"); |
| 511 | std::string deviceId; | 525 | std::string deviceId; |
| 512 | BlePhyInfo phyValue(static_cast<int32_t>(BLE_PHY_1M), static_cast<int32_t>(BLE_PHY_1M), | 526 | BlePhyInfo phyValue(static_cast<int32_t>(BLE_PHY_1M), static_cast<int32_t>(BLE_PHY_1M), |
| @@ -523,7 +537,7 @@ napi_value NapiGattServer::SetPhy(napi_env env, napi_callback_info info) | |||
| 523 | } | 537 | } |
| 524 | return NapiAsyncWorkRet(ret); | 538 | return NapiAsyncWorkRet(ret); |
| 525 | }; | 539 | }; |
| 526 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 540 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 527 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 541 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 528 | bool success = server->GetCallback()->asyncWorkMap_.TryPush( | 542 | bool success = server->GetCallback()->asyncWorkMap_.TryPush( |
| 529 | NapiAsyncType::GATT_SERVER_SET_PHY, asyncWork); | 543 | NapiAsyncType::GATT_SERVER_SET_PHY, asyncWork); |
| @@ -556,6 +570,8 @@ static napi_status ParseReadPhyValue(napi_env env, napi_callback_info info, | |||
| 556 | 570 | ||
| 557 | napi_value NapiGattServer::ReadPhy(napi_env env, napi_callback_info info) | 571 | napi_value NapiGattServer::ReadPhy(napi_env env, napi_callback_info info) |
| 558 | { | 572 | { |
| 573 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 574 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(readPhy)); | ||
| 559 | HILOGI("enter"); | 575 | HILOGI("enter"); |
| 560 | std::string deviceId; | 576 | std::string deviceId; |
| 561 | NapiGattServer *server = nullptr; | 577 | NapiGattServer *server = nullptr; |
| @@ -571,7 +587,7 @@ napi_value NapiGattServer::ReadPhy(napi_env env, napi_callback_info info) | |||
| 571 | return NapiAsyncWorkRet(ret); | 587 | return NapiAsyncWorkRet(ret); |
| 572 | }; | 588 | }; |
| 573 | 589 | ||
| 574 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK); | 590 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NEED_CALLBACK, haUtils); |
| 575 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 591 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 576 | bool success = server->GetCallback()->asyncWorkMap_.TryPush( | 592 | bool success = server->GetCallback()->asyncWorkMap_.TryPush( |
| 577 | NapiAsyncType::GATT_SERVER_READ_PHY, asyncWork); | 593 | NapiAsyncType::GATT_SERVER_READ_PHY, asyncWork); |
| @@ -588,7 +604,7 @@ napi_value NapiGattServer::RemoveAllServices(napi_env env, napi_callback_info in | |||
| 588 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 604 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 589 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 605 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 590 | }; | 606 | }; |
| 591 | - NAPI_BT_CONTEXT(env, "ble.GattServer.RemoveAllServices", validErrCodes); | 607 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattServerRemoveAllServices), validErrCodes); |
| 592 | std::shared_ptr<GattServer> server {nullptr}; | 608 | std::shared_ptr<GattServer> server {nullptr}; |
| 593 | auto status = CheckGattsEmptyParam(env, info, server); | 609 | auto status = CheckGattsEmptyParam(env, info, server); |
| 594 | NAPI_BT_ASSERT_ERR_NUM_RETURN_VERIFY(env, (status == napi_ok && server != nullptr), BT_ERR_INVALID_PARAM); | 610 | NAPI_BT_ASSERT_ERR_NUM_RETURN_VERIFY(env, (status == napi_ok && server != nullptr), BT_ERR_INVALID_PARAM); |
| @@ -622,6 +638,7 @@ static napi_status CheckGattsNotify(napi_env env, napi_callback_info info, std:: | |||
| 622 | 638 | ||
| 623 | napi_value NapiGattServer::NotifyCharacteristicChanged(napi_env env, napi_callback_info info) | 639 | napi_value NapiGattServer::NotifyCharacteristicChanged(napi_env env, napi_callback_info info) |
| 624 | { | 640 | { |
| 641 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(notifyCharacteristicChanged)); | ||
| 625 | HILOGI("enter"); | 642 | HILOGI("enter"); |
| 626 | std::shared_ptr<GattServer> server {nullptr}; | 643 | std::shared_ptr<GattServer> server {nullptr}; |
| 627 | std::string deviceId {}; | 644 | std::string deviceId {}; |
| @@ -676,7 +693,7 @@ napi_value NapiGattServer::Connect(napi_env env, napi_callback_info info) | |||
| 676 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 693 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 677 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 694 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 678 | }; | 695 | }; |
| 679 | - NAPI_BT_CONTEXT(env, "ble.GattServer.Connect", validErrCodes); | 696 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattServerConnect), validErrCodes); |
| 680 | std::string deviceId; | 697 | std::string deviceId; |
| 681 | bool autoConnect = false; | 698 | bool autoConnect = false; |
| 682 | NapiGattServer *server = nullptr; | 699 | NapiGattServer *server = nullptr; |
| @@ -699,7 +716,7 @@ napi_value NapiGattServer::CancelConnection(napi_env env, napi_callback_info inf | |||
| 699 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 716 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 700 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 717 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 701 | }; | 718 | }; |
| 702 | - NAPI_BT_CONTEXT(env, "ble.GattServer.CancelConnection", validErrCodes); | 719 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GattServerCancelConnection), validErrCodes); |
| 703 | std::string deviceId; | 720 | std::string deviceId; |
| 704 | NapiGattServer *server = nullptr; | 721 | NapiGattServer *server = nullptr; |
| 705 | 722 | ||
| @@ -42,7 +42,8 @@ NapiEventSubscribeModule::NapiEventSubscribeModule(std::vector<std::string> vali | |||
| 42 | : validEventNameVec_(validEventNameVec), moduleName_(moduleName) | 42 | : validEventNameVec_(validEventNameVec), moduleName_(moduleName) |
| 43 | {} | 43 | {} |
| 44 | 44 | ||
| 45 | -napi_status NapiEventSubscribeModule::Register(napi_env env, napi_callback_info info) | 45 | +napi_status NapiEventSubscribeModule::Register(napi_env env, napi_callback_info info, |
| 46 | + const std::shared_ptr<NapiHaEventUtils> &haUtils) | ||
| 46 | { | 47 | { |
| 47 | size_t argc = ARGS_SIZE_TWO; | 48 | size_t argc = ARGS_SIZE_TWO; |
| 48 | napi_value argv[ARGS_SIZE_TWO] = {nullptr}; | 49 | napi_value argv[ARGS_SIZE_TWO] = {nullptr}; |
| @@ -58,6 +59,10 @@ napi_status NapiEventSubscribeModule::Register(napi_env env, napi_callback_info | |||
| 58 | return napi_invalid_arg; | 59 | return napi_invalid_arg; |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 62 | + if (haUtils != nullptr) { | ||
| 63 | + haUtils->AddEventParam("event_name", name); | ||
| 64 | + } | ||
| 65 | + | ||
| 61 | napi_value callback = argv[PARAM1]; | 66 | napi_value callback = argv[PARAM1]; |
| 62 | NAPI_BT_CALL_RETURN(NapiIsFunction(env, callback)); | 67 | NAPI_BT_CALL_RETURN(NapiIsFunction(env, callback)); |
| 63 | 68 | ||
| @@ -86,7 +91,8 @@ napi_status NapiEventSubscribeModule::RegisterWithName(napi_env env, napi_callba | |||
| 86 | return napi_ok; | 91 | return napi_ok; |
| 87 | } | 92 | } |
| 88 | 93 | ||
| 89 | -napi_status NapiEventSubscribeModule::Deregister(napi_env env, napi_callback_info info) | 94 | +napi_status NapiEventSubscribeModule::Deregister(napi_env env, napi_callback_info info, |
| 95 | + const std::shared_ptr<NapiHaEventUtils> &haUtils) | ||
| 90 | { | 96 | { |
| 91 | size_t argc = ARGS_SIZE_TWO; | 97 | size_t argc = ARGS_SIZE_TWO; |
| 92 | napi_value argv[ARGS_SIZE_TWO] = {nullptr}; | 98 | napi_value argv[ARGS_SIZE_TWO] = {nullptr}; |
| @@ -102,6 +108,9 @@ napi_status NapiEventSubscribeModule::Deregister(napi_env env, napi_callback_inf | |||
| 102 | name.c_str(), ToLogString(validEventNameVec_).c_str()); | 108 | name.c_str(), ToLogString(validEventNameVec_).c_str()); |
| 103 | return napi_invalid_arg; | 109 | return napi_invalid_arg; |
| 104 | } | 110 | } |
| 111 | + if (haUtils != nullptr) { | ||
| 112 | + haUtils->AddEventParam("event_name", name); | ||
| 113 | + } | ||
| 105 | 114 | ||
| 106 | if (argc == ARGS_SIZE_ONE) { | 115 | if (argc == ARGS_SIZE_ONE) { |
| 107 | HILOGI("Deregister all %{public}s callback in %{public}s module", name.c_str(), moduleName_.c_str()); | 116 | HILOGI("Deregister all %{public}s callback in %{public}s module", name.c_str(), moduleName_.c_str()); |
| @@ -20,6 +20,11 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 23 | 28 | ||
| 24 | 29 | ||
| 25 | 30 | ||
| @@ -37,10 +42,13 @@ int64_t NapiHaEventUtils::processorId_ = -1; | |||
| 37 | std::mutex NapiHaEventUtils::processorLock_; | 42 | std::mutex NapiHaEventUtils::processorLock_; |
| 38 | SafeMap<napi_env, int32_t> NapiHaEventUtils::envErrCodeMap_ = {}; | 43 | SafeMap<napi_env, int32_t> NapiHaEventUtils::envErrCodeMap_ = {}; |
| 39 | 44 | ||
| 45 | +std::unordered_map<std::string, std::atomic<int>> g_callTimesByApiName; | ||
| 46 | + | ||
| 40 | NapiHaEventUtils::NapiHaEventUtils(napi_env env, const std::string &apiName): env_(env), apiName_(apiName) | 47 | NapiHaEventUtils::NapiHaEventUtils(napi_env env, const std::string &apiName): env_(env), apiName_(apiName) |
| 41 | { | 48 | { |
| 42 | beginTime_ = GetNowTimeMs(); | 49 | beginTime_ = GetNowTimeMs(); |
| 43 | GenerateProcessorId(); | 50 | GenerateProcessorId(); |
| 51 | + callTimes_ = g_callTimesByApiName[apiName_].fetch_add(1) + 1; | ||
| 44 | } | 52 | } |
| 45 | 53 | ||
| 46 | NapiHaEventUtils::~NapiHaEventUtils() | 54 | NapiHaEventUtils::~NapiHaEventUtils() |
| @@ -58,6 +66,41 @@ void NapiHaEventUtils::WriteErrCode(const int32_t errCode) | |||
| 58 | NapiHaEventUtils::WriteErrCode(env_, errCode); | 66 | NapiHaEventUtils::WriteErrCode(env_, errCode); |
| 59 | } | 67 | } |
| 60 | 68 | ||
| 69 | +void NapiHaEventUtils::AddEventParam(const std::string &key, const std::string &value) | ||
| 70 | +{ | ||
| 71 | + customParams_[key] = value; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +void NapiHaEventUtils::SetProfile(const std::string &profile) | ||
| 75 | +{ | ||
| 76 | + AddEventParam("profile", profile); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +void NapiHaEventUtils::CaptureSubscribeEventName(napi_env env, napi_callback_info info) | ||
| 80 | +{ | ||
| 81 | + // 期望 JS 端调用形式:obj.on(eventName, callback) / obj.off(eventName, callback) | ||
| 82 | + // argv[0] 即 eventName | ||
| 83 | + constexpr napi_valuetype EXPECTED_TYPE = napi_string; | ||
| 84 | + constexpr size_t MAX_EVENT_NAME_LEN = 64; | ||
| 85 | + | ||
| 86 | + size_t argc = ARGS_SIZE_TWO; | ||
| 87 | + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; | ||
| 88 | + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); | ||
| 89 | + if (argc < ARGS_SIZE_TWO) { | ||
| 90 | + return; | ||
| 91 | + } | ||
| 92 | + napi_valuetype type = napi_undefined; | ||
| 93 | + if (napi_typeof(env, argv[0], &type) != napi_ok || type != EXPECTED_TYPE) { | ||
| 94 | + return; | ||
| 95 | + } | ||
| 96 | + char eventName[MAX_EVENT_NAME_LEN] = {0}; | ||
| 97 | + size_t strLen = 0; | ||
| 98 | + if (napi_get_value_string_utf8(env, argv[0], eventName, sizeof(eventName), &strLen) != napi_ok) { | ||
| 99 | + return; | ||
| 100 | + } | ||
| 101 | + AddEventParam("event_name", std::string(eventName, strLen)); | ||
| 102 | +} | ||
| 103 | + | ||
| 61 | void NapiHaEventUtils::GenerateProcessorId() | 104 | void NapiHaEventUtils::GenerateProcessorId() |
| 62 | { | 105 | { |
| 63 | std::lock_guard<std::mutex> lock(processorLock_); | 106 | std::lock_guard<std::mutex> lock(processorLock_); |
| @@ -102,7 +145,7 @@ std::string NapiHaEventUtils::RandomTransId() const | |||
| 102 | void NapiHaEventUtils::WriteEndEvent() const | 145 | void NapiHaEventUtils::WriteEndEvent() const |
| 103 | { | 146 | { |
| 104 | 147 | ||
| 105 | - HiviewDFX::HiAppEvent::Event event("api_diagnostic", "api_exec_end", HiviewDFX::HiAppEvent::BEHAVIOR); | 148 | + HiviewDFX::HiAppEvent::Event event("api_diagnostic", "api_called_stat", HiviewDFX::HiAppEvent::BEHAVIOR); |
| 106 | std::string transId = RandomTransId(); | 149 | std::string transId = RandomTransId(); |
| 107 | int32_t errCode = BT_NO_ERROR; // 默认API调用成功 | 150 | int32_t errCode = BT_NO_ERROR; // 默认API调用成功 |
| 108 | errCode = envErrCodeMap_.ReadVal(env_); | 151 | errCode = envErrCodeMap_.ReadVal(env_); |
| @@ -112,11 +155,16 @@ void NapiHaEventUtils::WriteEndEvent() const | |||
| 112 | event.AddParam("sdk_name", SDK_NAME); | 155 | event.AddParam("sdk_name", SDK_NAME); |
| 113 | event.AddParam("begin_time", beginTime_); | 156 | event.AddParam("begin_time", beginTime_); |
| 114 | event.AddParam("end_time", GetNowTimeMs()); | 157 | event.AddParam("end_time", GetNowTimeMs()); |
| 158 | + event.AddParam("call_times", callTimes_); | ||
| 115 | event.AddParam("result", (errCode == BT_NO_ERROR ? 0 : 1)); | 159 | event.AddParam("result", (errCode == BT_NO_ERROR ? 0 : 1)); |
| 116 | event.AddParam("error_code", errCode); | 160 | event.AddParam("error_code", errCode); |
| 161 | + for (const auto ¶m : customParams_) { | ||
| 162 | + event.AddParam(param.first, param.second); | ||
| 163 | + } | ||
| 117 | int ret = Write(event); | 164 | int ret = Write(event); |
| 118 | - HILOGD("WriteEndEvent transId:%{public}s, apiName:%{public}s, sdkName:%{public}s, errCode:%{public}d," | 165 | + HILOGD("WriteEndEvent transId:%{public}s, apiName:%{public}s, sdkName:%{public}s, " |
| 119 | - "ret:%{public}d", transId.c_str(), apiName_.c_str(), SDK_NAME.c_str(), errCode, ret); | 166 | + "callTimes:%{public}d, errCode:%{public}d, ret:%{public}d", |
| 167 | + transId.c_str(), apiName_.c_str(), SDK_NAME.c_str(), callTimes_, errCode, ret); | ||
| 120 | 168 | ||
| 121 | } | 169 | } |
| 122 | 170 | ||
| @@ -192,11 +192,13 @@ static napi_status NapiConnectionOnOffExecuteWithName(napi_env env, napi_callbac | |||
| 192 | 192 | ||
| 193 | napi_value RegisterConnectionObserver(napi_env env, napi_callback_info info) | 193 | napi_value RegisterConnectionObserver(napi_env env, napi_callback_info info) |
| 194 | { | 194 | { |
| 195 | - auto connectionObserverFunc = [](napi_env env, napi_callback_info info) { | 195 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 196 | - return g_connectionObserver->eventSubscribe_.Register(env, info); | 196 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); |
| 197 | + auto connectionObserverFunc = [haUtils](napi_env env, napi_callback_info info) { | ||
| 198 | + return g_connectionObserver->eventSubscribe_.Register(env, info, haUtils); | ||
| 197 | }; | 199 | }; |
| 198 | - auto remoteDeviceObserverFunc = [](napi_env env, napi_callback_info info) { | 200 | + auto remoteDeviceObserverFunc = [haUtils](napi_env env, napi_callback_info info) { |
| 199 | - return g_remoteDeviceObserver->eventSubscribe_.Register(env, info); | 201 | + return g_remoteDeviceObserver->eventSubscribe_.Register(env, info, haUtils); |
| 200 | }; | 202 | }; |
| 201 | 203 | ||
| 202 | auto status = NapiConnectionOnOffExecute(env, info, connectionObserverFunc, remoteDeviceObserverFunc); | 204 | auto status = NapiConnectionOnOffExecute(env, info, connectionObserverFunc, remoteDeviceObserverFunc); |
| @@ -206,11 +208,13 @@ napi_value RegisterConnectionObserver(napi_env env, napi_callback_info info) | |||
| 206 | 208 | ||
| 207 | napi_value DeRegisterConnectionObserver(napi_env env, napi_callback_info info) | 209 | napi_value DeRegisterConnectionObserver(napi_env env, napi_callback_info info) |
| 208 | { | 210 | { |
| 209 | - auto connectionObserverFunc = [](napi_env env, napi_callback_info info) { | 211 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 210 | - return g_connectionObserver->eventSubscribe_.Deregister(env, info); | 212 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); |
| 213 | + auto connectionObserverFunc = [haUtils](napi_env env, napi_callback_info info) { | ||
| 214 | + return g_connectionObserver->eventSubscribe_.Deregister(env, info, haUtils); | ||
| 211 | }; | 215 | }; |
| 212 | - auto remoteDeviceObserverFunc = [](napi_env env, napi_callback_info info) { | 216 | + auto remoteDeviceObserverFunc = [haUtils](napi_env env, napi_callback_info info) { |
| 213 | - return g_remoteDeviceObserver->eventSubscribe_.Deregister(env, info); | 217 | + return g_remoteDeviceObserver->eventSubscribe_.Deregister(env, info, haUtils); |
| 214 | }; | 218 | }; |
| 215 | 219 | ||
| 216 | auto status = NapiConnectionOnOffExecute(env, info, connectionObserverFunc, remoteDeviceObserverFunc); | 220 | auto status = NapiConnectionOnOffExecute(env, info, connectionObserverFunc, remoteDeviceObserverFunc); |
| @@ -242,7 +246,7 @@ napi_value RegisterAclConnectionObserver( | |||
| 242 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 246 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 243 | BT_ERR_INTERNAL_ERROR | 247 | BT_ERR_INTERNAL_ERROR |
| 244 | }; | 248 | }; |
| 245 | - NAPI_BT_CONTEXT(env, "connection.RegisterAclConnectionObserver", validErrCodes); | 249 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(RegisterAclConnectionObserver), validErrCodes); |
| 246 | auto connectionObserverFuncWithName = [](napi_env env, napi_callback_info info, std::string typeName) { | 250 | auto connectionObserverFuncWithName = [](napi_env env, napi_callback_info info, std::string typeName) { |
| 247 | return g_connectionObserver->eventSubscribe_.RegisterWithName(env, info, typeName); | 251 | return g_connectionObserver->eventSubscribe_.RegisterWithName(env, info, typeName); |
| 248 | }; | 252 | }; |
| @@ -280,7 +284,7 @@ napi_value DeregisterAclConnectionObserver( | |||
| 280 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 284 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 281 | BT_ERR_INTERNAL_ERROR | 285 | BT_ERR_INTERNAL_ERROR |
| 282 | }; | 286 | }; |
| 283 | - NAPI_BT_CONTEXT(env, "connection.DeregisterAclConnectionObserver", validErrCodes); | 287 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(DeregisterAclConnectionObserver), validErrCodes); |
| 284 | auto connectionObserverFuncWithName = [](napi_env env, napi_callback_info info, std::string typeName) { | 288 | auto connectionObserverFuncWithName = [](napi_env env, napi_callback_info info, std::string typeName) { |
| 285 | return g_connectionObserver->eventSubscribe_.DeregisterWithName(env, info, typeName); | 289 | return g_connectionObserver->eventSubscribe_.DeregisterWithName(env, info, typeName); |
| 286 | }; | 290 | }; |
| @@ -328,26 +332,31 @@ napi_value GetVirtualAddressByHash(napi_env env, napi_callback_info info) | |||
| 328 | 332 | ||
| 329 | napi_value OnScanModeChange(napi_env env, napi_callback_info info) | 333 | napi_value OnScanModeChange(napi_env env, napi_callback_info info) |
| 330 | { | 334 | { |
| 335 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onScanModeChange)); | ||
| 331 | return RegisterConnectionObserverWithName(env, info, REGISTER_SCAN_MODE_CHANGE_TYPE); | 336 | return RegisterConnectionObserverWithName(env, info, REGISTER_SCAN_MODE_CHANGE_TYPE); |
| 332 | } | 337 | } |
| 333 | 338 | ||
| 334 | napi_value OffScanModeChange(napi_env env, napi_callback_info info) | 339 | napi_value OffScanModeChange(napi_env env, napi_callback_info info) |
| 335 | { | 340 | { |
| 341 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offScanModeChange)); | ||
| 336 | return DeRegisterConnectionObserverWithName(env, info, REGISTER_SCAN_MODE_CHANGE_TYPE); | 342 | return DeRegisterConnectionObserverWithName(env, info, REGISTER_SCAN_MODE_CHANGE_TYPE); |
| 337 | } | 343 | } |
| 338 | 344 | ||
| 339 | napi_value OnAclStateChange(napi_env env, napi_callback_info info) | 345 | napi_value OnAclStateChange(napi_env env, napi_callback_info info) |
| 340 | { | 346 | { |
| 347 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onAclStateChange)); | ||
| 341 | return RegisterAclConnectionObserver(env, info, REGISTER_ACL_STATE_TYPE); | 348 | return RegisterAclConnectionObserver(env, info, REGISTER_ACL_STATE_TYPE); |
| 342 | } | 349 | } |
| 343 | 350 | ||
| 344 | napi_value OffAclStateChange(napi_env env, napi_callback_info info) | 351 | napi_value OffAclStateChange(napi_env env, napi_callback_info info) |
| 345 | { | 352 | { |
| 353 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offAclStateChange)); | ||
| 346 | return DeregisterAclConnectionObserver(env, info, REGISTER_ACL_STATE_TYPE); | 354 | return DeregisterAclConnectionObserver(env, info, REGISTER_ACL_STATE_TYPE); |
| 347 | } | 355 | } |
| 348 | 356 | ||
| 349 | napi_value GetBtConnectionState(napi_env env, napi_callback_info info) | 357 | napi_value GetBtConnectionState(napi_env env, napi_callback_info info) |
| 350 | { | 358 | { |
| 359 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getBtConnectionState)); | ||
| 351 | HILOGD("enter"); | 360 | HILOGD("enter"); |
| 352 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 361 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 353 | int state = static_cast<int>(BTConnectState::DISCONNECTED); | 362 | int state = static_cast<int>(BTConnectState::DISCONNECTED); |
| @@ -366,7 +375,7 @@ napi_value PairDevice(napi_env env, napi_callback_info info) | |||
| 366 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 375 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 367 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 376 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 368 | }; | 377 | }; |
| 369 | - NAPI_BT_CONTEXT(env, "connection.PairDevice", validErrCodes); | 378 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(PairDevice), validErrCodes); |
| 370 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 379 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 371 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 380 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| 372 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet, BT_ERR_INVALID_PARAM); | 381 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet, BT_ERR_INVALID_PARAM); |
| @@ -379,6 +388,7 @@ napi_value PairDevice(napi_env env, napi_callback_info info) | |||
| 379 | 388 | ||
| 380 | napi_value CancelPairedDevice(napi_env env, napi_callback_info info) | 389 | napi_value CancelPairedDevice(napi_env env, napi_callback_info info) |
| 381 | { | 390 | { |
| 391 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(cancelPairedDevice)); | ||
| 382 | HILOGD("enter"); | 392 | HILOGD("enter"); |
| 383 | std::string remoteAddr{}; | 393 | std::string remoteAddr{}; |
| 384 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 394 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -406,6 +416,7 @@ bool CheckGetRemoteDeviceNameParam(napi_env env, napi_callback_info info, std::s | |||
| 406 | 416 | ||
| 407 | napi_value GetRemoteDeviceName(napi_env env, napi_callback_info info) | 417 | napi_value GetRemoteDeviceName(napi_env env, napi_callback_info info) |
| 408 | { | 418 | { |
| 419 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getRemoteDeviceName)); | ||
| 409 | HILOGD("start"); | 420 | HILOGD("start"); |
| 410 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 421 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 411 | std::string name = INVALID_NAME; | 422 | std::string name = INVALID_NAME; |
| @@ -430,7 +441,7 @@ napi_value GetCarKeyDfxData(napi_env env, napi_callback_info info) | |||
| 430 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 441 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 431 | BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 442 | BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 432 | }; | 443 | }; |
| 433 | - NAPI_BT_CONTEXT(env, "connection.GetCarKeyDfxData", validErrCodes); | 444 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GetCarKeyDfxData), validErrCodes); |
| 434 | napi_value result = nullptr; | 445 | napi_value result = nullptr; |
| 435 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 446 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 436 | std::string dfxData; | 447 | std::string dfxData; |
| @@ -463,7 +474,7 @@ napi_value SetCarKeyCardData(napi_env env, napi_callback_info info) | |||
| 463 | BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 474 | BT_ERR_SYSTEM_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 464 | BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 475 | BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 465 | }; | 476 | }; |
| 466 | - NAPI_BT_CONTEXT(env, "connection.SetCarKeyCardData", validErrCodes); | 477 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(SetCarKeyCardData), validErrCodes); |
| 467 | std::string remoteAddr; | 478 | std::string remoteAddr; |
| 468 | int32_t action = 0; | 479 | int32_t action = 0; |
| 469 | auto status = ParseSetCarKeyCardDataParameters(env, info, remoteAddr, action); | 480 | auto status = ParseSetCarKeyCardDataParameters(env, info, remoteAddr, action); |
| @@ -476,6 +487,7 @@ napi_value SetCarKeyCardData(napi_env env, napi_callback_info info) | |||
| 476 | 487 | ||
| 477 | napi_value GetRemoteDeviceClass(napi_env env, napi_callback_info info) | 488 | napi_value GetRemoteDeviceClass(napi_env env, napi_callback_info info) |
| 478 | { | 489 | { |
| 490 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getRemoteDeviceClass)); | ||
| 479 | HILOGD("start"); | 491 | HILOGD("start"); |
| 480 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 492 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 481 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 493 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -536,6 +548,7 @@ napi_value GetPairedDevices(napi_env env, napi_callback_info info) | |||
| 536 | 548 | ||
| 537 | napi_value GetProfileConnectionState(napi_env env, napi_callback_info info) | 549 | napi_value GetProfileConnectionState(napi_env env, napi_callback_info info) |
| 538 | { | 550 | { |
| 551 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getProfileConnState)); | ||
| 539 | HILOGD("enter"); | 552 | HILOGD("enter"); |
| 540 | int profileId = 0; | 553 | int profileId = 0; |
| 541 | bool checkRet = CheckProfileIdParam(env, info, profileId); | 554 | bool checkRet = CheckProfileIdParam(env, info, profileId); |
| @@ -554,6 +567,7 @@ napi_value GetProfileConnectionState(napi_env env, napi_callback_info info) | |||
| 554 | 567 | ||
| 555 | napi_value GetProfileConnectionStateEx(napi_env env, napi_callback_info info) | 568 | napi_value GetProfileConnectionStateEx(napi_env env, napi_callback_info info) |
| 556 | { | 569 | { |
| 570 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getProfileConnectionState)); | ||
| 557 | HILOGD("enter"); | 571 | HILOGD("enter"); |
| 558 | int profileId = 0; | 572 | int profileId = 0; |
| 559 | size_t argSize = ARGS_SIZE_ONE; | 573 | size_t argSize = ARGS_SIZE_ONE; |
| @@ -571,6 +585,7 @@ napi_value GetProfileConnectionStateEx(napi_env env, napi_callback_info info) | |||
| 571 | 585 | ||
| 572 | napi_value SetDevicePairingConfirmation(napi_env env, napi_callback_info info) | 586 | napi_value SetDevicePairingConfirmation(napi_env env, napi_callback_info info) |
| 573 | { | 587 | { |
| 588 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setDevicePairingConfirmation)); | ||
| 574 | HILOGD("enter"); | 589 | HILOGD("enter"); |
| 575 | std::string remoteAddr{}; | 590 | std::string remoteAddr{}; |
| 576 | bool accept = false; | 591 | bool accept = false; |
| @@ -591,6 +606,7 @@ napi_value SetDevicePairingConfirmation(napi_env env, napi_callback_info info) | |||
| 591 | 606 | ||
| 592 | napi_value SetLocalName(napi_env env, napi_callback_info info) | 607 | napi_value SetLocalName(napi_env env, napi_callback_info info) |
| 593 | { | 608 | { |
| 609 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setLocalName)); | ||
| 594 | HILOGD("enter"); | 610 | HILOGD("enter"); |
| 595 | std::string localName = INVALID_NAME; | 611 | std::string localName = INVALID_NAME; |
| 596 | bool checkRet = CheckLocalNameParam(env, info, localName); | 612 | bool checkRet = CheckLocalNameParam(env, info, localName); |
| @@ -604,6 +620,7 @@ napi_value SetLocalName(napi_env env, napi_callback_info info) | |||
| 604 | 620 | ||
| 605 | napi_value SetBluetoothScanMode(napi_env env, napi_callback_info info) | 621 | napi_value SetBluetoothScanMode(napi_env env, napi_callback_info info) |
| 606 | { | 622 | { |
| 623 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(setBluetoothScanMode)); | ||
| 607 | HILOGD("enter"); | 624 | HILOGD("enter"); |
| 608 | int32_t mode = 0; | 625 | int32_t mode = 0; |
| 609 | int32_t duration = 0; | 626 | int32_t duration = 0; |
| @@ -620,6 +637,7 @@ napi_value SetBluetoothScanMode(napi_env env, napi_callback_info info) | |||
| 620 | 637 | ||
| 621 | napi_value GetBluetoothScanMode(napi_env env, napi_callback_info info) | 638 | napi_value GetBluetoothScanMode(napi_env env, napi_callback_info info) |
| 622 | { | 639 | { |
| 640 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getBluetoothScanMode)); | ||
| 623 | HILOGD("enter"); | 641 | HILOGD("enter"); |
| 624 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 642 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 625 | int32_t scanMode = 0; | 643 | int32_t scanMode = 0; |
| @@ -638,7 +656,7 @@ napi_value StartBluetoothDiscovery(napi_env env, napi_callback_info info) | |||
| 638 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 656 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 639 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 657 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 640 | }; | 658 | }; |
| 641 | - NAPI_BT_CONTEXT(env, "connection.StartBluetoothDiscovery", validErrCodes); | 659 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(StartBluetoothDiscovery), validErrCodes); |
| 642 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 660 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 643 | int ret = host->StartBtDiscovery(); | 661 | int ret = host->StartBtDiscovery(); |
| 644 | NAPI_BT_ASSERT_RETURN_FALSE_VERIFY(env, ret == BT_NO_ERROR, ret); | 662 | NAPI_BT_ASSERT_RETURN_FALSE_VERIFY(env, ret == BT_NO_ERROR, ret); |
| @@ -647,6 +665,7 @@ napi_value StartBluetoothDiscovery(napi_env env, napi_callback_info info) | |||
| 647 | 665 | ||
| 648 | napi_value StopBluetoothDiscovery(napi_env env, napi_callback_info info) | 666 | napi_value StopBluetoothDiscovery(napi_env env, napi_callback_info info) |
| 649 | { | 667 | { |
| 668 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(stopBluetoothDiscovery)); | ||
| 650 | HILOGD("enter"); | 669 | HILOGD("enter"); |
| 651 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 670 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 652 | int ret = host->CancelBtDiscovery(); | 671 | int ret = host->CancelBtDiscovery(); |
| @@ -675,6 +694,8 @@ napi_status ParseSetDevicePinCodeParameters(napi_env env, napi_callback_info inf | |||
| 675 | 694 | ||
| 676 | napi_value SetDevicePinCode(napi_env env, napi_callback_info info) | 695 | napi_value SetDevicePinCode(napi_env env, napi_callback_info info) |
| 677 | { | 696 | { |
| 697 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 698 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setDevicePinCode)); | ||
| 678 | HILOGD("enter"); | 699 | HILOGD("enter"); |
| 679 | std::string remoteAddr = ""; | 700 | std::string remoteAddr = ""; |
| 680 | std::string pinCode = ""; | 701 | std::string pinCode = ""; |
| @@ -687,7 +708,7 @@ napi_value SetDevicePinCode(napi_env env, napi_callback_info info) | |||
| 687 | HILOGI("SetDevicePinCode err: %{public}d", err); | 708 | HILOGI("SetDevicePinCode err: %{public}d", err); |
| 688 | return NapiAsyncWorkRet(err); | 709 | return NapiAsyncWorkRet(err); |
| 689 | }; | 710 | }; |
| 690 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 711 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 691 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 712 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 692 | asyncWork->Run(); | 713 | asyncWork->Run(); |
| 693 | return asyncWork->GetRet(); | 714 | return asyncWork->GetRet(); |
| @@ -747,7 +768,7 @@ napi_value PairDeviceAsync(napi_env env, napi_callback_info info) | |||
| 747 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, | 768 | BT_ERR_PERMISSION_FAILED, BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, |
| 748 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR | 769 | BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, BT_ERR_INTERNAL_ERROR |
| 749 | }; | 770 | }; |
| 750 | - NAPI_BT_CONTEXT(env, "connection.PairDeviceAsync", validErrCodes); | 771 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(PairDeviceAsync), validErrCodes); |
| 751 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 772 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 752 | int32_t addressType = AddressType::UNSET_ADDRESS; | 773 | int32_t addressType = AddressType::UNSET_ADDRESS; |
| 753 | auto checkRet = CheckDeviceAsyncParam(env, info, remoteAddr, addressType); | 774 | auto checkRet = CheckDeviceAsyncParam(env, info, remoteAddr, addressType); |
| @@ -853,6 +874,8 @@ napi_value GenerateLocalOobData(napi_env env, napi_callback_info info) | |||
| 853 | 874 | ||
| 854 | napi_value CancelPairedDeviceAsync(napi_env env, napi_callback_info info) | 875 | napi_value CancelPairedDeviceAsync(napi_env env, napi_callback_info info) |
| 855 | { | 876 | { |
| 877 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 878 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(cancelPairedDevice)); | ||
| 856 | HILOGD("enter"); | 879 | HILOGD("enter"); |
| 857 | std::string remoteAddr {}; | 880 | std::string remoteAddr {}; |
| 858 | bool checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); | 881 | bool checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); |
| @@ -865,7 +888,7 @@ napi_value CancelPairedDeviceAsync(napi_env env, napi_callback_info info) | |||
| 865 | HILOGI("err: %{public}d", err); | 888 | HILOGI("err: %{public}d", err); |
| 866 | return NapiAsyncWorkRet(err); | 889 | return NapiAsyncWorkRet(err); |
| 867 | }; | 890 | }; |
| 868 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 891 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 869 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 892 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 870 | asyncWork->Run(); | 893 | asyncWork->Run(); |
| 871 | return asyncWork->GetRet(); | 894 | return asyncWork->GetRet(); |
| @@ -873,6 +896,8 @@ napi_value CancelPairedDeviceAsync(napi_env env, napi_callback_info info) | |||
| 873 | 896 | ||
| 874 | napi_value CancelPairingDevice(napi_env env, napi_callback_info info) | 897 | napi_value CancelPairingDevice(napi_env env, napi_callback_info info) |
| 875 | { | 898 | { |
| 899 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 900 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(cancelPairingDevice)); | ||
| 876 | HILOGD("enter"); | 901 | HILOGD("enter"); |
| 877 | std::string remoteAddr{}; | 902 | std::string remoteAddr{}; |
| 878 | bool checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); | 903 | bool checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); |
| @@ -884,7 +909,7 @@ napi_value CancelPairingDevice(napi_env env, napi_callback_info info) | |||
| 884 | HILOGI("err: %{public}d", err); | 909 | HILOGI("err: %{public}d", err); |
| 885 | return NapiAsyncWorkRet(err); | 910 | return NapiAsyncWorkRet(err); |
| 886 | }; | 911 | }; |
| 887 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 912 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 888 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 913 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 889 | asyncWork->Run(); | 914 | asyncWork->Run(); |
| 890 | return asyncWork->GetRet(); | 915 | return asyncWork->GetRet(); |
| @@ -906,7 +931,7 @@ napi_value PairCredibleDevice(napi_env env, napi_callback_info info) | |||
| 906 | { | 931 | { |
| 907 | HILOGD("enter"); | 932 | HILOGD("enter"); |
| 908 | std::shared_ptr<NapiHaEventUtils> haUtils = | 933 | std::shared_ptr<NapiHaEventUtils> haUtils = |
| 909 | - std::make_shared<NapiHaEventUtils>(env, "connection.PairCredibleDevice"); | 934 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(PairCredibleDevice)); |
| 910 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 935 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 911 | int transport = BT_TRANSPORT_NONE; | 936 | int transport = BT_TRANSPORT_NONE; |
| 912 | auto status = CheckPairCredibleDeviceParam(env, info, remoteAddr, transport); | 937 | auto status = CheckPairCredibleDeviceParam(env, info, remoteAddr, transport); |
| @@ -936,6 +961,8 @@ napi_status CheckGetProfileUuids(napi_env env, napi_callback_info info, std::str | |||
| 936 | 961 | ||
| 937 | napi_value GetLocalProfileUuids(napi_env env, napi_callback_info info) | 962 | napi_value GetLocalProfileUuids(napi_env env, napi_callback_info info) |
| 938 | { | 963 | { |
| 964 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 965 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getLocalProfileUuids)); | ||
| 939 | HILOGD("enter"); | 966 | HILOGD("enter"); |
| 940 | auto func = []() { | 967 | auto func = []() { |
| 941 | std::vector<std::string> uuids{}; | 968 | std::vector<std::string> uuids{}; |
| @@ -944,7 +971,7 @@ napi_value GetLocalProfileUuids(napi_env env, napi_callback_info info) | |||
| 944 | auto object = std::make_shared<NapiNativeUuidsArray>(uuids); | 971 | auto object = std::make_shared<NapiNativeUuidsArray>(uuids); |
| 945 | return NapiAsyncWorkRet(err, object); | 972 | return NapiAsyncWorkRet(err, object); |
| 946 | }; | 973 | }; |
| 947 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 974 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 948 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 975 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 949 | asyncWork->Run(); | 976 | asyncWork->Run(); |
| 950 | return asyncWork->GetRet(); | 977 | return asyncWork->GetRet(); |
| @@ -952,6 +979,8 @@ napi_value GetLocalProfileUuids(napi_env env, napi_callback_info info) | |||
| 952 | 979 | ||
| 953 | napi_value GetRemoteProfileUuids(napi_env env, napi_callback_info info) | 980 | napi_value GetRemoteProfileUuids(napi_env env, napi_callback_info info) |
| 954 | { | 981 | { |
| 982 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 983 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getRemoteProfileUuids)); | ||
| 955 | HILOGD("enter"); | 984 | HILOGD("enter"); |
| 956 | std::string address; | 985 | std::string address; |
| 957 | auto status = CheckGetProfileUuids(env, info, address); | 986 | auto status = CheckGetProfileUuids(env, info, address); |
| @@ -964,7 +993,7 @@ napi_value GetRemoteProfileUuids(napi_env env, napi_callback_info info) | |||
| 964 | auto object = std::make_shared<NapiNativeUuidsArray>(uuids); | 993 | auto object = std::make_shared<NapiNativeUuidsArray>(uuids); |
| 965 | return NapiAsyncWorkRet(err, object); | 994 | return NapiAsyncWorkRet(err, object); |
| 966 | }; | 995 | }; |
| 967 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 996 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 968 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 997 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 969 | asyncWork->Run(); | 998 | asyncWork->Run(); |
| 970 | return asyncWork->GetRet(); | 999 | return asyncWork->GetRet(); |
| @@ -972,6 +1001,7 @@ napi_value GetRemoteProfileUuids(napi_env env, napi_callback_info info) | |||
| 972 | 1001 | ||
| 973 | napi_value IsBluetoothDiscovering(napi_env env, napi_callback_info info) | 1002 | napi_value IsBluetoothDiscovering(napi_env env, napi_callback_info info) |
| 974 | { | 1003 | { |
| 1004 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(isBluetoothDiscovering)); | ||
| 975 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); | 1005 | BluetoothHost *host = &BluetoothHost::GetDefaultHost(); |
| 976 | bool isDiscovering = false; | 1006 | bool isDiscovering = false; |
| 977 | int32_t err = host->IsBtDiscovering(isDiscovering); | 1007 | int32_t err = host->IsBtDiscovering(isDiscovering); |
| @@ -984,6 +1014,7 @@ napi_value IsBluetoothDiscovering(napi_env env, napi_callback_info info) | |||
| 984 | 1014 | ||
| 985 | napi_value GetPairState(napi_env env, napi_callback_info info) | 1015 | napi_value GetPairState(napi_env env, napi_callback_info info) |
| 986 | { | 1016 | { |
| 1017 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getPairState)); | ||
| 987 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1018 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 988 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 1019 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| 989 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet, BT_ERR_INVALID_PARAM); | 1020 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet, BT_ERR_INVALID_PARAM); |
| @@ -1003,7 +1034,7 @@ napi_value ConnectAllowedProfiles(napi_env env, napi_callback_info info) | |||
| 1003 | { | 1034 | { |
| 1004 | HILOGI("enter"); | 1035 | HILOGI("enter"); |
| 1005 | std::shared_ptr<NapiHaEventUtils> haUtils = | 1036 | std::shared_ptr<NapiHaEventUtils> haUtils = |
| 1006 | - std::make_shared<NapiHaEventUtils>(env, "connection.ConnectAllowedProfiles"); | 1037 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(ConnectAllowedProfiles)); |
| 1007 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1038 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1008 | auto checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); | 1039 | auto checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); |
| 1009 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet == napi_ok, BT_ERR_INVALID_PARAM); | 1040 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -1024,7 +1055,7 @@ napi_value DisconnectAllowedProfiles(napi_env env, napi_callback_info info) | |||
| 1024 | { | 1055 | { |
| 1025 | HILOGI("enter"); | 1056 | HILOGI("enter"); |
| 1026 | std::shared_ptr<NapiHaEventUtils> haUtils = | 1057 | std::shared_ptr<NapiHaEventUtils> haUtils = |
| 1027 | - std::make_shared<NapiHaEventUtils>(env, "connection.DisconnectAllowedProfiles"); | 1058 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(DisconnectAllowedProfiles)); |
| 1028 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1059 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1029 | auto checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); | 1060 | auto checkRet = CheckDeviceAsyncParam(env, info, remoteAddr); |
| 1030 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet == napi_ok, BT_ERR_INVALID_PARAM); | 1061 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -1043,6 +1074,7 @@ napi_value DisconnectAllowedProfiles(napi_env env, napi_callback_info info) | |||
| 1043 | 1074 | ||
| 1044 | napi_value GetRemoteProductId(napi_env env, napi_callback_info info) | 1075 | napi_value GetRemoteProductId(napi_env env, napi_callback_info info) |
| 1045 | { | 1076 | { |
| 1077 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getRemoteProductId)); | ||
| 1046 | HILOGD("start"); | 1078 | HILOGD("start"); |
| 1047 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1079 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1048 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 1080 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -1061,6 +1093,7 @@ napi_value GetRemoteProductId(napi_env env, napi_callback_info info) | |||
| 1061 | 1093 | ||
| 1062 | napi_value GetRemoteDeviceTransport(napi_env env, napi_callback_info info) | 1094 | napi_value GetRemoteDeviceTransport(napi_env env, napi_callback_info info) |
| 1063 | { | 1095 | { |
| 1096 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getRemoteDeviceTransport)); | ||
| 1064 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1097 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1065 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 1098 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| 1066 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet, BT_ERR_INVALID_PARAM); | 1099 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet, BT_ERR_INVALID_PARAM); |
| @@ -1094,6 +1127,8 @@ napi_status ParseSetRemoteDeviceNameParameters(napi_env env, napi_callback_info | |||
| 1094 | 1127 | ||
| 1095 | napi_value SetRemoteDeviceName(napi_env env, napi_callback_info info) | 1128 | napi_value SetRemoteDeviceName(napi_env env, napi_callback_info info) |
| 1096 | { | 1129 | { |
| 1130 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1131 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setRemoteDeviceName)); | ||
| 1097 | HILOGD("enter"); | 1132 | HILOGD("enter"); |
| 1098 | std::string remoteAddr = ""; | 1133 | std::string remoteAddr = ""; |
| 1099 | std::string deviceName = ""; | 1134 | std::string deviceName = ""; |
| @@ -1106,7 +1141,7 @@ napi_value SetRemoteDeviceName(napi_env env, napi_callback_info info) | |||
| 1106 | HILOGI("SetDeviceName err: %{public}d", err); | 1141 | HILOGI("SetDeviceName err: %{public}d", err); |
| 1107 | return NapiAsyncWorkRet(err); | 1142 | return NapiAsyncWorkRet(err); |
| 1108 | }; | 1143 | }; |
| 1109 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1144 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1110 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1145 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1111 | asyncWork->Run(); | 1146 | asyncWork->Run(); |
| 1112 | return asyncWork->GetRet(); | 1147 | return asyncWork->GetRet(); |
| @@ -1131,6 +1166,8 @@ napi_status ParseSetRemoteDeviceTypeParameters(napi_env env, napi_callback_info | |||
| 1131 | 1166 | ||
| 1132 | napi_value SetRemoteDeviceType(napi_env env, napi_callback_info info) | 1167 | napi_value SetRemoteDeviceType(napi_env env, napi_callback_info info) |
| 1133 | { | 1168 | { |
| 1169 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1170 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setRemoteDeviceType)); | ||
| 1134 | HILOGD("enter"); | 1171 | HILOGD("enter"); |
| 1135 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1172 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1136 | int32_t deviceType = DeviceType::DEVICE_TYPE_DEFAULT; | 1173 | int32_t deviceType = DeviceType::DEVICE_TYPE_DEFAULT; |
| @@ -1143,7 +1180,7 @@ napi_value SetRemoteDeviceType(napi_env env, napi_callback_info info) | |||
| 1143 | HILOGI("SetRemoteDeviceType err: %{public}d", err); | 1180 | HILOGI("SetRemoteDeviceType err: %{public}d", err); |
| 1144 | return NapiAsyncWorkRet(err); | 1181 | return NapiAsyncWorkRet(err); |
| 1145 | }; | 1182 | }; |
| 1146 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1183 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1147 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1184 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1148 | asyncWork->Run(); | 1185 | asyncWork->Run(); |
| 1149 | return asyncWork->GetRet(); | 1186 | return asyncWork->GetRet(); |
| @@ -1151,6 +1188,8 @@ napi_value SetRemoteDeviceType(napi_env env, napi_callback_info info) | |||
| 1151 | 1188 | ||
| 1152 | napi_value GetRemoteDeviceType(napi_env env, napi_callback_info info) | 1189 | napi_value GetRemoteDeviceType(napi_env env, napi_callback_info info) |
| 1153 | { | 1190 | { |
| 1191 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1192 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getRemoteDeviceType)); | ||
| 1154 | HILOGD("enter"); | 1193 | HILOGD("enter"); |
| 1155 | std::string remoteAddr; | 1194 | std::string remoteAddr; |
| 1156 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 1195 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -1163,7 +1202,7 @@ napi_value GetRemoteDeviceType(napi_env env, napi_callback_info info) | |||
| 1163 | auto object = std::make_shared<NapiNativeInt>(deviceType); | 1202 | auto object = std::make_shared<NapiNativeInt>(deviceType); |
| 1164 | return NapiAsyncWorkRet(err, object); | 1203 | return NapiAsyncWorkRet(err, object); |
| 1165 | }; | 1204 | }; |
| 1166 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1205 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1167 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1206 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1168 | asyncWork->Run(); | 1207 | asyncWork->Run(); |
| 1169 | return asyncWork->GetRet(); | 1208 | return asyncWork->GetRet(); |
| @@ -1171,6 +1210,8 @@ napi_value GetRemoteDeviceType(napi_env env, napi_callback_info info) | |||
| 1171 | 1210 | ||
| 1172 | napi_value GetRemoteDeviceBatteryInfo(napi_env env, napi_callback_info info) | 1211 | napi_value GetRemoteDeviceBatteryInfo(napi_env env, napi_callback_info info) |
| 1173 | { | 1212 | { |
| 1213 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1214 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getRemoteDeviceBatteryInfo)); | ||
| 1174 | HILOGD("enter"); | 1215 | HILOGD("enter"); |
| 1175 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1216 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1176 | auto checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 1217 | auto checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -1183,7 +1224,7 @@ napi_value GetRemoteDeviceBatteryInfo(napi_env env, napi_callback_info info) | |||
| 1183 | auto object = std::make_shared<NapiNativeBatteryInfo>(batteryInfo); | 1224 | auto object = std::make_shared<NapiNativeBatteryInfo>(batteryInfo); |
| 1184 | return NapiAsyncWorkRet(err, object); | 1225 | return NapiAsyncWorkRet(err, object); |
| 1185 | }; | 1226 | }; |
| 1186 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1227 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1187 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1228 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1188 | asyncWork->Run(); | 1229 | asyncWork->Run(); |
| 1189 | return asyncWork->GetRet(); | 1230 | return asyncWork->GetRet(); |
| @@ -1461,6 +1502,8 @@ napi_status ParseControlDeviceActionParams(napi_env env, napi_value object, Cont | |||
| 1461 | 1502 | ||
| 1462 | napi_value ControlDeviceAction(napi_env env, napi_callback_info info) | 1503 | napi_value ControlDeviceAction(napi_env env, napi_callback_info info) |
| 1463 | { | 1504 | { |
| 1505 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1506 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(controlDeviceAction)); | ||
| 1464 | HILOGD("ControlDeviceAction enter"); | 1507 | HILOGD("ControlDeviceAction enter"); |
| 1465 | size_t argc = ARGS_SIZE_ONE; | 1508 | size_t argc = ARGS_SIZE_ONE; |
| 1466 | napi_value argv[ARGS_SIZE_ONE] = {nullptr}; | 1509 | napi_value argv[ARGS_SIZE_ONE] = {nullptr}; |
| @@ -1484,7 +1527,7 @@ napi_value ControlDeviceAction(napi_env env, napi_callback_info info) | |||
| 1484 | HILOGI("ControlDeviceAction err: %{public}d", err); | 1527 | HILOGI("ControlDeviceAction err: %{public}d", err); |
| 1485 | return NapiAsyncWorkRet(err); | 1528 | return NapiAsyncWorkRet(err); |
| 1486 | }; | 1529 | }; |
| 1487 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1530 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1488 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1531 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1489 | asyncWork->Run(); | 1532 | asyncWork->Run(); |
| 1490 | return asyncWork->GetRet(); | 1533 | return asyncWork->GetRet(); |
| @@ -1492,6 +1535,8 @@ napi_value ControlDeviceAction(napi_env env, napi_callback_info info) | |||
| 1492 | 1535 | ||
| 1493 | napi_value GetRemoteDeviceConnectionTime(napi_env env, napi_callback_info info) | 1536 | napi_value GetRemoteDeviceConnectionTime(napi_env env, napi_callback_info info) |
| 1494 | { | 1537 | { |
| 1538 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1539 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getLastConnectionTime)); | ||
| 1495 | HILOGD("enter"); | 1540 | HILOGD("enter"); |
| 1496 | std::string remoteAddr = INVALID_MAC_ADDRESS; | 1541 | std::string remoteAddr = INVALID_MAC_ADDRESS; |
| 1497 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 1542 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -1504,7 +1549,7 @@ napi_value GetRemoteDeviceConnectionTime(napi_env env, napi_callback_info info) | |||
| 1504 | auto object = std::make_shared<NapiNativeInt64>(connectionTime); | 1549 | auto object = std::make_shared<NapiNativeInt64>(connectionTime); |
| 1505 | return NapiAsyncWorkRet(err, object); | 1550 | return NapiAsyncWorkRet(err, object); |
| 1506 | }; | 1551 | }; |
| 1507 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1552 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1508 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1553 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1509 | asyncWork->Run(); | 1554 | asyncWork->Run(); |
| 1510 | return asyncWork->GetRet(); | 1555 | return asyncWork->GetRet(); |
| @@ -1512,6 +1557,8 @@ napi_value GetRemoteDeviceConnectionTime(napi_env env, napi_callback_info info) | |||
| 1512 | 1557 | ||
| 1513 | napi_value UpdateCloudBluetoothDevice(napi_env env, napi_callback_info info) | 1558 | napi_value UpdateCloudBluetoothDevice(napi_env env, napi_callback_info info) |
| 1514 | { | 1559 | { |
| 1560 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 1561 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(updateCloudBluetoothDevice)); | ||
| 1515 | HILOGI("[CLOUD_DEV] UpdateCloudBluetoothDevice enter"); | 1562 | HILOGI("[CLOUD_DEV] UpdateCloudBluetoothDevice enter"); |
| 1516 | size_t argc = ARGS_SIZE_ONE; | 1563 | size_t argc = ARGS_SIZE_ONE; |
| 1517 | napi_value argv[ARGS_SIZE_ONE] = {nullptr}; | 1564 | napi_value argv[ARGS_SIZE_ONE] = {nullptr}; |
| @@ -1526,7 +1573,7 @@ napi_value UpdateCloudBluetoothDevice(napi_env env, napi_callback_info info) | |||
| 1526 | HILOGI("[CLOUD_DEV] UpdateCloudBluetoothDevice err: %{public}d", err); | 1573 | HILOGI("[CLOUD_DEV] UpdateCloudBluetoothDevice err: %{public}d", err); |
| 1527 | return NapiAsyncWorkRet(err); | 1574 | return NapiAsyncWorkRet(err); |
| 1528 | }; | 1575 | }; |
| 1529 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 1576 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 1530 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 1577 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 1531 | asyncWork->Run(); | 1578 | asyncWork->Run(); |
| 1532 | return asyncWork->GetRet(); | 1579 | return asyncWork->GetRet(); |
| @@ -85,6 +85,7 @@ napi_value NapiHandsFreeAudioGateway::DefineCreateProfile(napi_env env, napi_val | |||
| 85 | 85 | ||
| 86 | napi_value NapiHandsFreeAudioGateway::CreateHfpAgProfile(napi_env env, napi_callback_info info) | 86 | napi_value NapiHandsFreeAudioGateway::CreateHfpAgProfile(napi_env env, napi_callback_info info) |
| 87 | { | 87 | { |
| 88 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createHfpAgProfile)); | ||
| 88 | HILOGI("enter"); | 89 | HILOGI("enter"); |
| 89 | napi_value napiProfile; | 90 | napi_value napiProfile; |
| 90 | napi_value constructor = nullptr; | 91 | napi_value constructor = nullptr; |
| @@ -103,8 +104,10 @@ napi_value NapiHandsFreeAudioGateway::HandsFreeAudioGatewayConstructor(napi_env | |||
| 103 | 104 | ||
| 104 | napi_value NapiHandsFreeAudioGateway::On(napi_env env, napi_callback_info info) | 105 | napi_value NapiHandsFreeAudioGateway::On(napi_env env, napi_callback_info info) |
| 105 | { | 106 | { |
| 107 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 108 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 106 | if (observer_) { | 109 | if (observer_) { |
| 107 | - auto status = observer_->eventSubscribe_.Register(env, info); | 110 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 108 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 111 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 109 | } | 112 | } |
| 110 | if (!isRegistered_) { | 113 | if (!isRegistered_) { |
| @@ -117,8 +120,10 @@ napi_value NapiHandsFreeAudioGateway::On(napi_env env, napi_callback_info info) | |||
| 117 | 120 | ||
| 118 | napi_value NapiHandsFreeAudioGateway::Off(napi_env env, napi_callback_info info) | 121 | napi_value NapiHandsFreeAudioGateway::Off(napi_env env, napi_callback_info info) |
| 119 | { | 122 | { |
| 123 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 124 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 120 | if (observer_) { | 125 | if (observer_) { |
| 121 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 126 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 122 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 127 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 123 | } | 128 | } |
| 124 | return NapiGetUndefinedRet(env); | 129 | return NapiGetUndefinedRet(env); |
| @@ -126,6 +131,7 @@ napi_value NapiHandsFreeAudioGateway::Off(napi_env env, napi_callback_info info) | |||
| 126 | 131 | ||
| 127 | napi_value NapiHandsFreeAudioGateway::GetConnectionDevices(napi_env env, napi_callback_info info) | 132 | napi_value NapiHandsFreeAudioGateway::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 128 | { | 133 | { |
| 134 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 129 | HILOGI("enter"); | 135 | HILOGI("enter"); |
| 130 | napi_value ret = nullptr; | 136 | napi_value ret = nullptr; |
| 131 | if (napi_create_array(env, &ret) != napi_ok) { | 137 | if (napi_create_array(env, &ret) != napi_ok) { |
| @@ -150,6 +156,7 @@ napi_value NapiHandsFreeAudioGateway::GetConnectionDevices(napi_env env, napi_ca | |||
| 150 | 156 | ||
| 151 | napi_value NapiHandsFreeAudioGateway::GetDeviceState(napi_env env, napi_callback_info info) | 157 | napi_value NapiHandsFreeAudioGateway::GetDeviceState(napi_env env, napi_callback_info info) |
| 152 | { | 158 | { |
| 159 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 153 | HILOGD("enter"); | 160 | HILOGD("enter"); |
| 154 | napi_value result = nullptr; | 161 | napi_value result = nullptr; |
| 155 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; | 162 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; |
| @@ -176,6 +183,7 @@ napi_value NapiHandsFreeAudioGateway::GetDeviceState(napi_env env, napi_callback | |||
| 176 | 183 | ||
| 177 | napi_value NapiHandsFreeAudioGateway::GetScoState(napi_env env, napi_callback_info info) | 184 | napi_value NapiHandsFreeAudioGateway::GetScoState(napi_env env, napi_callback_info info) |
| 178 | { | 185 | { |
| 186 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getScoState)); | ||
| 179 | HILOGI("enter"); | 187 | HILOGI("enter"); |
| 180 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 188 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 181 | size_t argc = expectedArgsCount; | 189 | size_t argc = expectedArgsCount; |
| @@ -208,6 +216,7 @@ napi_value NapiHandsFreeAudioGateway::GetScoState(napi_env env, napi_callback_in | |||
| 208 | 216 | ||
| 209 | napi_value NapiHandsFreeAudioGateway::ConnectSco(napi_env env, napi_callback_info info) | 217 | napi_value NapiHandsFreeAudioGateway::ConnectSco(napi_env env, napi_callback_info info) |
| 210 | { | 218 | { |
| 219 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connectSco)); | ||
| 211 | HILOGI("enter"); | 220 | HILOGI("enter"); |
| 212 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 221 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 213 | size_t argc = expectedArgsCount; | 222 | size_t argc = expectedArgsCount; |
| @@ -242,6 +251,7 @@ napi_value NapiHandsFreeAudioGateway::ConnectSco(napi_env env, napi_callback_inf | |||
| 242 | 251 | ||
| 243 | napi_value NapiHandsFreeAudioGateway::DisconnectSco(napi_env env, napi_callback_info info) | 252 | napi_value NapiHandsFreeAudioGateway::DisconnectSco(napi_env env, napi_callback_info info) |
| 244 | { | 253 | { |
| 254 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnectSco)); | ||
| 245 | HILOGI("enter"); | 255 | HILOGI("enter"); |
| 246 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 256 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 247 | size_t argc = expectedArgsCount; | 257 | size_t argc = expectedArgsCount; |
| @@ -276,6 +286,7 @@ napi_value NapiHandsFreeAudioGateway::DisconnectSco(napi_env env, napi_callback_ | |||
| 276 | 286 | ||
| 277 | napi_value NapiHandsFreeAudioGateway::OpenVoiceRecognition(napi_env env, napi_callback_info info) | 287 | napi_value NapiHandsFreeAudioGateway::OpenVoiceRecognition(napi_env env, napi_callback_info info) |
| 278 | { | 288 | { |
| 289 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(openVoiceRecognition)); | ||
| 279 | HILOGI("enter"); | 290 | HILOGI("enter"); |
| 280 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 291 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 281 | size_t argc = expectedArgsCount; | 292 | size_t argc = expectedArgsCount; |
| @@ -307,6 +318,7 @@ napi_value NapiHandsFreeAudioGateway::OpenVoiceRecognition(napi_env env, napi_ca | |||
| 307 | 318 | ||
| 308 | napi_value NapiHandsFreeAudioGateway::CloseVoiceRecognition(napi_env env, napi_callback_info info) | 319 | napi_value NapiHandsFreeAudioGateway::CloseVoiceRecognition(napi_env env, napi_callback_info info) |
| 309 | { | 320 | { |
| 321 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(closeVoiceRecognition)); | ||
| 310 | HILOGI("enter"); | 322 | HILOGI("enter"); |
| 311 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 323 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 312 | size_t argc = expectedArgsCount; | 324 | size_t argc = expectedArgsCount; |
| @@ -338,6 +350,7 @@ napi_value NapiHandsFreeAudioGateway::CloseVoiceRecognition(napi_env env, napi_c | |||
| 338 | 350 | ||
| 339 | napi_value NapiHandsFreeAudioGateway::Connect(napi_env env, napi_callback_info info) | 351 | napi_value NapiHandsFreeAudioGateway::Connect(napi_env env, napi_callback_info info) |
| 340 | { | 352 | { |
| 353 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 341 | HILOGI("enter"); | 354 | HILOGI("enter"); |
| 342 | std::string remoteAddr {}; | 355 | std::string remoteAddr {}; |
| 343 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 356 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -353,6 +366,7 @@ napi_value NapiHandsFreeAudioGateway::Connect(napi_env env, napi_callback_info i | |||
| 353 | 366 | ||
| 354 | napi_value NapiHandsFreeAudioGateway::Disconnect(napi_env env, napi_callback_info info) | 367 | napi_value NapiHandsFreeAudioGateway::Disconnect(napi_env env, napi_callback_info info) |
| 355 | { | 368 | { |
| 369 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 356 | HILOGI("enter"); | 370 | HILOGI("enter"); |
| 357 | std::string remoteAddr {}; | 371 | std::string remoteAddr {}; |
| 358 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 372 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -368,6 +382,8 @@ napi_value NapiHandsFreeAudioGateway::Disconnect(napi_env env, napi_callback_inf | |||
| 368 | 382 | ||
| 369 | napi_value NapiHandsFreeAudioGateway::SetConnectionStrategy(napi_env env, napi_callback_info info) | 383 | napi_value NapiHandsFreeAudioGateway::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 370 | { | 384 | { |
| 385 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 386 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 371 | HILOGD("start"); | 387 | HILOGD("start"); |
| 372 | std::string remoteAddr {}; | 388 | std::string remoteAddr {}; |
| 373 | int32_t strategy = 0; | 389 | int32_t strategy = 0; |
| @@ -381,7 +397,7 @@ napi_value NapiHandsFreeAudioGateway::SetConnectionStrategy(napi_env env, napi_c | |||
| 381 | HILOGI("err: %{public}d", err); | 397 | HILOGI("err: %{public}d", err); |
| 382 | return NapiAsyncWorkRet(err); | 398 | return NapiAsyncWorkRet(err); |
| 383 | }; | 399 | }; |
| 384 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 400 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 385 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 401 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 386 | asyncWork->Run(); | 402 | asyncWork->Run(); |
| 387 | return asyncWork->GetRet(); | 403 | return asyncWork->GetRet(); |
| @@ -389,6 +405,8 @@ napi_value NapiHandsFreeAudioGateway::SetConnectionStrategy(napi_env env, napi_c | |||
| 389 | 405 | ||
| 390 | napi_value NapiHandsFreeAudioGateway::GetConnectionStrategy(napi_env env, napi_callback_info info) | 406 | napi_value NapiHandsFreeAudioGateway::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 391 | { | 407 | { |
| 408 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 409 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 392 | HILOGD("start"); | 410 | HILOGD("start"); |
| 393 | std::string remoteAddr {}; | 411 | std::string remoteAddr {}; |
| 394 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 412 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -403,7 +421,7 @@ napi_value NapiHandsFreeAudioGateway::GetConnectionStrategy(napi_env env, napi_c | |||
| 403 | auto object = std::make_shared<NapiNativeInt>(strategy); | 421 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 404 | return NapiAsyncWorkRet(err, object); | 422 | return NapiAsyncWorkRet(err, object); |
| 405 | }; | 423 | }; |
| 406 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 424 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 407 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 425 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 408 | asyncWork->Run(); | 426 | asyncWork->Run(); |
| 409 | return asyncWork->GetRet(); | 427 | return asyncWork->GetRet(); |
| @@ -65,8 +65,10 @@ napi_value NapiHandsFreeUnit::HandsFreeUnitConstructor(napi_env env, napi_callba | |||
| 65 | 65 | ||
| 66 | napi_value NapiHandsFreeUnit::On(napi_env env, napi_callback_info info) | 66 | napi_value NapiHandsFreeUnit::On(napi_env env, napi_callback_info info) |
| 67 | { | 67 | { |
| 68 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 69 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 68 | if (observer_) { | 70 | if (observer_) { |
| 69 | - auto status = observer_->eventSubscribe_.Register(env, info); | 71 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 70 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 72 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 71 | } | 73 | } |
| 72 | if (!isRegistered_) { | 74 | if (!isRegistered_) { |
| @@ -79,8 +81,10 @@ napi_value NapiHandsFreeUnit::On(napi_env env, napi_callback_info info) | |||
| 79 | 81 | ||
| 80 | napi_value NapiHandsFreeUnit::Off(napi_env env, napi_callback_info info) | 82 | napi_value NapiHandsFreeUnit::Off(napi_env env, napi_callback_info info) |
| 81 | { | 83 | { |
| 84 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 85 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 82 | if (observer_) { | 86 | if (observer_) { |
| 83 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 87 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 84 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 88 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 85 | } | 89 | } |
| 86 | return NapiGetUndefinedRet(env); | 90 | return NapiGetUndefinedRet(env); |
| @@ -88,6 +92,7 @@ napi_value NapiHandsFreeUnit::Off(napi_env env, napi_callback_info info) | |||
| 88 | 92 | ||
| 89 | napi_value NapiHandsFreeUnit::GetConnectionDevices(napi_env env, napi_callback_info info) | 93 | napi_value NapiHandsFreeUnit::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 90 | { | 94 | { |
| 95 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 91 | HILOGI("enter"); | 96 | HILOGI("enter"); |
| 92 | napi_value ret = nullptr; | 97 | napi_value ret = nullptr; |
| 93 | napi_create_array(env, &ret); | 98 | napi_create_array(env, &ret); |
| @@ -104,6 +109,7 @@ napi_value NapiHandsFreeUnit::GetConnectionDevices(napi_env env, napi_callback_i | |||
| 104 | 109 | ||
| 105 | napi_value NapiHandsFreeUnit::GetDeviceState(napi_env env, napi_callback_info info) | 110 | napi_value NapiHandsFreeUnit::GetDeviceState(napi_env env, napi_callback_info info) |
| 106 | { | 111 | { |
| 112 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 107 | HILOGI("enter"); | 113 | HILOGI("enter"); |
| 108 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 114 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 109 | size_t argc = expectedArgsCount; | 115 | size_t argc = expectedArgsCount; |
| @@ -136,6 +142,7 @@ napi_value NapiHandsFreeUnit::GetDeviceState(napi_env env, napi_callback_info in | |||
| 136 | 142 | ||
| 137 | napi_value NapiHandsFreeUnit::GetScoState(napi_env env, napi_callback_info info) | 143 | napi_value NapiHandsFreeUnit::GetScoState(napi_env env, napi_callback_info info) |
| 138 | { | 144 | { |
| 145 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getScoState)); | ||
| 139 | HILOGI("enter"); | 146 | HILOGI("enter"); |
| 140 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 147 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 141 | size_t argc = expectedArgsCount; | 148 | size_t argc = expectedArgsCount; |
| @@ -168,6 +175,7 @@ napi_value NapiHandsFreeUnit::GetScoState(napi_env env, napi_callback_info info) | |||
| 168 | 175 | ||
| 169 | napi_value NapiHandsFreeUnit::Connect(napi_env env, napi_callback_info info) | 176 | napi_value NapiHandsFreeUnit::Connect(napi_env env, napi_callback_info info) |
| 170 | { | 177 | { |
| 178 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 171 | HILOGI("enter"); | 179 | HILOGI("enter"); |
| 172 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 180 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 173 | size_t argc = expectedArgsCount; | 181 | size_t argc = expectedArgsCount; |
| @@ -199,6 +207,7 @@ napi_value NapiHandsFreeUnit::Connect(napi_env env, napi_callback_info info) | |||
| 199 | 207 | ||
| 200 | napi_value NapiHandsFreeUnit::Disconnect(napi_env env, napi_callback_info info) | 208 | napi_value NapiHandsFreeUnit::Disconnect(napi_env env, napi_callback_info info) |
| 201 | { | 209 | { |
| 210 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 202 | HILOGI("enter"); | 211 | HILOGI("enter"); |
| 203 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 212 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 204 | size_t argc = expectedArgsCount; | 213 | size_t argc = expectedArgsCount; |
| @@ -230,6 +239,7 @@ napi_value NapiHandsFreeUnit::Disconnect(napi_env env, napi_callback_info info) | |||
| 230 | 239 | ||
| 231 | napi_value NapiHandsFreeUnit::ConnectSco(napi_env env, napi_callback_info info) | 240 | napi_value NapiHandsFreeUnit::ConnectSco(napi_env env, napi_callback_info info) |
| 232 | { | 241 | { |
| 242 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connectSco)); | ||
| 233 | HILOGI("enter"); | 243 | HILOGI("enter"); |
| 234 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 244 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 235 | size_t argc = expectedArgsCount; | 245 | size_t argc = expectedArgsCount; |
| @@ -261,6 +271,7 @@ napi_value NapiHandsFreeUnit::ConnectSco(napi_env env, napi_callback_info info) | |||
| 261 | 271 | ||
| 262 | napi_value NapiHandsFreeUnit::DisconnectSco(napi_env env, napi_callback_info info) | 272 | napi_value NapiHandsFreeUnit::DisconnectSco(napi_env env, napi_callback_info info) |
| 263 | { | 273 | { |
| 274 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnectSco)); | ||
| 264 | HILOGI("enter"); | 275 | HILOGI("enter"); |
| 265 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 276 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 266 | size_t argc = expectedArgsCount; | 277 | size_t argc = expectedArgsCount; |
| @@ -292,6 +303,7 @@ napi_value NapiHandsFreeUnit::DisconnectSco(napi_env env, napi_callback_info inf | |||
| 292 | 303 | ||
| 293 | napi_value NapiHandsFreeUnit::SendDTMF(napi_env env, napi_callback_info info) | 304 | napi_value NapiHandsFreeUnit::SendDTMF(napi_env env, napi_callback_info info) |
| 294 | { | 305 | { |
| 306 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(sendDTMF)); | ||
| 295 | HILOGI("enter"); | 307 | HILOGI("enter"); |
| 296 | size_t expectedArgsCount = ARGS_SIZE_TWO; | 308 | size_t expectedArgsCount = ARGS_SIZE_TWO; |
| 297 | size_t argc = expectedArgsCount; | 309 | size_t argc = expectedArgsCount; |
| @@ -30,6 +30,7 @@ | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | + | ||
| 33 | 34 | ||
| 34 | namespace OHOS { | 35 | namespace OHOS { |
| 35 | namespace Bluetooth { | 36 | namespace Bluetooth { |
| @@ -167,6 +168,7 @@ napi_value NapiBluetoothHidDevice::DefineCreateProfile(napi_env env, napi_value | |||
| 167 | 168 | ||
| 168 | napi_value NapiBluetoothHidDevice::CreateHidDeviceProfile(napi_env env, napi_callback_info info) | 169 | napi_value NapiBluetoothHidDevice::CreateHidDeviceProfile(napi_env env, napi_callback_info info) |
| 169 | { | 170 | { |
| 171 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createHidDeviceProfile)); | ||
| 170 | HILOGI("enter"); | 172 | HILOGI("enter"); |
| 171 | napi_value napiProfile; | 173 | napi_value napiProfile; |
| 172 | napi_value constructor = nullptr; | 174 | napi_value constructor = nullptr; |
| @@ -188,8 +190,10 @@ napi_value NapiBluetoothHidDevice::HidDeviceConstructor(napi_env env, napi_callb | |||
| 188 | 190 | ||
| 189 | napi_value NapiBluetoothHidDevice::On(napi_env env, napi_callback_info info) | 191 | napi_value NapiBluetoothHidDevice::On(napi_env env, napi_callback_info info) |
| 190 | { | 192 | { |
| 193 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 194 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 191 | if (observer_) { | 195 | if (observer_) { |
| 192 | - auto status = observer_->eventSubscribe_.Register(env, info); | 196 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 193 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 197 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 194 | } | 198 | } |
| 195 | return NapiGetUndefinedRet(env); | 199 | return NapiGetUndefinedRet(env); |
| @@ -197,8 +201,10 @@ napi_value NapiBluetoothHidDevice::On(napi_env env, napi_callback_info info) | |||
| 197 | 201 | ||
| 198 | napi_value NapiBluetoothHidDevice::Off(napi_env env, napi_callback_info info) | 202 | napi_value NapiBluetoothHidDevice::Off(napi_env env, napi_callback_info info) |
| 199 | { | 203 | { |
| 204 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 205 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 200 | if (observer_) { | 206 | if (observer_) { |
| 201 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 207 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 202 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 208 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 203 | } | 209 | } |
| 204 | return NapiGetUndefinedRet(env); | 210 | return NapiGetUndefinedRet(env); |
| @@ -206,6 +212,7 @@ napi_value NapiBluetoothHidDevice::Off(napi_env env, napi_callback_info info) | |||
| 206 | 212 | ||
| 207 | napi_value NapiBluetoothHidDevice::OnGetReport(napi_env env, napi_callback_info info) | 213 | napi_value NapiBluetoothHidDevice::OnGetReport(napi_env env, napi_callback_info info) |
| 208 | { | 214 | { |
| 215 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onGetReport)); | ||
| 209 | if (observer_) { | 216 | if (observer_) { |
| 210 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 217 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| 211 | STR_BT_HID_DEVICE_OBSERVER_APP_GET_REPORT); | 218 | STR_BT_HID_DEVICE_OBSERVER_APP_GET_REPORT); |
| @@ -216,6 +223,7 @@ napi_value NapiBluetoothHidDevice::OnGetReport(napi_env env, napi_callback_info | |||
| 216 | 223 | ||
| 217 | napi_value NapiBluetoothHidDevice::OnSetReport(napi_env env, napi_callback_info info) | 224 | napi_value NapiBluetoothHidDevice::OnSetReport(napi_env env, napi_callback_info info) |
| 218 | { | 225 | { |
| 226 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onSetReport)); | ||
| 219 | if (observer_) { | 227 | if (observer_) { |
| 220 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 228 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| 221 | STR_BT_HID_DEVICE_OBSERVER_APP_SET_REPORT); | 229 | STR_BT_HID_DEVICE_OBSERVER_APP_SET_REPORT); |
| @@ -226,6 +234,7 @@ napi_value NapiBluetoothHidDevice::OnSetReport(napi_env env, napi_callback_info | |||
| 226 | 234 | ||
| 227 | napi_value NapiBluetoothHidDevice::OnInterruptDataReceived(napi_env env, napi_callback_info info) | 235 | napi_value NapiBluetoothHidDevice::OnInterruptDataReceived(napi_env env, napi_callback_info info) |
| 228 | { | 236 | { |
| 237 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onInterruptDataReceived)); | ||
| 229 | if (observer_) { | 238 | if (observer_) { |
| 230 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 239 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| 231 | STR_BT_HID_DEVICE_OBSERVER_INTERRUPT_DATA_RECEIVED); | 240 | STR_BT_HID_DEVICE_OBSERVER_INTERRUPT_DATA_RECEIVED); |
| @@ -236,6 +245,7 @@ napi_value NapiBluetoothHidDevice::OnInterruptDataReceived(napi_env env, napi_ca | |||
| 236 | 245 | ||
| 237 | napi_value NapiBluetoothHidDevice::OnSetProtocol(napi_env env, napi_callback_info info) | 246 | napi_value NapiBluetoothHidDevice::OnSetProtocol(napi_env env, napi_callback_info info) |
| 238 | { | 247 | { |
| 248 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onSetProtocol)); | ||
| 239 | if (observer_) { | 249 | if (observer_) { |
| 240 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 250 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| 241 | STR_BT_HID_DEVICE_OBSERVER_SET_PROTOCOL); | 251 | STR_BT_HID_DEVICE_OBSERVER_SET_PROTOCOL); |
| @@ -246,6 +256,7 @@ napi_value NapiBluetoothHidDevice::OnSetProtocol(napi_env env, napi_callback_inf | |||
| 246 | 256 | ||
| 247 | napi_value NapiBluetoothHidDevice::OnVirtualCableUnplug(napi_env env, napi_callback_info info) | 257 | napi_value NapiBluetoothHidDevice::OnVirtualCableUnplug(napi_env env, napi_callback_info info) |
| 248 | { | 258 | { |
| 259 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onVirtualCableUnplug)); | ||
| 249 | if (observer_) { | 260 | if (observer_) { |
| 250 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 261 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| 251 | STR_BT_HID_DEVICE_OBSERVER_VIRTUAL_CABLE_UNPLUG); | 262 | STR_BT_HID_DEVICE_OBSERVER_VIRTUAL_CABLE_UNPLUG); |
| @@ -256,6 +267,7 @@ napi_value NapiBluetoothHidDevice::OnVirtualCableUnplug(napi_env env, napi_callb | |||
| 256 | 267 | ||
| 257 | napi_value NapiBluetoothHidDevice::OnConnectionStateChange(napi_env env, napi_callback_info info) | 268 | napi_value NapiBluetoothHidDevice::OnConnectionStateChange(napi_env env, napi_callback_info info) |
| 258 | { | 269 | { |
| 270 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onConnectionStateChange)); | ||
| 259 | if (observer_) { | 271 | if (observer_) { |
| 260 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 272 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| 261 | STR_BT_HID_DEVICE_CONNECT_STATE_CHANGE); | 273 | STR_BT_HID_DEVICE_CONNECT_STATE_CHANGE); |
| @@ -266,6 +278,7 @@ napi_value NapiBluetoothHidDevice::OnConnectionStateChange(napi_env env, napi_ca | |||
| 266 | 278 | ||
| 267 | napi_value NapiBluetoothHidDevice::OffGetReport(napi_env env, napi_callback_info info) | 279 | napi_value NapiBluetoothHidDevice::OffGetReport(napi_env env, napi_callback_info info) |
| 268 | { | 280 | { |
| 281 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offGetReport)); | ||
| 269 | if (observer_) { | 282 | if (observer_) { |
| 270 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 283 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| 271 | STR_BT_HID_DEVICE_OBSERVER_APP_GET_REPORT); | 284 | STR_BT_HID_DEVICE_OBSERVER_APP_GET_REPORT); |
| @@ -276,6 +289,7 @@ napi_value NapiBluetoothHidDevice::OffGetReport(napi_env env, napi_callback_info | |||
| 276 | 289 | ||
| 277 | napi_value NapiBluetoothHidDevice::OffSetReport(napi_env env, napi_callback_info info) | 290 | napi_value NapiBluetoothHidDevice::OffSetReport(napi_env env, napi_callback_info info) |
| 278 | { | 291 | { |
| 292 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offSetReport)); | ||
| 279 | if (observer_) { | 293 | if (observer_) { |
| 280 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 294 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| 281 | STR_BT_HID_DEVICE_OBSERVER_APP_SET_REPORT); | 295 | STR_BT_HID_DEVICE_OBSERVER_APP_SET_REPORT); |
| @@ -286,6 +300,7 @@ napi_value NapiBluetoothHidDevice::OffSetReport(napi_env env, napi_callback_info | |||
| 286 | 300 | ||
| 287 | napi_value NapiBluetoothHidDevice::OffInterruptDataReceived(napi_env env, napi_callback_info info) | 301 | napi_value NapiBluetoothHidDevice::OffInterruptDataReceived(napi_env env, napi_callback_info info) |
| 288 | { | 302 | { |
| 303 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offInterruptDataReceived)); | ||
| 289 | if (observer_) { | 304 | if (observer_) { |
| 290 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 305 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| 291 | STR_BT_HID_DEVICE_OBSERVER_INTERRUPT_DATA_RECEIVED); | 306 | STR_BT_HID_DEVICE_OBSERVER_INTERRUPT_DATA_RECEIVED); |
| @@ -296,6 +311,7 @@ napi_value NapiBluetoothHidDevice::OffInterruptDataReceived(napi_env env, napi_c | |||
| 296 | 311 | ||
| 297 | napi_value NapiBluetoothHidDevice::OffSetProtocol(napi_env env, napi_callback_info info) | 312 | napi_value NapiBluetoothHidDevice::OffSetProtocol(napi_env env, napi_callback_info info) |
| 298 | { | 313 | { |
| 314 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offSetProtocol)); | ||
| 299 | if (observer_) { | 315 | if (observer_) { |
| 300 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 316 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| 301 | STR_BT_HID_DEVICE_OBSERVER_SET_PROTOCOL); | 317 | STR_BT_HID_DEVICE_OBSERVER_SET_PROTOCOL); |
| @@ -306,6 +322,7 @@ napi_value NapiBluetoothHidDevice::OffSetProtocol(napi_env env, napi_callback_in | |||
| 306 | 322 | ||
| 307 | napi_value NapiBluetoothHidDevice::OffVirtualCableUnplug(napi_env env, napi_callback_info info) | 323 | napi_value NapiBluetoothHidDevice::OffVirtualCableUnplug(napi_env env, napi_callback_info info) |
| 308 | { | 324 | { |
| 325 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offVirtualCableUnplug)); | ||
| 309 | if (observer_) { | 326 | if (observer_) { |
| 310 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 327 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| 311 | STR_BT_HID_DEVICE_OBSERVER_VIRTUAL_CABLE_UNPLUG); | 328 | STR_BT_HID_DEVICE_OBSERVER_VIRTUAL_CABLE_UNPLUG); |
| @@ -316,6 +333,7 @@ napi_value NapiBluetoothHidDevice::OffVirtualCableUnplug(napi_env env, napi_call | |||
| 316 | 333 | ||
| 317 | napi_value NapiBluetoothHidDevice::OffConnectionStateChange(napi_env env, napi_callback_info info) | 334 | napi_value NapiBluetoothHidDevice::OffConnectionStateChange(napi_env env, napi_callback_info info) |
| 318 | { | 335 | { |
| 336 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offConnectionStateChange)); | ||
| 319 | if (observer_) { | 337 | if (observer_) { |
| 320 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 338 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| 321 | STR_BT_HID_DEVICE_CONNECT_STATE_CHANGE); | 339 | STR_BT_HID_DEVICE_CONNECT_STATE_CHANGE); |
| @@ -326,6 +344,7 @@ napi_value NapiBluetoothHidDevice::OffConnectionStateChange(napi_env env, napi_c | |||
| 326 | 344 | ||
| 327 | napi_value NapiBluetoothHidDevice::GetConnectedDevices(napi_env env, napi_callback_info info) | 345 | napi_value NapiBluetoothHidDevice::GetConnectedDevices(napi_env env, napi_callback_info info) |
| 328 | { | 346 | { |
| 347 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectedDevices)); | ||
| 329 | HILOGI("enter"); | 348 | HILOGI("enter"); |
| 330 | napi_value ret = nullptr; | 349 | napi_value ret = nullptr; |
| 331 | if (napi_create_array(env, &ret) != napi_ok) { | 350 | if (napi_create_array(env, &ret) != napi_ok) { |
| @@ -349,6 +368,7 @@ napi_value NapiBluetoothHidDevice::GetConnectedDevices(napi_env env, napi_callba | |||
| 349 | 368 | ||
| 350 | napi_value NapiBluetoothHidDevice::GetConnectionState(napi_env env, napi_callback_info info) | 369 | napi_value NapiBluetoothHidDevice::GetConnectionState(napi_env env, napi_callback_info info) |
| 351 | { | 370 | { |
| 371 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 352 | napi_value result = nullptr; | 372 | napi_value result = nullptr; |
| 353 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; | 373 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; |
| 354 | if (napi_create_int32(env, profileState, &result) != napi_ok) { | 374 | if (napi_create_int32(env, profileState, &result) != napi_ok) { |
| @@ -659,6 +679,8 @@ napi_value NapiBluetoothHidDevice::ReportError(napi_env env, napi_callback_info | |||
| 659 | 679 | ||
| 660 | napi_value NapiBluetoothHidDevice::SetConnectionStrategy(napi_env env, napi_callback_info info) | 680 | napi_value NapiBluetoothHidDevice::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 661 | { | 681 | { |
| 682 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 683 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 662 | HILOGD("start"); | 684 | HILOGD("start"); |
| 663 | std::string remoteAddr {}; | 685 | std::string remoteAddr {}; |
| 664 | int32_t strategy = static_cast<int>(BTStrategyType::CONNECTION_UNKNOWN); | 686 | int32_t strategy = static_cast<int>(BTStrategyType::CONNECTION_UNKNOWN); |
| @@ -672,7 +694,7 @@ napi_value NapiBluetoothHidDevice::SetConnectionStrategy(napi_env env, napi_call | |||
| 672 | HILOGI("err: %{public}d", err); | 694 | HILOGI("err: %{public}d", err); |
| 673 | return NapiAsyncWorkRet(err); | 695 | return NapiAsyncWorkRet(err); |
| 674 | }; | 696 | }; |
| 675 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 697 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 676 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 698 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 677 | asyncWork->Run(); | 699 | asyncWork->Run(); |
| 678 | return asyncWork->GetRet(); | 700 | return asyncWork->GetRet(); |
| @@ -680,6 +702,8 @@ napi_value NapiBluetoothHidDevice::SetConnectionStrategy(napi_env env, napi_call | |||
| 680 | 702 | ||
| 681 | napi_value NapiBluetoothHidDevice::GetConnectionStrategy(napi_env env, napi_callback_info info) | 703 | napi_value NapiBluetoothHidDevice::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 682 | { | 704 | { |
| 705 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 706 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 683 | HILOGD("start"); | 707 | HILOGD("start"); |
| 684 | std::string remoteAddr {}; | 708 | std::string remoteAddr {}; |
| 685 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 709 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -694,7 +718,7 @@ napi_value NapiBluetoothHidDevice::GetConnectionStrategy(napi_env env, napi_call | |||
| 694 | auto object = std::make_shared<NapiNativeInt>(strategy); | 718 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 695 | return NapiAsyncWorkRet(err, object); | 719 | return NapiAsyncWorkRet(err, object); |
| 696 | }; | 720 | }; |
| 697 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 721 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 698 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 722 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 699 | asyncWork->Run(); | 723 | asyncWork->Run(); |
| 700 | return asyncWork->GetRet(); | 724 | return asyncWork->GetRet(); |
| @@ -80,6 +80,7 @@ napi_value NapiBluetoothHidHost::DefineCreateProfile(napi_env env, napi_value ex | |||
| 80 | 80 | ||
| 81 | napi_value NapiBluetoothHidHost::CreateHidHostProfile(napi_env env, napi_callback_info info) | 81 | napi_value NapiBluetoothHidHost::CreateHidHostProfile(napi_env env, napi_callback_info info) |
| 82 | { | 82 | { |
| 83 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createHidHostProfile)); | ||
| 83 | HILOGI("enter"); | 84 | HILOGI("enter"); |
| 84 | napi_value napiProfile; | 85 | napi_value napiProfile; |
| 85 | napi_value constructor = nullptr; | 86 | napi_value constructor = nullptr; |
| @@ -93,7 +94,6 @@ napi_value NapiBluetoothHidHost::CreateHidHostProfile(napi_env env, napi_callbac | |||
| 93 | return napiProfile; | 94 | return napiProfile; |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | - | ||
| 97 | napi_value NapiBluetoothHidHost::HidHostConstructor(napi_env env, napi_callback_info info) | 97 | napi_value NapiBluetoothHidHost::HidHostConstructor(napi_env env, napi_callback_info info) |
| 98 | { | 98 | { |
| 99 | napi_value thisVar = nullptr; | 99 | napi_value thisVar = nullptr; |
| @@ -103,8 +103,10 @@ napi_value NapiBluetoothHidHost::HidHostConstructor(napi_env env, napi_callback_ | |||
| 103 | 103 | ||
| 104 | napi_value NapiBluetoothHidHost::On(napi_env env, napi_callback_info info) | 104 | napi_value NapiBluetoothHidHost::On(napi_env env, napi_callback_info info) |
| 105 | { | 105 | { |
| 106 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 107 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 106 | if (observer_) { | 108 | if (observer_) { |
| 107 | - auto status = observer_->eventSubscribe_.Register(env, info); | 109 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 108 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 110 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 109 | } | 111 | } |
| 110 | return NapiGetUndefinedRet(env); | 112 | return NapiGetUndefinedRet(env); |
| @@ -112,8 +114,10 @@ napi_value NapiBluetoothHidHost::On(napi_env env, napi_callback_info info) | |||
| 112 | 114 | ||
| 113 | napi_value NapiBluetoothHidHost::Off(napi_env env, napi_callback_info info) | 115 | napi_value NapiBluetoothHidHost::Off(napi_env env, napi_callback_info info) |
| 114 | { | 116 | { |
| 117 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 118 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 115 | if (observer_) { | 119 | if (observer_) { |
| 116 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 120 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 117 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 121 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 118 | } | 122 | } |
| 119 | return NapiGetUndefinedRet(env); | 123 | return NapiGetUndefinedRet(env); |
| @@ -121,6 +125,7 @@ napi_value NapiBluetoothHidHost::Off(napi_env env, napi_callback_info info) | |||
| 121 | 125 | ||
| 122 | napi_value NapiBluetoothHidHost::GetConnectionDevices(napi_env env, napi_callback_info info) | 126 | napi_value NapiBluetoothHidHost::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 123 | { | 127 | { |
| 128 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 124 | HILOGI("enter"); | 129 | HILOGI("enter"); |
| 125 | 130 | ||
| 126 | napi_value ret = nullptr; | 131 | napi_value ret = nullptr; |
| @@ -147,6 +152,7 @@ napi_value NapiBluetoothHidHost::GetConnectionDevices(napi_env env, napi_callbac | |||
| 147 | 152 | ||
| 148 | napi_value NapiBluetoothHidHost::GetDeviceState(napi_env env, napi_callback_info info) | 153 | napi_value NapiBluetoothHidHost::GetDeviceState(napi_env env, napi_callback_info info) |
| 149 | { | 154 | { |
| 155 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 150 | napi_value result = nullptr; | 156 | napi_value result = nullptr; |
| 151 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; | 157 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; |
| 152 | if (napi_create_int32(env, profileState, &result) != napi_ok) { | 158 | if (napi_create_int32(env, profileState, &result) != napi_ok) { |
| @@ -172,6 +178,7 @@ napi_value NapiBluetoothHidHost::GetDeviceState(napi_env env, napi_callback_info | |||
| 172 | 178 | ||
| 173 | napi_value NapiBluetoothHidHost::Connect(napi_env env, napi_callback_info info) | 179 | napi_value NapiBluetoothHidHost::Connect(napi_env env, napi_callback_info info) |
| 174 | { | 180 | { |
| 181 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 175 | HILOGI("enter"); | 182 | HILOGI("enter"); |
| 176 | std::string remoteAddr {}; | 183 | std::string remoteAddr {}; |
| 177 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 184 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -187,6 +194,7 @@ napi_value NapiBluetoothHidHost::Connect(napi_env env, napi_callback_info info) | |||
| 187 | 194 | ||
| 188 | napi_value NapiBluetoothHidHost::Disconnect(napi_env env, napi_callback_info info) | 195 | napi_value NapiBluetoothHidHost::Disconnect(napi_env env, napi_callback_info info) |
| 189 | { | 196 | { |
| 197 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 190 | HILOGI("Disconnect called"); | 198 | HILOGI("Disconnect called"); |
| 191 | std::string remoteAddr {}; | 199 | std::string remoteAddr {}; |
| 192 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 200 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -202,6 +210,8 @@ napi_value NapiBluetoothHidHost::Disconnect(napi_env env, napi_callback_info inf | |||
| 202 | 210 | ||
| 203 | napi_value NapiBluetoothHidHost::SetConnectionStrategy(napi_env env, napi_callback_info info) | 211 | napi_value NapiBluetoothHidHost::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 204 | { | 212 | { |
| 213 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 214 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 205 | HILOGD("start"); | 215 | HILOGD("start"); |
| 206 | std::string remoteAddr {}; | 216 | std::string remoteAddr {}; |
| 207 | int32_t strategy = 0; | 217 | int32_t strategy = 0; |
| @@ -215,7 +225,7 @@ napi_value NapiBluetoothHidHost::SetConnectionStrategy(napi_env env, napi_callba | |||
| 215 | HILOGI("err: %{public}d", err); | 225 | HILOGI("err: %{public}d", err); |
| 216 | return NapiAsyncWorkRet(err); | 226 | return NapiAsyncWorkRet(err); |
| 217 | }; | 227 | }; |
| 218 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 228 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 219 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 229 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 220 | asyncWork->Run(); | 230 | asyncWork->Run(); |
| 221 | return asyncWork->GetRet(); | 231 | return asyncWork->GetRet(); |
| @@ -223,6 +233,8 @@ napi_value NapiBluetoothHidHost::SetConnectionStrategy(napi_env env, napi_callba | |||
| 223 | 233 | ||
| 224 | napi_value NapiBluetoothHidHost::GetConnectionStrategy(napi_env env, napi_callback_info info) | 234 | napi_value NapiBluetoothHidHost::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 225 | { | 235 | { |
| 236 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 237 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 226 | HILOGD("start"); | 238 | HILOGD("start"); |
| 227 | std::string remoteAddr {}; | 239 | std::string remoteAddr {}; |
| 228 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 240 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -237,7 +249,7 @@ napi_value NapiBluetoothHidHost::GetConnectionStrategy(napi_env env, napi_callba | |||
| 237 | auto object = std::make_shared<NapiNativeInt>(strategy); | 249 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 238 | return NapiAsyncWorkRet(err, object); | 250 | return NapiAsyncWorkRet(err, object); |
| 239 | }; | 251 | }; |
| 240 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 252 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 241 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 253 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 242 | asyncWork->Run(); | 254 | asyncWork->Run(); |
| 243 | return asyncWork->GetRet(); | 255 | return asyncWork->GetRet(); |
| @@ -69,6 +69,7 @@ napi_value NapiMapMse::DefineCreateProfile(napi_env env, napi_value exports) | |||
| 69 | 69 | ||
| 70 | napi_value NapiMapMse::CreateMapMseProfile(napi_env env, napi_callback_info info) | 70 | napi_value NapiMapMse::CreateMapMseProfile(napi_env env, napi_callback_info info) |
| 71 | { | 71 | { |
| 72 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createMapMseProfile)); | ||
| 72 | napi_value napiProfile; | 73 | napi_value napiProfile; |
| 73 | napi_value constructor = nullptr; | 74 | napi_value constructor = nullptr; |
| 74 | napi_get_reference_value(env, g_consRef_, &constructor); | 75 | napi_get_reference_value(env, g_consRef_, &constructor); |
| @@ -88,8 +89,10 @@ napi_value NapiMapMse::MapMseConstructor(napi_env env, napi_callback_info info) | |||
| 88 | 89 | ||
| 89 | napi_value NapiMapMse::On(napi_env env, napi_callback_info info) | 90 | napi_value NapiMapMse::On(napi_env env, napi_callback_info info) |
| 90 | { | 91 | { |
| 92 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 93 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 91 | if (observer_) { | 94 | if (observer_) { |
| 92 | - auto status = observer_->eventSubscribe_.Register(env, info); | 95 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 93 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 96 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 94 | } | 97 | } |
| 95 | return NapiGetUndefinedRet(env); | 98 | return NapiGetUndefinedRet(env); |
| @@ -97,8 +100,10 @@ napi_value NapiMapMse::On(napi_env env, napi_callback_info info) | |||
| 97 | 100 | ||
| 98 | napi_value NapiMapMse::Off(napi_env env, napi_callback_info info) | 101 | napi_value NapiMapMse::Off(napi_env env, napi_callback_info info) |
| 99 | { | 102 | { |
| 103 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 104 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 100 | if (observer_) { | 105 | if (observer_) { |
| 101 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 106 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 102 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 107 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 103 | } | 108 | } |
| 104 | return NapiGetUndefinedRet(env); | 109 | return NapiGetUndefinedRet(env); |
| @@ -130,6 +135,7 @@ napi_value NapiMapMse::GetConnectedDevices(napi_env env, napi_callback_info info | |||
| 130 | 135 | ||
| 131 | napi_value NapiMapMse::GetConnectionState(napi_env env, napi_callback_info info) | 136 | napi_value NapiMapMse::GetConnectionState(napi_env env, napi_callback_info info) |
| 132 | { | 137 | { |
| 138 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 133 | HILOGI("enter"); | 139 | HILOGI("enter"); |
| 134 | std::string remoteAddr {}; | 140 | std::string remoteAddr {}; |
| 135 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 141 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -150,6 +156,7 @@ napi_value NapiMapMse::GetConnectionState(napi_env env, napi_callback_info info) | |||
| 150 | 156 | ||
| 151 | napi_value NapiMapMse::Disconnect(napi_env env, napi_callback_info info) | 157 | napi_value NapiMapMse::Disconnect(napi_env env, napi_callback_info info) |
| 152 | { | 158 | { |
| 159 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 153 | HILOGD("enter"); | 160 | HILOGD("enter"); |
| 154 | std::string remoteAddr{}; | 161 | std::string remoteAddr{}; |
| 155 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 162 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -165,6 +172,8 @@ napi_value NapiMapMse::Disconnect(napi_env env, napi_callback_info info) | |||
| 165 | 172 | ||
| 166 | napi_value NapiMapMse::SetConnectionStrategy(napi_env env, napi_callback_info info) | 173 | napi_value NapiMapMse::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 167 | { | 174 | { |
| 175 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 176 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 168 | HILOGD("enter"); | 177 | HILOGD("enter"); |
| 169 | std::string remoteAddr{}; | 178 | std::string remoteAddr{}; |
| 170 | int32_t strategy = 0; | 179 | int32_t strategy = 0; |
| @@ -178,7 +187,7 @@ napi_value NapiMapMse::SetConnectionStrategy(napi_env env, napi_callback_info in | |||
| 178 | HILOGI("err: %{public}d", errorCode); | 187 | HILOGI("err: %{public}d", errorCode); |
| 179 | return NapiAsyncWorkRet(errorCode); | 188 | return NapiAsyncWorkRet(errorCode); |
| 180 | }; | 189 | }; |
| 181 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 190 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 182 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 191 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 183 | asyncWork->Run(); | 192 | asyncWork->Run(); |
| 184 | return asyncWork->GetRet(); | 193 | return asyncWork->GetRet(); |
| @@ -186,6 +195,8 @@ napi_value NapiMapMse::SetConnectionStrategy(napi_env env, napi_callback_info in | |||
| 186 | 195 | ||
| 187 | napi_value NapiMapMse::GetConnectionStrategy(napi_env env, napi_callback_info info) | 196 | napi_value NapiMapMse::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 188 | { | 197 | { |
| 198 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 199 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 189 | HILOGD("enter"); | 200 | HILOGD("enter"); |
| 190 | std::string remoteAddr{}; | 201 | std::string remoteAddr{}; |
| 191 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 202 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -200,7 +211,7 @@ napi_value NapiMapMse::GetConnectionStrategy(napi_env env, napi_callback_info in | |||
| 200 | auto object = std::make_shared<NapiNativeInt>(strategy); | 211 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 201 | return NapiAsyncWorkRet(errorCode, object); | 212 | return NapiAsyncWorkRet(errorCode, object); |
| 202 | }; | 213 | }; |
| 203 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 214 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 204 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 215 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 205 | asyncWork->Run(); | 216 | asyncWork->Run(); |
| 206 | return asyncWork->GetRet(); | 217 | return asyncWork->GetRet(); |
| @@ -208,6 +219,8 @@ napi_value NapiMapMse::GetConnectionStrategy(napi_env env, napi_callback_info in | |||
| 208 | 219 | ||
| 209 | napi_value NapiMapMse::SetMessageAccessAuthorization(napi_env env, napi_callback_info info) | 220 | napi_value NapiMapMse::SetMessageAccessAuthorization(napi_env env, napi_callback_info info) |
| 210 | { | 221 | { |
| 222 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 223 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setMessageAccessAuthorization)); | ||
| 211 | std::string remoteAddr{}; | 224 | std::string remoteAddr{}; |
| 212 | int32_t accessAuthorization = 0; | 225 | int32_t accessAuthorization = 0; |
| 213 | auto status = CheckAccessAuthorizationParam(env, info, remoteAddr, accessAuthorization); | 226 | auto status = CheckAccessAuthorizationParam(env, info, remoteAddr, accessAuthorization); |
| @@ -220,7 +233,7 @@ napi_value NapiMapMse::SetMessageAccessAuthorization(napi_env env, napi_callback | |||
| 220 | HILOGI("errorCode: %{public}d", errorCode); | 233 | HILOGI("errorCode: %{public}d", errorCode); |
| 221 | return NapiAsyncWorkRet(errorCode); | 234 | return NapiAsyncWorkRet(errorCode); |
| 222 | }; | 235 | }; |
| 223 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 236 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 224 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 237 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 225 | asyncWork->Run(); | 238 | asyncWork->Run(); |
| 226 | return asyncWork->GetRet(); | 239 | return asyncWork->GetRet(); |
| @@ -228,6 +241,8 @@ napi_value NapiMapMse::SetMessageAccessAuthorization(napi_env env, napi_callback | |||
| 228 | 241 | ||
| 229 | napi_value NapiMapMse::GetMessageAccessAuthorization(napi_env env, napi_callback_info info) | 242 | napi_value NapiMapMse::GetMessageAccessAuthorization(napi_env env, napi_callback_info info) |
| 230 | { | 243 | { |
| 244 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 245 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getMessageAccessAuthorization)); | ||
| 231 | std::string remoteAddr{}; | 246 | std::string remoteAddr{}; |
| 232 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 247 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| 233 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 248 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| @@ -241,7 +256,7 @@ napi_value NapiMapMse::GetMessageAccessAuthorization(napi_env env, napi_callback | |||
| 241 | auto object = std::make_shared<NapiNativeInt>(accessAuthorization); | 256 | auto object = std::make_shared<NapiNativeInt>(accessAuthorization); |
| 242 | return NapiAsyncWorkRet(errorCode, object); | 257 | return NapiAsyncWorkRet(errorCode, object); |
| 243 | }; | 258 | }; |
| 244 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 259 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 245 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 260 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 246 | asyncWork->Run(); | 261 | asyncWork->Run(); |
| 247 | return asyncWork->GetRet(); | 262 | return asyncWork->GetRet(); |
| @@ -59,8 +59,11 @@ napi_value NapiA2dpSink::A2dpSinkConstructor(napi_env env, napi_callback_info in | |||
| 59 | 59 | ||
| 60 | napi_value NapiA2dpSink::On(napi_env env, napi_callback_info info) | 60 | napi_value NapiA2dpSink::On(napi_env env, napi_callback_info info) |
| 61 | { | 61 | { |
| 62 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 63 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 64 | + haUtils->SetProfile("a2dpSink"); | ||
| 62 | if (observer_) { | 65 | if (observer_) { |
| 63 | - auto status = observer_->eventSubscribe_.Register(env, info); | 66 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 64 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 67 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 65 | } | 68 | } |
| 66 | if (!isRegistered_) { | 69 | if (!isRegistered_) { |
| @@ -73,8 +76,11 @@ napi_value NapiA2dpSink::On(napi_env env, napi_callback_info info) | |||
| 73 | 76 | ||
| 74 | napi_value NapiA2dpSink::Off(napi_env env, napi_callback_info info) | 77 | napi_value NapiA2dpSink::Off(napi_env env, napi_callback_info info) |
| 75 | { | 78 | { |
| 79 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 80 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 81 | + haUtils->SetProfile("a2dpSink"); | ||
| 76 | if (observer_) { | 82 | if (observer_) { |
| 77 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 83 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 78 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 84 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 79 | } | 85 | } |
| 80 | return NapiGetUndefinedRet(env); | 86 | return NapiGetUndefinedRet(env); |
| @@ -82,6 +88,7 @@ napi_value NapiA2dpSink::Off(napi_env env, napi_callback_info info) | |||
| 82 | 88 | ||
| 83 | napi_value NapiA2dpSink::GetConnectionDevices(napi_env env, napi_callback_info info) | 89 | napi_value NapiA2dpSink::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 84 | { | 90 | { |
| 91 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 85 | HILOGI("enter"); | 92 | HILOGI("enter"); |
| 86 | napi_value ret = nullptr; | 93 | napi_value ret = nullptr; |
| 87 | napi_create_array(env, &ret); | 94 | napi_create_array(env, &ret); |
| @@ -99,6 +106,7 @@ napi_value NapiA2dpSink::GetConnectionDevices(napi_env env, napi_callback_info i | |||
| 99 | 106 | ||
| 100 | napi_value NapiA2dpSink::GetDeviceState(napi_env env, napi_callback_info info) | 107 | napi_value NapiA2dpSink::GetDeviceState(napi_env env, napi_callback_info info) |
| 101 | { | 108 | { |
| 109 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 102 | HILOGI("enter"); | 110 | HILOGI("enter"); |
| 103 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 111 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 104 | size_t argc = expectedArgsCount; | 112 | size_t argc = expectedArgsCount; |
| @@ -131,6 +139,7 @@ napi_value NapiA2dpSink::GetDeviceState(napi_env env, napi_callback_info info) | |||
| 131 | 139 | ||
| 132 | napi_value NapiA2dpSink::Connect(napi_env env, napi_callback_info info) | 140 | napi_value NapiA2dpSink::Connect(napi_env env, napi_callback_info info) |
| 133 | { | 141 | { |
| 142 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 134 | HILOGI("enter"); | 143 | HILOGI("enter"); |
| 135 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 144 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 136 | size_t argc = expectedArgsCount; | 145 | size_t argc = expectedArgsCount; |
| @@ -163,6 +172,7 @@ napi_value NapiA2dpSink::Connect(napi_env env, napi_callback_info info) | |||
| 163 | 172 | ||
| 164 | napi_value NapiA2dpSink::Disconnect(napi_env env, napi_callback_info info) | 173 | napi_value NapiA2dpSink::Disconnect(napi_env env, napi_callback_info info) |
| 165 | { | 174 | { |
| 175 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 166 | HILOGI("enter"); | 176 | HILOGI("enter"); |
| 167 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 177 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 168 | size_t argc = expectedArgsCount; | 178 | size_t argc = expectedArgsCount; |
| @@ -195,6 +205,7 @@ napi_value NapiA2dpSink::Disconnect(napi_env env, napi_callback_info info) | |||
| 195 | 205 | ||
| 196 | napi_value NapiA2dpSink::getPlayingState(napi_env env, napi_callback_info info) | 206 | napi_value NapiA2dpSink::getPlayingState(napi_env env, napi_callback_info info) |
| 197 | { | 207 | { |
| 208 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getPlayingState)); | ||
| 198 | HILOGI("enter"); | 209 | HILOGI("enter"); |
| 199 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 210 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 200 | size_t argc = expectedArgsCount; | 211 | size_t argc = expectedArgsCount; |
| @@ -59,8 +59,11 @@ napi_value NapiAvrcpController::AvrcpControllerConstructor(napi_env env, napi_ca | |||
| 59 | 59 | ||
| 60 | napi_value NapiAvrcpController::On(napi_env env, napi_callback_info info) | 60 | napi_value NapiAvrcpController::On(napi_env env, napi_callback_info info) |
| 61 | { | 61 | { |
| 62 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 63 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 64 | + haUtils->SetProfile("avrcpController"); | ||
| 62 | if (observer_) { | 65 | if (observer_) { |
| 63 | - auto status = observer_->eventSubscribe_.Register(env, info); | 66 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 64 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 67 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 65 | } | 68 | } |
| 66 | 69 | ||
| @@ -75,8 +78,11 @@ napi_value NapiAvrcpController::On(napi_env env, napi_callback_info info) | |||
| 75 | 78 | ||
| 76 | napi_value NapiAvrcpController::Off(napi_env env, napi_callback_info info) | 79 | napi_value NapiAvrcpController::Off(napi_env env, napi_callback_info info) |
| 77 | { | 80 | { |
| 81 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 82 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 83 | + haUtils->SetProfile("avrcpController"); | ||
| 78 | if (observer_) { | 84 | if (observer_) { |
| 79 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 85 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 80 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 86 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 81 | } | 87 | } |
| 82 | return NapiGetUndefinedRet(env); | 88 | return NapiGetUndefinedRet(env); |
| @@ -84,6 +90,7 @@ napi_value NapiAvrcpController::Off(napi_env env, napi_callback_info info) | |||
| 84 | 90 | ||
| 85 | napi_value NapiAvrcpController::GetConnectionDevices(napi_env env, napi_callback_info info) | 91 | napi_value NapiAvrcpController::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 86 | { | 92 | { |
| 93 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 87 | HILOGI("enter"); | 94 | HILOGI("enter"); |
| 88 | napi_value ret = nullptr; | 95 | napi_value ret = nullptr; |
| 89 | napi_create_array(env, &ret); | 96 | napi_create_array(env, &ret); |
| @@ -101,6 +108,7 @@ napi_value NapiAvrcpController::GetConnectionDevices(napi_env env, napi_callback | |||
| 101 | 108 | ||
| 102 | napi_value NapiAvrcpController::GetDeviceState(napi_env env, napi_callback_info info) | 109 | napi_value NapiAvrcpController::GetDeviceState(napi_env env, napi_callback_info info) |
| 103 | { | 110 | { |
| 111 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 104 | HILOGI("enter"); | 112 | HILOGI("enter"); |
| 105 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 113 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 106 | size_t argc = expectedArgsCount; | 114 | size_t argc = expectedArgsCount; |
| @@ -131,9 +139,9 @@ napi_value NapiAvrcpController::GetDeviceState(napi_env env, napi_callback_info | |||
| 131 | return result; | 139 | return result; |
| 132 | } | 140 | } |
| 133 | 141 | ||
| 134 | - | ||
| 135 | napi_value NapiAvrcpController::Connect(napi_env env, napi_callback_info info) | 142 | napi_value NapiAvrcpController::Connect(napi_env env, napi_callback_info info) |
| 136 | { | 143 | { |
| 144 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 137 | HILOGI("enter"); | 145 | HILOGI("enter"); |
| 138 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 146 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 139 | size_t argc = expectedArgsCount; | 147 | size_t argc = expectedArgsCount; |
| @@ -166,6 +174,7 @@ napi_value NapiAvrcpController::Connect(napi_env env, napi_callback_info info) | |||
| 166 | 174 | ||
| 167 | napi_value NapiAvrcpController::Disconnect(napi_env env, napi_callback_info info) | 175 | napi_value NapiAvrcpController::Disconnect(napi_env env, napi_callback_info info) |
| 168 | { | 176 | { |
| 177 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 169 | HILOGI("enter"); | 178 | HILOGI("enter"); |
| 170 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 179 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 171 | size_t argc = expectedArgsCount; | 180 | size_t argc = expectedArgsCount; |
| @@ -59,8 +59,11 @@ napi_value NapiAvrcpTarget::AvrcpTargetConstructor(napi_env env, napi_callback_i | |||
| 59 | 59 | ||
| 60 | napi_value NapiAvrcpTarget::On(napi_env env, napi_callback_info info) | 60 | napi_value NapiAvrcpTarget::On(napi_env env, napi_callback_info info) |
| 61 | { | 61 | { |
| 62 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 63 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 64 | + haUtils->SetProfile("avrcpTarget"); | ||
| 62 | if (observer_) { | 65 | if (observer_) { |
| 63 | - auto status = observer_->eventSubscribe_.Register(env, info); | 66 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 64 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 67 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 65 | } | 68 | } |
| 66 | 69 | ||
| @@ -75,8 +78,11 @@ napi_value NapiAvrcpTarget::On(napi_env env, napi_callback_info info) | |||
| 75 | 78 | ||
| 76 | napi_value NapiAvrcpTarget::Off(napi_env env, napi_callback_info info) | 79 | napi_value NapiAvrcpTarget::Off(napi_env env, napi_callback_info info) |
| 77 | { | 80 | { |
| 81 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 82 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 83 | + haUtils->SetProfile("avrcpTarget"); | ||
| 78 | if (observer_) { | 84 | if (observer_) { |
| 79 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 85 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 80 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 86 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 81 | } | 87 | } |
| 82 | return NapiGetUndefinedRet(env); | 88 | return NapiGetUndefinedRet(env); |
| @@ -84,6 +90,7 @@ napi_value NapiAvrcpTarget::Off(napi_env env, napi_callback_info info) | |||
| 84 | 90 | ||
| 85 | napi_value NapiAvrcpTarget::GetConnectionDevices(napi_env env, napi_callback_info info) | 91 | napi_value NapiAvrcpTarget::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 86 | { | 92 | { |
| 93 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 87 | HILOGI("enter"); | 94 | HILOGI("enter"); |
| 88 | napi_value ret = nullptr; | 95 | napi_value ret = nullptr; |
| 89 | napi_create_array(env, &ret); | 96 | napi_create_array(env, &ret); |
| @@ -101,6 +108,7 @@ napi_value NapiAvrcpTarget::GetConnectionDevices(napi_env env, napi_callback_inf | |||
| 101 | 108 | ||
| 102 | napi_value NapiAvrcpTarget::GetDeviceState(napi_env env, napi_callback_info info) | 109 | napi_value NapiAvrcpTarget::GetDeviceState(napi_env env, napi_callback_info info) |
| 103 | { | 110 | { |
| 111 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 104 | HILOGI("enter"); | 112 | HILOGI("enter"); |
| 105 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 113 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 106 | size_t argc = expectedArgsCount; | 114 | size_t argc = expectedArgsCount; |
| @@ -133,6 +141,7 @@ napi_value NapiAvrcpTarget::GetDeviceState(napi_env env, napi_callback_info info | |||
| 133 | 141 | ||
| 134 | napi_value NapiAvrcpTarget::Connect(napi_env env, napi_callback_info info) | 142 | napi_value NapiAvrcpTarget::Connect(napi_env env, napi_callback_info info) |
| 135 | { | 143 | { |
| 144 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(connect)); | ||
| 136 | HILOGI("enter"); | 145 | HILOGI("enter"); |
| 137 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 146 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 138 | size_t argc = expectedArgsCount; | 147 | size_t argc = expectedArgsCount; |
| @@ -165,6 +174,7 @@ napi_value NapiAvrcpTarget::Connect(napi_env env, napi_callback_info info) | |||
| 165 | 174 | ||
| 166 | napi_value NapiAvrcpTarget::Disconnect(napi_env env, napi_callback_info info) | 175 | napi_value NapiAvrcpTarget::Disconnect(napi_env env, napi_callback_info info) |
| 167 | { | 176 | { |
| 177 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 168 | HILOGI("enter"); | 178 | HILOGI("enter"); |
| 169 | size_t expectedArgsCount = ARGS_SIZE_ONE; | 179 | size_t expectedArgsCount = ARGS_SIZE_ONE; |
| 170 | size_t argc = expectedArgsCount; | 180 | size_t argc = expectedArgsCount; |
| @@ -46,6 +46,7 @@ napi_value BluetoothHostInit(napi_env env, napi_value exports) | |||
| 46 | 46 | ||
| 47 | napi_value RegisterHostObserver(napi_env env, napi_callback_info info) | 47 | napi_value RegisterHostObserver(napi_env env, napi_callback_info info) |
| 48 | { | 48 | { |
| 49 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(on)); | ||
| 49 | HILOGD("enter"); | 50 | HILOGD("enter"); |
| 50 | size_t argc = ARGS_SIZE_TWO; | 51 | size_t argc = ARGS_SIZE_TWO; |
| 51 | napi_value argv[ARGS_SIZE_TWO] = {0}; | 52 | napi_value argv[ARGS_SIZE_TWO] = {0}; |
| @@ -67,6 +68,7 @@ napi_value RegisterHostObserver(napi_env env, napi_callback_info info) | |||
| 67 | 68 | ||
| 68 | napi_value DeregisterHostObserver(napi_env env, napi_callback_info info) | 69 | napi_value DeregisterHostObserver(napi_env env, napi_callback_info info) |
| 69 | { | 70 | { |
| 71 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(off)); | ||
| 70 | HILOGD("enter"); | 72 | HILOGD("enter"); |
| 71 | size_t argc = ARGS_SIZE_TWO; | 73 | size_t argc = ARGS_SIZE_TWO; |
| 72 | napi_value argv[ARGS_SIZE_TWO] = {0}; | 74 | napi_value argv[ARGS_SIZE_TWO] = {0}; |
| @@ -27,6 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | + | ||
| 30 | 31 | ||
| 31 | namespace OHOS { | 32 | namespace OHOS { |
| 32 | namespace Bluetooth { | 33 | namespace Bluetooth { |
| @@ -69,6 +70,7 @@ napi_value NapiBluetoothOpp::DefineCreateProfile(napi_env env, napi_value export | |||
| 69 | 70 | ||
| 70 | napi_value NapiBluetoothOpp::CreateOppServerProfile(napi_env env, napi_callback_info info) | 71 | napi_value NapiBluetoothOpp::CreateOppServerProfile(napi_env env, napi_callback_info info) |
| 71 | { | 72 | { |
| 73 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createOppServerProfile)); | ||
| 72 | napi_value napiProfile; | 74 | napi_value napiProfile; |
| 73 | napi_value constructor = nullptr; | 75 | napi_value constructor = nullptr; |
| 74 | napi_get_reference_value(env, g_consRef_, &constructor); | 76 | napi_get_reference_value(env, g_consRef_, &constructor); |
| @@ -88,8 +90,10 @@ napi_value NapiBluetoothOpp::OppConstructor(napi_env env, napi_callback_info inf | |||
| 88 | 90 | ||
| 89 | napi_value NapiBluetoothOpp::On(napi_env env, napi_callback_info info) | 91 | napi_value NapiBluetoothOpp::On(napi_env env, napi_callback_info info) |
| 90 | { | 92 | { |
| 93 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 94 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 91 | if (observer_) { | 95 | if (observer_) { |
| 92 | - auto status = observer_->eventSubscribe_.Register(env, info); | 96 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 93 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 97 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 94 | } | 98 | } |
| 95 | return NapiGetUndefinedRet(env); | 99 | return NapiGetUndefinedRet(env); |
| @@ -97,8 +101,10 @@ napi_value NapiBluetoothOpp::On(napi_env env, napi_callback_info info) | |||
| 97 | 101 | ||
| 98 | napi_value NapiBluetoothOpp::Off(napi_env env, napi_callback_info info) | 102 | napi_value NapiBluetoothOpp::Off(napi_env env, napi_callback_info info) |
| 99 | { | 103 | { |
| 104 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 105 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 100 | if (observer_) { | 106 | if (observer_) { |
| 101 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 107 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 102 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 108 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 103 | } | 109 | } |
| 104 | return NapiGetUndefinedRet(env); | 110 | return NapiGetUndefinedRet(env); |
| @@ -136,7 +142,7 @@ napi_value NapiBluetoothOpp::SendFile(napi_env env, napi_callback_info info) | |||
| 136 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_FILE_TYPE_NOT_SUPPORT, | 142 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_FILE_TYPE_NOT_SUPPORT, |
| 137 | BT_ERR_TRANSFER_BUSY, BT_ERR_FILE_NOT_ACCESSIBLE | 143 | BT_ERR_TRANSFER_BUSY, BT_ERR_FILE_NOT_ACCESSIBLE |
| 138 | }; | 144 | }; |
| 139 | - NAPI_BT_CONTEXT(env, "opp.SendFile", validErrCodes); | 145 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(SendFile), validErrCodes); |
| 140 | std::string device {}; | 146 | std::string device {}; |
| 141 | std::vector<FileHolder> fileHolders; | 147 | std::vector<FileHolder> fileHolders; |
| 142 | 148 | ||
| @@ -171,7 +177,7 @@ napi_value NapiBluetoothOpp::SetIncomingFileConfirmation(napi_env env, napi_call | |||
| 171 | BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, | 177 | BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, |
| 172 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_TRANSFER_BUSY, BT_ERR_FILE_NOT_ACCESSIBLE | 178 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_TRANSFER_BUSY, BT_ERR_FILE_NOT_ACCESSIBLE |
| 173 | }; | 179 | }; |
| 174 | - NAPI_BT_CONTEXT(env, "opp.SetIncomingFileConfirmation", validErrCodes); | 180 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(SetIncomingFileConfirmation), validErrCodes); |
| 175 | bool accept = false; | 181 | bool accept = false; |
| 176 | int32_t fileFd = -1; | 182 | int32_t fileFd = -1; |
| 177 | auto status = CheckSetIncomingFileConfirmation(env, info, accept, fileFd); | 183 | auto status = CheckSetIncomingFileConfirmation(env, info, accept, fileFd); |
| @@ -198,7 +204,7 @@ napi_value NapiBluetoothOpp::GetCurrentTransferInformation(napi_env env, napi_ca | |||
| 198 | BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, | 204 | BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, |
| 199 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_TRANSFER_INFORMATION_EMPTY | 205 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_TRANSFER_INFORMATION_EMPTY |
| 200 | }; | 206 | }; |
| 201 | - NAPI_BT_CONTEXT(env, "opp.GetCurrentTransferInformation", validErrCodes); | 207 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(GetCurrentTransferInformation), validErrCodes); |
| 202 | napi_value ret = nullptr; | 208 | napi_value ret = nullptr; |
| 203 | napi_create_object(env, &ret); | 209 | napi_create_object(env, &ret); |
| 204 | napi_status checkRet = CheckEmptyParam(env, info); | 210 | napi_status checkRet = CheckEmptyParam(env, info); |
| @@ -233,7 +239,7 @@ napi_value NapiBluetoothOpp::SetLastReceivedFileUri(napi_env env, napi_callback_ | |||
| 233 | BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, | 239 | BT_ERR_INVALID_PARAM, BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, |
| 234 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR | 240 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR |
| 235 | }; | 241 | }; |
| 236 | - NAPI_BT_CONTEXT(env, "opp.SetLastReceivedFileUri", validErrCodes); | 242 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(SetLastReceivedFileUri), validErrCodes); |
| 237 | std::string uri {}; | 243 | std::string uri {}; |
| 238 | 244 | ||
| 239 | auto status = CheckLastReceivedFileUri(env, info, uri); | 245 | auto status = CheckLastReceivedFileUri(env, info, uri); |
| @@ -260,7 +266,7 @@ napi_value NapiBluetoothOpp::CancelTransfer(napi_env env, napi_callback_info inf | |||
| 260 | BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, | 266 | BT_ERR_API_NOT_SUPPORT, BT_ERR_SERVICE_DISCONNECTED, BT_ERR_INVALID_STATE, |
| 261 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_TRANSFER_BUSY | 267 | BT_ERR_PROFILE_DISABLED, BT_ERR_INTERNAL_ERROR, BT_ERR_TRANSFER_BUSY |
| 262 | }; | 268 | }; |
| 263 | - NAPI_BT_CONTEXT(env, "opp.CancelTransfer", validErrCodes); | 269 | + NAPI_BT_CONTEXT(env, BT_HA_API_NAME(CancelTransfer), validErrCodes); |
| 264 | napi_value ret = nullptr; | 270 | napi_value ret = nullptr; |
| 265 | bool isOk = false; | 271 | bool isOk = false; |
| 266 | napi_get_boolean(env, isOk, &ret); | 272 | napi_get_boolean(env, isOk, &ret); |
| @@ -275,6 +281,7 @@ napi_value NapiBluetoothOpp::CancelTransfer(napi_env env, napi_callback_info inf | |||
| 275 | 281 | ||
| 276 | napi_value NapiBluetoothOpp::GetConnectionDevices(napi_env env, napi_callback_info info) | 282 | napi_value NapiBluetoothOpp::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 277 | { | 283 | { |
| 284 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 278 | HILOGI("enter"); | 285 | HILOGI("enter"); |
| 279 | 286 | ||
| 280 | napi_value ret = nullptr; | 287 | napi_value ret = nullptr; |
| @@ -299,6 +306,7 @@ napi_value NapiBluetoothOpp::GetConnectionDevices(napi_env env, napi_callback_in | |||
| 299 | 306 | ||
| 300 | napi_value NapiBluetoothOpp::GetDeviceState(napi_env env, napi_callback_info info) | 307 | napi_value NapiBluetoothOpp::GetDeviceState(napi_env env, napi_callback_info info) |
| 301 | { | 308 | { |
| 309 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 302 | HILOGI("enter"); | 310 | HILOGI("enter"); |
| 303 | std::string remoteAddr{}; | 311 | std::string remoteAddr{}; |
| 304 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 312 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -25,6 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | + | ||
| 28 | 29 | ||
| 29 | namespace OHOS { | 30 | namespace OHOS { |
| 30 | namespace Bluetooth { | 31 | namespace Bluetooth { |
| @@ -34,6 +35,7 @@ thread_local napi_ref NapiBluetoothPan::consRef_ = nullptr; | |||
| 34 | 35 | ||
| 35 | napi_value NapiBluetoothPan::CreatePanProfile(napi_env env, napi_callback_info info) | 36 | napi_value NapiBluetoothPan::CreatePanProfile(napi_env env, napi_callback_info info) |
| 36 | { | 37 | { |
| 38 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createPanProfile)); | ||
| 37 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 39 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 38 | napi_value napiProfile; | 40 | napi_value napiProfile; |
| 39 | napi_value constructor = nullptr; | 41 | napi_value constructor = nullptr; |
| @@ -96,6 +98,8 @@ napi_value NapiBluetoothPan::DefineCreateProfile(napi_env env, napi_value export | |||
| 96 | 98 | ||
| 97 | napi_value NapiBluetoothPan::SetConnectionStrategy(napi_env env, napi_callback_info info) | 99 | napi_value NapiBluetoothPan::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 98 | { | 100 | { |
| 101 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 102 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 99 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 103 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 100 | std::string remoteAddr {}; | 104 | std::string remoteAddr {}; |
| 101 | int32_t strategy = static_cast<int>(BTStrategyType::CONNECTION_UNKNOWN); | 105 | int32_t strategy = static_cast<int>(BTStrategyType::CONNECTION_UNKNOWN); |
| @@ -109,7 +113,7 @@ napi_value NapiBluetoothPan::SetConnectionStrategy(napi_env env, napi_callback_i | |||
| 109 | HILOGI("Pan SetConnectionStrategy err: %{public}d", err); | 113 | HILOGI("Pan SetConnectionStrategy err: %{public}d", err); |
| 110 | return NapiAsyncWorkRet(err); | 114 | return NapiAsyncWorkRet(err); |
| 111 | }; | 115 | }; |
| 112 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 116 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 113 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 117 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 114 | asyncWork->Run(); | 118 | asyncWork->Run(); |
| 115 | return asyncWork->GetRet(); | 119 | return asyncWork->GetRet(); |
| @@ -117,6 +121,8 @@ napi_value NapiBluetoothPan::SetConnectionStrategy(napi_env env, napi_callback_i | |||
| 117 | 121 | ||
| 118 | napi_value NapiBluetoothPan::GetConnectionStrategy(napi_env env, napi_callback_info info) | 122 | napi_value NapiBluetoothPan::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 119 | { | 123 | { |
| 124 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 125 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 120 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 126 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 121 | std::string remoteAddr {}; | 127 | std::string remoteAddr {}; |
| 122 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 128 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -131,7 +137,7 @@ napi_value NapiBluetoothPan::GetConnectionStrategy(napi_env env, napi_callback_i | |||
| 131 | auto object = std::make_shared<NapiNativeInt>(strategy); | 137 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 132 | return NapiAsyncWorkRet(err, object); | 138 | return NapiAsyncWorkRet(err, object); |
| 133 | }; | 139 | }; |
| 134 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 140 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 135 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 141 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 136 | asyncWork->Run(); | 142 | asyncWork->Run(); |
| 137 | return asyncWork->GetRet(); | 143 | return asyncWork->GetRet(); |
| @@ -146,9 +152,11 @@ napi_value NapiBluetoothPan::PanConstructor(napi_env env, napi_callback_info inf | |||
| 146 | 152 | ||
| 147 | napi_value NapiBluetoothPan::On(napi_env env, napi_callback_info info) | 153 | napi_value NapiBluetoothPan::On(napi_env env, napi_callback_info info) |
| 148 | { | 154 | { |
| 155 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 156 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 149 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 157 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 150 | if (observer_) { | 158 | if (observer_) { |
| 151 | - auto status = observer_->eventSubscribe_.Register(env, info); | 159 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 152 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 160 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 153 | } | 161 | } |
| 154 | return NapiGetUndefinedRet(env); | 162 | return NapiGetUndefinedRet(env); |
| @@ -156,6 +164,7 @@ napi_value NapiBluetoothPan::On(napi_env env, napi_callback_info info) | |||
| 156 | 164 | ||
| 157 | napi_value NapiBluetoothPan::OnConnectionStateChange(napi_env env, napi_callback_info info) | 165 | napi_value NapiBluetoothPan::OnConnectionStateChange(napi_env env, napi_callback_info info) |
| 158 | { | 166 | { |
| 167 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(onConnectionStateChange)); | ||
| 159 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 168 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 160 | if (observer_) { | 169 | if (observer_) { |
| 161 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, | 170 | auto status = observer_->eventSubscribe_.RegisterWithName(env, info, |
| @@ -167,9 +176,11 @@ napi_value NapiBluetoothPan::OnConnectionStateChange(napi_env env, napi_callback | |||
| 167 | 176 | ||
| 168 | napi_value NapiBluetoothPan::Off(napi_env env, napi_callback_info info) | 177 | napi_value NapiBluetoothPan::Off(napi_env env, napi_callback_info info) |
| 169 | { | 178 | { |
| 179 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 180 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 170 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 181 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 171 | if (observer_) { | 182 | if (observer_) { |
| 172 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 183 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 173 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 184 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 174 | } | 185 | } |
| 175 | return NapiGetUndefinedRet(env); | 186 | return NapiGetUndefinedRet(env); |
| @@ -177,6 +188,7 @@ napi_value NapiBluetoothPan::Off(napi_env env, napi_callback_info info) | |||
| 177 | 188 | ||
| 178 | napi_value NapiBluetoothPan::OffConnectionStateChange(napi_env env, napi_callback_info info) | 189 | napi_value NapiBluetoothPan::OffConnectionStateChange(napi_env env, napi_callback_info info) |
| 179 | { | 190 | { |
| 191 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(offConnectionStateChange)); | ||
| 180 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 192 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 181 | if (observer_) { | 193 | if (observer_) { |
| 182 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, | 194 | auto status = observer_->eventSubscribe_.DeregisterWithName(env, info, |
| @@ -188,6 +200,7 @@ napi_value NapiBluetoothPan::OffConnectionStateChange(napi_env env, napi_callbac | |||
| 188 | 200 | ||
| 189 | napi_value NapiBluetoothPan::GetConnectionDevices(napi_env env, napi_callback_info info) | 201 | napi_value NapiBluetoothPan::GetConnectionDevices(napi_env env, napi_callback_info info) |
| 190 | { | 202 | { |
| 203 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionDevices)); | ||
| 191 | napi_value ret = nullptr; | 204 | napi_value ret = nullptr; |
| 192 | NAPI_BT_ASSERT_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT, ret); | 205 | NAPI_BT_ASSERT_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT, ret); |
| 193 | if (napi_create_array(env, &ret) != napi_ok) { | 206 | if (napi_create_array(env, &ret) != napi_ok) { |
| @@ -214,6 +227,7 @@ napi_value NapiBluetoothPan::GetConnectionDevices(napi_env env, napi_callback_in | |||
| 214 | 227 | ||
| 215 | napi_value NapiBluetoothPan::GetDeviceState(napi_env env, napi_callback_info info) | 228 | napi_value NapiBluetoothPan::GetDeviceState(napi_env env, napi_callback_info info) |
| 216 | { | 229 | { |
| 230 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceState)); | ||
| 217 | napi_value result = nullptr; | 231 | napi_value result = nullptr; |
| 218 | NAPI_BT_ASSERT_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT, result); | 232 | NAPI_BT_ASSERT_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT, result); |
| 219 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; | 233 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; |
| @@ -264,6 +278,7 @@ napi_value NapiBluetoothPan::GetConnectedDevices(napi_env env, napi_callback_inf | |||
| 264 | 278 | ||
| 265 | napi_value NapiBluetoothPan::GetConnectionState(napi_env env, napi_callback_info info) | 279 | napi_value NapiBluetoothPan::GetConnectionState(napi_env env, napi_callback_info info) |
| 266 | { | 280 | { |
| 281 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 267 | napi_value result = nullptr; | 282 | napi_value result = nullptr; |
| 268 | NAPI_BT_ASSERT_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT, result); | 283 | NAPI_BT_ASSERT_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT, result); |
| 269 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; | 284 | int32_t profileState = ProfileConnectionState::STATE_DISCONNECTED; |
| @@ -291,8 +306,8 @@ napi_value NapiBluetoothPan::GetConnectionState(napi_env env, napi_callback_info | |||
| 291 | napi_value NapiBluetoothPan::Disconnect(napi_env env, napi_callback_info info) | 306 | napi_value NapiBluetoothPan::Disconnect(napi_env env, napi_callback_info info) |
| 292 | { | 307 | { |
| 293 | NAPI_BT_ASSERT_RETURN_FALSE(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 308 | NAPI_BT_ASSERT_RETURN_FALSE(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 294 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, | 309 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 295 | - "pan.Disconnect"); | 310 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(Disconnect)); |
| 296 | std::string remoteAddr {}; | 311 | std::string remoteAddr {}; |
| 297 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 312 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| 298 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet, BT_ERR_INVALID_PARAM); | 313 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet, BT_ERR_INVALID_PARAM); |
| @@ -307,8 +322,8 @@ napi_value NapiBluetoothPan::Disconnect(napi_env env, napi_callback_info info) | |||
| 307 | napi_value NapiBluetoothPan::Connect(napi_env env, napi_callback_info info) | 322 | napi_value NapiBluetoothPan::Connect(napi_env env, napi_callback_info info) |
| 308 | { | 323 | { |
| 309 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 324 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 310 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, | 325 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 311 | - "pan.Connect"); | 326 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(Connect)); |
| 312 | std::string remoteAddr {}; | 327 | std::string remoteAddr {}; |
| 313 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 328 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| 314 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, checkRet, BT_ERR_INVALID_PARAM); | 329 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, checkRet, BT_ERR_INVALID_PARAM); |
| @@ -333,8 +348,8 @@ static bool CheckSetTetheringParam(napi_env env, napi_callback_info info, bool & | |||
| 333 | napi_value NapiBluetoothPan::SetTethering(napi_env env, napi_callback_info info) | 348 | napi_value NapiBluetoothPan::SetTethering(napi_env env, napi_callback_info info) |
| 334 | { | 349 | { |
| 335 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 350 | NAPI_BT_ASSERT_RETURN_UNDEF(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 336 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, | 351 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 337 | - "pan.SetTethering"); | 352 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(SetTethering)); |
| 338 | bool value = false; | 353 | bool value = false; |
| 339 | bool checkRet = CheckSetTetheringParam(env, info, value); | 354 | bool checkRet = CheckSetTetheringParam(env, info, value); |
| 340 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet, BT_ERR_INVALID_PARAM); | 355 | NAPI_BT_ASSERT_RETURN_UNDEF(env, checkRet, BT_ERR_INVALID_PARAM); |
| @@ -348,8 +363,8 @@ napi_value NapiBluetoothPan::SetTethering(napi_env env, napi_callback_info info) | |||
| 348 | napi_value NapiBluetoothPan::IsTetheringOn(napi_env env, napi_callback_info info) | 363 | napi_value NapiBluetoothPan::IsTetheringOn(napi_env env, napi_callback_info info) |
| 349 | { | 364 | { |
| 350 | NAPI_BT_ASSERT_RETURN_FALSE(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); | 365 | NAPI_BT_ASSERT_RETURN_FALSE(env, IS_PAN_SUPPORTED, BT_ERR_API_NOT_SUPPORT); |
| 351 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, | 366 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 352 | - "pan.IsTetheringOn"); | 367 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(IsTetheringOn)); |
| 353 | napi_status checkRet = CheckEmptyParam(env, info); | 368 | napi_status checkRet = CheckEmptyParam(env, info); |
| 354 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet == napi_ok, BT_ERR_INVALID_PARAM); | 369 | NAPI_BT_ASSERT_RETURN_FALSE(env, checkRet == napi_ok, BT_ERR_INVALID_PARAM); |
| 355 | 370 | ||
| @@ -366,8 +381,8 @@ napi_value NapiBluetoothPan::IsTetheringOn(napi_env env, napi_callback_info info | |||
| 366 | 381 | ||
| 367 | napi_value NapiBluetoothPan::IsPanSupported(napi_env env, napi_callback_info info) | 382 | napi_value NapiBluetoothPan::IsPanSupported(napi_env env, napi_callback_info info) |
| 368 | { | 383 | { |
| 369 | - std::shared_ptr<NapiHaEventUtils> haUtils = std::make_shared<NapiHaEventUtils>(env, | 384 | + std::shared_ptr<NapiHaEventUtils> haUtils = |
| 370 | - "pan.IsPanSupported"); | 385 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(IsPanSupported)); |
| 371 | napi_status status = CheckEmptyParam(env, info); | 386 | napi_status status = CheckEmptyParam(env, info); |
| 372 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 387 | NAPI_BT_ASSERT_ERR_NUM_RETURN(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 373 | 388 | ||
| @@ -78,6 +78,7 @@ napi_value NapiPbapServer::DefineCreateProfile(napi_env env, napi_value exports) | |||
| 78 | 78 | ||
| 79 | napi_value NapiPbapServer::CreatePbapServerProfile(napi_env env, napi_callback_info info) | 79 | napi_value NapiPbapServer::CreatePbapServerProfile(napi_env env, napi_callback_info info) |
| 80 | { | 80 | { |
| 81 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(createPbapServerProfile)); | ||
| 81 | napi_value napiProfile; | 82 | napi_value napiProfile; |
| 82 | napi_value constructor = nullptr; | 83 | napi_value constructor = nullptr; |
| 83 | napi_get_reference_value(env, g_consRef_, &constructor); | 84 | napi_get_reference_value(env, g_consRef_, &constructor); |
| @@ -120,8 +121,10 @@ napi_value NapiPbapServer::ShareTypeInit(napi_env env) | |||
| 120 | 121 | ||
| 121 | napi_value NapiPbapServer::On(napi_env env, napi_callback_info info) | 122 | napi_value NapiPbapServer::On(napi_env env, napi_callback_info info) |
| 122 | { | 123 | { |
| 124 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 125 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(on)); | ||
| 123 | if (observer_) { | 126 | if (observer_) { |
| 124 | - auto status = observer_->eventSubscribe_.Register(env, info); | 127 | + auto status = observer_->eventSubscribe_.Register(env, info, haUtils); |
| 125 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 128 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 126 | } | 129 | } |
| 127 | return NapiGetUndefinedRet(env); | 130 | return NapiGetUndefinedRet(env); |
| @@ -129,8 +132,10 @@ napi_value NapiPbapServer::On(napi_env env, napi_callback_info info) | |||
| 129 | 132 | ||
| 130 | napi_value NapiPbapServer::Off(napi_env env, napi_callback_info info) | 133 | napi_value NapiPbapServer::Off(napi_env env, napi_callback_info info) |
| 131 | { | 134 | { |
| 135 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 136 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(off)); | ||
| 132 | if (observer_) { | 137 | if (observer_) { |
| 133 | - auto status = observer_->eventSubscribe_.Deregister(env, info); | 138 | + auto status = observer_->eventSubscribe_.Deregister(env, info, haUtils); |
| 134 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); | 139 | NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); |
| 135 | } | 140 | } |
| 136 | return NapiGetUndefinedRet(env); | 141 | return NapiGetUndefinedRet(env); |
| @@ -162,6 +167,7 @@ napi_value NapiPbapServer::GetConnectedDevices(napi_env env, napi_callback_info | |||
| 162 | 167 | ||
| 163 | napi_value NapiPbapServer::GetConnectionState(napi_env env, napi_callback_info info) | 168 | napi_value NapiPbapServer::GetConnectionState(napi_env env, napi_callback_info info) |
| 164 | { | 169 | { |
| 170 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getConnectionState)); | ||
| 165 | HILOGI("enter"); | 171 | HILOGI("enter"); |
| 166 | std::string remoteAddr{}; | 172 | std::string remoteAddr{}; |
| 167 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 173 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -182,6 +188,7 @@ napi_value NapiPbapServer::GetConnectionState(napi_env env, napi_callback_info i | |||
| 182 | 188 | ||
| 183 | napi_value NapiPbapServer::Disconnect(napi_env env, napi_callback_info info) | 189 | napi_value NapiPbapServer::Disconnect(napi_env env, napi_callback_info info) |
| 184 | { | 190 | { |
| 191 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(disconnect)); | ||
| 185 | HILOGI("enter"); | 192 | HILOGI("enter"); |
| 186 | std::string remoteAddr{}; | 193 | std::string remoteAddr{}; |
| 187 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); | 194 | bool checkRet = CheckDeivceIdParam(env, info, remoteAddr); |
| @@ -197,6 +204,8 @@ napi_value NapiPbapServer::Disconnect(napi_env env, napi_callback_info info) | |||
| 197 | 204 | ||
| 198 | napi_value NapiPbapServer::SetConnectionStrategy(napi_env env, napi_callback_info info) | 205 | napi_value NapiPbapServer::SetConnectionStrategy(napi_env env, napi_callback_info info) |
| 199 | { | 206 | { |
| 207 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 208 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setConnectionStrategy)); | ||
| 200 | HILOGI("enter"); | 209 | HILOGI("enter"); |
| 201 | std::string remoteAddr{}; | 210 | std::string remoteAddr{}; |
| 202 | int32_t strategy = 0; | 211 | int32_t strategy = 0; |
| @@ -210,7 +219,7 @@ napi_value NapiPbapServer::SetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 210 | HILOGI("err: %{public}d", errorCode); | 219 | HILOGI("err: %{public}d", errorCode); |
| 211 | return NapiAsyncWorkRet(errorCode); | 220 | return NapiAsyncWorkRet(errorCode); |
| 212 | }; | 221 | }; |
| 213 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 222 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 214 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 223 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 215 | asyncWork->Run(); | 224 | asyncWork->Run(); |
| 216 | return asyncWork->GetRet(); | 225 | return asyncWork->GetRet(); |
| @@ -218,6 +227,8 @@ napi_value NapiPbapServer::SetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 218 | 227 | ||
| 219 | napi_value NapiPbapServer::GetConnectionStrategy(napi_env env, napi_callback_info info) | 228 | napi_value NapiPbapServer::GetConnectionStrategy(napi_env env, napi_callback_info info) |
| 220 | { | 229 | { |
| 230 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 231 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getConnectionStrategy)); | ||
| 221 | HILOGI("enter"); | 232 | HILOGI("enter"); |
| 222 | std::string remoteAddr{}; | 233 | std::string remoteAddr{}; |
| 223 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 234 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -232,7 +243,7 @@ napi_value NapiPbapServer::GetConnectionStrategy(napi_env env, napi_callback_inf | |||
| 232 | auto object = std::make_shared<NapiNativeInt>(strategy); | 243 | auto object = std::make_shared<NapiNativeInt>(strategy); |
| 233 | return NapiAsyncWorkRet(errorCode, object); | 244 | return NapiAsyncWorkRet(errorCode, object); |
| 234 | }; | 245 | }; |
| 235 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 246 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 236 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 247 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 237 | asyncWork->Run(); | 248 | asyncWork->Run(); |
| 238 | return asyncWork->GetRet(); | 249 | return asyncWork->GetRet(); |
| @@ -259,6 +270,8 @@ napi_status CheckShareTypeParam(napi_env env, napi_callback_info info, std::stri | |||
| 259 | 270 | ||
| 260 | napi_value NapiPbapServer::SetShareType(napi_env env, napi_callback_info info) | 271 | napi_value NapiPbapServer::SetShareType(napi_env env, napi_callback_info info) |
| 261 | { | 272 | { |
| 273 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 274 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setShareType)); | ||
| 262 | HILOGI("enter"); | 275 | HILOGI("enter"); |
| 263 | std::string remoteAddr{}; | 276 | std::string remoteAddr{}; |
| 264 | int32_t shareType = 0; | 277 | int32_t shareType = 0; |
| @@ -272,7 +285,7 @@ napi_value NapiPbapServer::SetShareType(napi_env env, napi_callback_info info) | |||
| 272 | HILOGI("errorCode: %{public}d", errorCode); | 285 | HILOGI("errorCode: %{public}d", errorCode); |
| 273 | return NapiAsyncWorkRet(errorCode); | 286 | return NapiAsyncWorkRet(errorCode); |
| 274 | }; | 287 | }; |
| 275 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 288 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 276 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 289 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 277 | asyncWork->Run(); | 290 | asyncWork->Run(); |
| 278 | return asyncWork->GetRet(); | 291 | return asyncWork->GetRet(); |
| @@ -280,6 +293,8 @@ napi_value NapiPbapServer::SetShareType(napi_env env, napi_callback_info info) | |||
| 280 | 293 | ||
| 281 | napi_value NapiPbapServer::GetShareType(napi_env env, napi_callback_info info) | 294 | napi_value NapiPbapServer::GetShareType(napi_env env, napi_callback_info info) |
| 282 | { | 295 | { |
| 296 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 297 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getShareType)); | ||
| 283 | HILOGI("enter"); | 298 | HILOGI("enter"); |
| 284 | std::string remoteAddr{}; | 299 | std::string remoteAddr{}; |
| 285 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 300 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -294,7 +309,7 @@ napi_value NapiPbapServer::GetShareType(napi_env env, napi_callback_info info) | |||
| 294 | auto object = std::make_shared<NapiNativeInt>(shareType); | 309 | auto object = std::make_shared<NapiNativeInt>(shareType); |
| 295 | return NapiAsyncWorkRet(errorCode, object); | 310 | return NapiAsyncWorkRet(errorCode, object); |
| 296 | }; | 311 | }; |
| 297 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 312 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 298 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 313 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 299 | asyncWork->Run(); | 314 | asyncWork->Run(); |
| 300 | return asyncWork->GetRet(); | 315 | return asyncWork->GetRet(); |
| @@ -302,6 +317,8 @@ napi_value NapiPbapServer::GetShareType(napi_env env, napi_callback_info info) | |||
| 302 | 317 | ||
| 303 | napi_value NapiPbapServer::SetPhoneBookAccessAuthorization(napi_env env, napi_callback_info info) | 318 | napi_value NapiPbapServer::SetPhoneBookAccessAuthorization(napi_env env, napi_callback_info info) |
| 304 | { | 319 | { |
| 320 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 321 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(setPhoneBookAccessAuthorization)); | ||
| 305 | HILOGI("enter"); | 322 | HILOGI("enter"); |
| 306 | std::string remoteAddr{}; | 323 | std::string remoteAddr{}; |
| 307 | int32_t accessAuthorization = 0; | 324 | int32_t accessAuthorization = 0; |
| @@ -315,7 +332,7 @@ napi_value NapiPbapServer::SetPhoneBookAccessAuthorization(napi_env env, napi_ca | |||
| 315 | HILOGI("errorCode: %{public}d", errorCode); | 332 | HILOGI("errorCode: %{public}d", errorCode); |
| 316 | return NapiAsyncWorkRet(errorCode); | 333 | return NapiAsyncWorkRet(errorCode); |
| 317 | }; | 334 | }; |
| 318 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 335 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 319 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 336 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 320 | asyncWork->Run(); | 337 | asyncWork->Run(); |
| 321 | return asyncWork->GetRet(); | 338 | return asyncWork->GetRet(); |
| @@ -323,6 +340,8 @@ napi_value NapiPbapServer::SetPhoneBookAccessAuthorization(napi_env env, napi_ca | |||
| 323 | 340 | ||
| 324 | napi_value NapiPbapServer::GetPhoneBookAccessAuthorization(napi_env env, napi_callback_info info) | 341 | napi_value NapiPbapServer::GetPhoneBookAccessAuthorization(napi_env env, napi_callback_info info) |
| 325 | { | 342 | { |
| 343 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 344 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(getPhoneBookAccessAuthorization)); | ||
| 326 | HILOGI("enter"); | 345 | HILOGI("enter"); |
| 327 | std::string remoteAddr{}; | 346 | std::string remoteAddr{}; |
| 328 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); | 347 | auto status = CheckDeviceAddressParam(env, info, remoteAddr); |
| @@ -337,7 +356,7 @@ napi_value NapiPbapServer::GetPhoneBookAccessAuthorization(napi_env env, napi_ca | |||
| 337 | auto object = std::make_shared<NapiNativeInt>(accessAuthorization); | 356 | auto object = std::make_shared<NapiNativeInt>(accessAuthorization); |
| 338 | return NapiAsyncWorkRet(errorCode, object); | 357 | return NapiAsyncWorkRet(errorCode, object); |
| 339 | }; | 358 | }; |
| 340 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 359 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 341 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 360 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 342 | asyncWork->Run(); | 361 | asyncWork->Run(); |
| 343 | return asyncWork->GetRet(); | 362 | return asyncWork->GetRet(); |
| @@ -185,6 +185,8 @@ void HandleSppConnectResult(napi_env env, SppConnectCallbackInfo* callbackInfo) | |||
| 185 | 185 | ||
| 186 | napi_value NapiSppClient::SppConnect(napi_env env, napi_callback_info info) | 186 | napi_value NapiSppClient::SppConnect(napi_env env, napi_callback_info info) |
| 187 | { | 187 | { |
| 188 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 189 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(sppConnect)); | ||
| 188 | HILOGI("enter"); | 190 | HILOGI("enter"); |
| 189 | std::string deviceId; | 191 | std::string deviceId; |
| 190 | SppConnectCallbackInfo *callbackInfo = new SppConnectCallbackInfo(); | 192 | SppConnectCallbackInfo *callbackInfo = new SppConnectCallbackInfo(); |
| @@ -232,6 +234,7 @@ static napi_status CheckSppCloseClientSocketParams(napi_env env, napi_callback_i | |||
| 232 | 234 | ||
| 233 | napi_value NapiSppClient::SppCloseClientSocket(napi_env env, napi_callback_info info) | 235 | napi_value NapiSppClient::SppCloseClientSocket(napi_env env, napi_callback_info info) |
| 234 | { | 236 | { |
| 237 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(sppCloseClientSocket)); | ||
| 235 | HILOGI("enter"); | 238 | HILOGI("enter"); |
| 236 | std::shared_ptr<NapiSppClient> client = nullptr; | 239 | std::shared_ptr<NapiSppClient> client = nullptr; |
| 237 | int id = -1; | 240 | int id = -1; |
| @@ -325,6 +328,7 @@ static bool ShouldRefuseConnect(int32_t pid) | |||
| 325 | 328 | ||
| 326 | napi_value NapiSppClient::SppWrite(napi_env env, napi_callback_info info) | 329 | napi_value NapiSppClient::SppWrite(napi_env env, napi_callback_info info) |
| 327 | { | 330 | { |
| 331 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(sppWrite)); | ||
| 328 | HILOGI("enter"); | 332 | HILOGI("enter"); |
| 329 | uint8_t* totalBuf = nullptr; | 333 | uint8_t* totalBuf = nullptr; |
| 330 | size_t totalSize = 0; | 334 | size_t totalSize = 0; |
| @@ -581,6 +585,8 @@ static int WriteDataLoop(std::shared_ptr<OutputStream> outputStream, uint8_t* to | |||
| 581 | 585 | ||
| 582 | napi_value NapiSppClient::SppWriteAsync(napi_env env, napi_callback_info info) | 586 | napi_value NapiSppClient::SppWriteAsync(napi_env env, napi_callback_info info) |
| 583 | { | 587 | { |
| 588 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 589 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(sppWriteAsync)); | ||
| 584 | HILOGD("enter"); | 590 | HILOGD("enter"); |
| 585 | uint8_t* totalBuf = nullptr; | 591 | uint8_t* totalBuf = nullptr; |
| 586 | size_t totalSize = 0; | 592 | size_t totalSize = 0; |
| @@ -607,7 +613,7 @@ napi_value NapiSppClient::SppWriteAsync(napi_env env, napi_callback_info info) | |||
| 607 | return NapiAsyncWorkRet(err); | 613 | return NapiAsyncWorkRet(err); |
| 608 | }; | 614 | }; |
| 609 | 615 | ||
| 610 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 616 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 611 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 617 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 612 | 618 | ||
| 613 | asyncWork->Run(); | 619 | asyncWork->Run(); |
| @@ -644,6 +650,8 @@ static int ReadData(std::shared_ptr<InputStream> inputStream, int bufSize, SppCa | |||
| 644 | 650 | ||
| 645 | napi_value NapiSppClient::SppReadAsync(napi_env env, napi_callback_info info) | 651 | napi_value NapiSppClient::SppReadAsync(napi_env env, napi_callback_info info) |
| 646 | { | 652 | { |
| 653 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 654 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(sppReadAsync)); | ||
| 647 | HILOGD("enter"); | 655 | HILOGD("enter"); |
| 648 | int id = -1; | 656 | int id = -1; |
| 649 | auto status = CheckSppReadParams(env, info, id); | 657 | auto status = CheckSppReadParams(env, info, id); |
| @@ -675,7 +683,7 @@ napi_value NapiSppClient::SppReadAsync(napi_env env, napi_callback_info info) | |||
| 675 | client->sppReadFlag = false; | 683 | client->sppReadFlag = false; |
| 676 | return NapiAsyncWorkRet(err, object); | 684 | return NapiAsyncWorkRet(err, object); |
| 677 | }; | 685 | }; |
| 678 | - auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK); | 686 | + auto asyncWork = NapiAsyncWorkFactory::CreateAsyncWork(env, info, func, ASYNC_WORK_NO_NEED_CALLBACK, haUtils); |
| 679 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); | 687 | NAPI_BT_ASSERT_RETURN_UNDEF(env, asyncWork, BT_ERR_INTERNAL_ERROR); |
| 680 | asyncWork->Run(); | 688 | asyncWork->Run(); |
| 681 | return asyncWork->GetRet(); | 689 | return asyncWork->GetRet(); |
| @@ -694,6 +702,7 @@ static napi_status CheckSppFdParams(napi_env env, napi_callback_info info, int & | |||
| 694 | 702 | ||
| 695 | napi_value NapiSppClient::GetDeviceId(napi_env env, napi_callback_info info) | 703 | napi_value NapiSppClient::GetDeviceId(napi_env env, napi_callback_info info) |
| 696 | { | 704 | { |
| 705 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getDeviceId)); | ||
| 697 | HILOGD("enter"); | 706 | HILOGD("enter"); |
| 698 | int id = -1; | 707 | int id = -1; |
| 699 | auto status = CheckSppFdParams(env, info, id); | 708 | auto status = CheckSppFdParams(env, info, id); |
| @@ -711,6 +720,7 @@ napi_value NapiSppClient::GetDeviceId(napi_env env, napi_callback_info info) | |||
| 711 | 720 | ||
| 712 | napi_value NapiSppClient::IsConnected(napi_env env, napi_callback_info info) | 721 | napi_value NapiSppClient::IsConnected(napi_env env, napi_callback_info info) |
| 713 | { | 722 | { |
| 723 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(isConnected)); | ||
| 714 | HILOGD("enter"); | 724 | HILOGD("enter"); |
| 715 | bool isConnected = false; | 725 | bool isConnected = false; |
| 716 | int id = -1; | 726 | int id = -1; |
| @@ -731,6 +741,7 @@ napi_value NapiSppClient::IsConnected(napi_env env, napi_callback_info info) | |||
| 731 | 741 | ||
| 732 | napi_value NapiSppClient::GetMaxReceiveDataSize(napi_env env, napi_callback_info info) | 742 | napi_value NapiSppClient::GetMaxReceiveDataSize(napi_env env, napi_callback_info info) |
| 733 | { | 743 | { |
| 744 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getMaxReceiveDataSize)); | ||
| 734 | HILOGD("enter"); | 745 | HILOGD("enter"); |
| 735 | int id = -1; | 746 | int id = -1; |
| 736 | auto status = CheckSppFdParams(env, info, id); | 747 | auto status = CheckSppFdParams(env, info, id); |
| @@ -747,6 +758,7 @@ napi_value NapiSppClient::GetMaxReceiveDataSize(napi_env env, napi_callback_info | |||
| 747 | 758 | ||
| 748 | napi_value NapiSppClient::GetMaxTransmitDataSize(napi_env env, napi_callback_info info) | 759 | napi_value NapiSppClient::GetMaxTransmitDataSize(napi_env env, napi_callback_info info) |
| 749 | { | 760 | { |
| 761 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getMaxTransmitDataSize)); | ||
| 750 | HILOGD("enter"); | 762 | HILOGD("enter"); |
| 751 | int id = -1; | 763 | int id = -1; |
| 752 | auto status = CheckSppFdParams(env, info, id); | 764 | auto status = CheckSppFdParams(env, info, id); |
| @@ -57,11 +57,15 @@ void DefineSppFunctions(napi_env env, napi_value exports) | |||
| 57 | 57 | ||
| 58 | napi_value NapiSppServer::RegisterSocketObserver(napi_env env, napi_callback_info info) | 58 | napi_value NapiSppServer::RegisterSocketObserver(napi_env env, napi_callback_info info) |
| 59 | { | 59 | { |
| 60 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(on)); | ||
| 61 | + haUtils.CaptureSubscribeEventName(env, info); | ||
| 60 | return NapiSppClient::On(env, info); | 62 | return NapiSppClient::On(env, info); |
| 61 | } | 63 | } |
| 62 | 64 | ||
| 63 | napi_value NapiSppServer::DeRegisterSocketObserver(napi_env env, napi_callback_info info) | 65 | napi_value NapiSppServer::DeRegisterSocketObserver(napi_env env, napi_callback_info info) |
| 64 | { | 66 | { |
| 67 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(off)); | ||
| 68 | + haUtils.CaptureSubscribeEventName(env, info); | ||
| 65 | return NapiSppClient::Off(env, info); | 69 | return NapiSppClient::Off(env, info); |
| 66 | } | 70 | } |
| 67 | 71 | ||
| @@ -122,6 +126,8 @@ static napi_status CheckSppListenParams( | |||
| 122 | 126 | ||
| 123 | napi_value NapiSppServer::SppListen(napi_env env, napi_callback_info info) | 127 | napi_value NapiSppServer::SppListen(napi_env env, napi_callback_info info) |
| 124 | { | 128 | { |
| 129 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 130 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(sppListen)); | ||
| 125 | HILOGD("enter"); | 131 | HILOGD("enter"); |
| 126 | string name; | 132 | string name; |
| 127 | SppListenCallbackInfo *callbackInfo = new (std::nothrow) SppListenCallbackInfo(); | 133 | SppListenCallbackInfo *callbackInfo = new (std::nothrow) SppListenCallbackInfo(); |
| @@ -241,6 +247,8 @@ static napi_status CheckSppAcceptParams( | |||
| 241 | 247 | ||
| 242 | napi_value NapiSppServer::SppAccept(napi_env env, napi_callback_info info) | 248 | napi_value NapiSppServer::SppAccept(napi_env env, napi_callback_info info) |
| 243 | { | 249 | { |
| 250 | + std::shared_ptr<NapiHaEventUtils> haUtils = | ||
| 251 | + std::make_shared<NapiHaEventUtils>(env, BT_HA_API_NAME(sppAccept)); | ||
| 244 | HILOGD("enter"); | 252 | HILOGD("enter"); |
| 245 | int32_t serverSocketNum = -1; | 253 | int32_t serverSocketNum = -1; |
| 246 | SppAcceptCallbackInfo *callbackInfo = new (std::nothrow) SppAcceptCallbackInfo(); | 254 | SppAcceptCallbackInfo *callbackInfo = new (std::nothrow) SppAcceptCallbackInfo(); |
| @@ -332,6 +340,7 @@ static napi_status CheckSppCloseServerSockeParams(napi_env env, napi_callback_in | |||
| 332 | 340 | ||
| 333 | napi_value NapiSppServer::SppCloseServerSocket(napi_env env, napi_callback_info info) | 341 | napi_value NapiSppServer::SppCloseServerSocket(napi_env env, napi_callback_info info) |
| 334 | { | 342 | { |
| 343 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(sppCloseServerSocket)); | ||
| 335 | HILOGD("enter"); | 344 | HILOGD("enter"); |
| 336 | int id = -1; | 345 | int id = -1; |
| 337 | auto status = CheckSppCloseServerSockeParams(env, info, id); | 346 | auto status = CheckSppCloseServerSockeParams(env, info, id); |
| @@ -379,6 +388,7 @@ static napi_status CheckSppFdParams(napi_env env, napi_callback_info info, int & | |||
| 379 | 388 | ||
| 380 | napi_value NapiSppServer::getL2capPsm(napi_env env, napi_callback_info info) | 389 | napi_value NapiSppServer::getL2capPsm(napi_env env, napi_callback_info info) |
| 381 | { | 390 | { |
| 391 | + NapiHaEventUtils haUtils(env, BT_HA_API_NAME(getL2capPsm)); | ||
| 382 | HILOGD("enter"); | 392 | HILOGD("enter"); |
| 383 | int id = -1; | 393 | int id = -1; |
| 384 | auto status = CheckSppFdParams(env, info, id); | 394 | auto status = CheckSppFdParams(env, info, id); |