• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_H_
16 #define NAPI_BLUETOOTH_SPP_CLIENT_H_
17 
18 #include <thread>
19 #include <map>
20 #include "bluetooth_socket.h"
21 #include "napi_bluetooth_utils.h"
22 
23 namespace OHOS {
24 namespace Bluetooth {
25 const std::string STR_BT_SPP_READ = "sppRead";
26 
27 struct NapiSppClient {
28     static napi_value SppConnect(napi_env env, napi_callback_info info);
29     static napi_value SppCloseClientSocket(napi_env env, napi_callback_info info);
30     static napi_value SppWrite(napi_env env, napi_callback_info info);
31     static napi_value On(napi_env env, napi_callback_info info);
32     static napi_value Off(napi_env env, napi_callback_info info);
33     static void SppRead(int id);
34 
35     static std::map<int, std::shared_ptr<NapiSppClient>> clientMap;
36     static int count;
37 
38     bool sppReadFlag = false;
39     std::map<std::string, std::shared_ptr<BluetoothCallbackInfo>> callbackInfos_ = {};
40 
41     std::shared_ptr<SppClientSocket> client_ = nullptr;
42     std::shared_ptr<BluetoothRemoteDevice> device_ = nullptr;
43     std::shared_ptr<std::thread> thread_;
44     int id_ = -1;
45 };
46 } // namespace Bluetooth
47 } // namespace OHOS
48 #endif /* NAPI_BLUETOOTH_SPP_CLIENT_H_ */