1 /* 2 * Copyright (C) 2025 Huawei Device Co., Ltd. 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_SOFTBUS_LINK_ENHANCE_SERVER_H_ 17 #define NAPI_SOFTBUS_LINK_ENHANCE_SERVER_H_ 18 19 #include "napi_link_enhance_utils.h" 20 21 namespace Communication { 22 namespace OHOS::Softbus { 23 class NapiLinkEnhanceServer { 24 25 public: 26 static napi_value Create(napi_env env, napi_callback_info info); 27 static void DefineJSClass(napi_env env); 28 static napi_value Constructor(napi_env env, napi_callback_info info); 29 30 static napi_value On(napi_env env, napi_callback_info info); 31 static napi_value Off(napi_env env, napi_callback_info info); 32 33 static napi_value Start(napi_env env, napi_callback_info info); 34 static napi_value Stop(napi_env env, napi_callback_info info); 35 static napi_value Close(napi_env env, napi_callback_info info); 36 NapiLinkEnhanceServer(const std::string & name)37 NapiLinkEnhanceServer(const std::string &name) 38 { 39 this->name_ = name; 40 } 41 ~NapiLinkEnhanceServer() = default; 42 bool IsAcceptedEnable(); 43 bool IsStopEnable(); 44 static std::unordered_map<std::string, NapiLinkEnhanceServer *> enhanceServerMap_; 45 static std::mutex serverMapMutex_; 46 47 static thread_local napi_ref consRef_; 48 49 napi_ref acceptConnectRef_ = nullptr; 50 napi_ref serverStopRef_ = nullptr; 51 napi_env env_ = nullptr; 52 53 std::string name_ = ""; 54 private: 55 std::recursive_timed_mutex lock_; 56 bool isAcceptedEnable_ = false; 57 bool isStopEnable_ = false; SetAcceptedEnable(bool isAcceptedEnable)58 void SetAcceptedEnable(bool isAcceptedEnable) 59 { 60 this->lock_.lock(); 61 this->isAcceptedEnable_ = isAcceptedEnable; 62 this->lock_.unlock(); 63 } SetStopEnable(bool isStopEnable)64 void SetStopEnable(bool isStopEnable) 65 { 66 this->lock_.lock(); 67 this->isStopEnable_ = isStopEnable; 68 this->lock_.unlock(); 69 } 70 }; 71 } // namespace SoftBus 72 } // namespace Communication 73 #endif /* NAPI_SOFTBUS_LINK_ENHANCE_SERVER_H_ */ 74