1 /* 2 * Copyright (C) Huawei Device Co., Ltd. 2025-2025. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NAPI_HA_EVENT_UTILS_H 17 #define NAPI_HA_EVENT_UTILS_H 18 19 #include <iostream> 20 #include <string> 21 #include "safe_map.h" 22 #include "napi/native_api.h" 23 24 namespace OHOS { 25 namespace Bluetooth { 26 27 class NapiHaEventUtils { 28 public: 29 NapiHaEventUtils(napi_env env, const std::string &apiName); 30 ~NapiHaEventUtils(); 31 void WriteErrCode(const int32_t errCode); 32 static void WriteErrCode(napi_env env, const int32_t errCode); 33 34 private: 35 NapiHaEventUtils() = delete; 36 static void GenerateProcessorId(); 37 static int64_t AddProcessor(); 38 std::string RandomTransId() const; 39 int64_t GetNowTimeMs() const; 40 void WriteEndEvent() const; 41 42 private: 43 static int64_t processorId_; 44 static std::mutex processorLock_; 45 static SafeMap<napi_env, int32_t> envErrCodeMap_; // mapping between napi_env and errCode 46 napi_env env_; 47 std::string apiName_; 48 int64_t beginTime_; 49 }; 50 51 } // namespace Bluetooth 52 } // namespace OHOS 53 #endif /* NAPI_HA_EVENT_UTILS_H */ 54