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 41 #ifdef BLUETOOTH_API_SINCE_10 42 static napi_value NotifyCharacteristicChangedEx(napi_env env, napi_callback_info info); 43 #else 44 static napi_value NotifyCharacteristicChanged(napi_env env, napi_callback_info info); 45 #endif 46 GetServer()47 std::shared_ptr<GattServer> &GetServer() 48 { 49 return server_; 50 } GetCallback()51 NapiGattServerCallback &GetCallback() 52 { 53 return callback_; 54 } 55 static std::vector<std::string> deviceList; 56 NapiGattServer()57 NapiGattServer() 58 { 59 HILOGI("enter"); 60 server_ = GattServer::CreateInstance(callback_); 61 } 62 ~NapiGattServer() = default; 63 64 static thread_local napi_ref consRef_; 65 66 private: 67 std::shared_ptr<GattServer> server_ = nullptr; 68 NapiGattServerCallback callback_; 69 }; 70 } // namespace Bluetooth 71 } // namespace OHOS 72 #endif /* NAPI_BLUETOOTH_GATT_SERVER_H_ */