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 #ifndef NAPI_BLUETOOTH_SPP_SERVER_H_ 16 #define NAPI_BLUETOOTH_SPP_SERVER_H_ 17 18 #include <map> 19 #include "bluetooth_socket.h" 20 #include "napi_bluetooth_spp_client.h" 21 22 namespace OHOS { 23 namespace Bluetooth { 24 struct SppListenCallbackInfo : public AsyncCallbackInfo { 25 std::shared_ptr<ServerSocket> server_ = nullptr; 26 std::string name_ = ""; 27 std::shared_ptr<SppOption> sppOption_; 28 }; 29 30 struct SppAcceptCallbackInfo : public AsyncCallbackInfo { 31 std::shared_ptr<ServerSocket> server_ = nullptr; 32 std::shared_ptr<ClientSocket> client_ = nullptr; 33 }; 34 35 void DefineSppFunctions(napi_env env, napi_value exports); 36 void SppPropertyValueInit(napi_env env, napi_value exports); 37 38 struct NapiSppServer { 39 static napi_value SppListen(napi_env env, napi_callback_info info); 40 static napi_value SppAccept(napi_env env, napi_callback_info info); 41 static napi_value SppConnect(napi_env env, napi_callback_info info); 42 static napi_value SppCloseServerSocket(napi_env env, napi_callback_info info); 43 static napi_value RegisterSocketObserver(napi_env env, napi_callback_info info); 44 static napi_value DeRegisterSocketObserver(napi_env env, napi_callback_info info); 45 46 static std::map<int, std::shared_ptr<NapiSppServer>> serverMap; 47 static int count; 48 49 std::shared_ptr<ServerSocket> server_ = nullptr; 50 int id_ = -1; 51 }; 52 } // namespace Bluetooth 53 } // namespace OHOS 54 #endif /* NAPI_BLUETOOTH_SPP_SERVER_H_ */