1 /* 2 * Copyright (C) 2021 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_BLUETOOTH_GATT_SERVER_H_ 17 #define NAPI_BLUETOOTH_GATT_SERVER_H_ 18 19 #include <vector> 20 #include "bluetooth_gatt_server.h" 21 #include "bluetooth_log.h" 22 #include "napi_bluetooth_gatt_server_callback.h" 23 24 namespace OHOS { 25 namespace Bluetooth { 26 class NapiGattServer { 27 28 public: 29 static napi_value CreateGattServer(napi_env env, napi_callback_info info); 30 static void DefineGattServerJSClass(napi_env env); 31 static napi_value GattServerConstructor(napi_env env, napi_callback_info info); 32 33 static napi_value On(napi_env env, napi_callback_info info); 34 static napi_value Off(napi_env env, napi_callback_info info); 35 36 static napi_value AddService(napi_env env, napi_callback_info info); 37 static napi_value Close(napi_env env, napi_callback_info info); 38 static napi_value RemoveGattService(napi_env env, napi_callback_info info); 39 static napi_value SendResponse(napi_env env, napi_callback_info info); 40 static napi_value NotifyCharacteristicChanged(napi_env env, napi_callback_info info); 41 GetServer()42 std::shared_ptr<GattServer> &GetServer() 43 { 44 return server_; 45 } GetCallback()46 NapiGattServerCallback &GetCallback() 47 { 48 return callback_; 49 } 50 static std::vector<std::string> deviceList; 51 NapiGattServer()52 NapiGattServer() 53 { 54 HILOGI("enter"); 55 server_ = std::make_shared<GattServer>(callback_); 56 } 57 ~NapiGattServer() = default; 58 59 static thread_local napi_ref consRef_; 60 61 private: 62 std::shared_ptr<GattServer> server_ = nullptr; 63 NapiGattServerCallback callback_; 64 }; 65 } // namespace Bluetooth 66 } // namespace OHOS 67 #endif /* NAPI_BLUETOOTH_GATT_SERVER_H_ */