1 /* 2 * Copyright (C) 2022 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 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines a bluetooth system that provides basic bluetooth connection and profile functions, 21 * including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc. 22 * 23 */ 24 25 /** 26 * @file bluetooth_pan.h 27 * 28 * @brief Declares PAN role framework functions, including basic and observer functions. 29 * 30 */ 31 #ifndef BLUETOOTH_PAN_H 32 #define BLUETOOTH_PAN_H 33 34 #include <string> 35 #include <vector> 36 #include <memory> 37 38 #include "bluetooth_def.h" 39 #include "bluetooth_remote_device.h" 40 #include "bluetooth_types.h" 41 namespace OHOS { 42 namespace Bluetooth { 43 /** 44 * @brief Class for pan observer functions. 45 * 46 */ 47 class PanObserver { 48 public: 49 /** 50 * @brief The observer function to notify connection state changed. 51 * 52 * @param device Remote device object. 53 * @param state Connection state. 54 */ OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state)55 virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state) 56 {} 57 58 /** 59 * @brief Destroy the PanObserver object. 60 * 61 */ ~PanObserver()62 virtual ~PanObserver() 63 {} 64 }; 65 66 /** 67 * @brief Class for Pan API. 68 * 69 */ 70 class BLUETOOTH_API Pan { 71 public: 72 /** 73 * @brief Get the instance of Pan object. 74 * 75 * @return Returns the pointer to the Pan instance. 76 */ 77 static Pan *GetProfile(); 78 79 /** 80 * @brief Get remote Pan device list which are in the specified states. 81 * 82 * @param states List of remote device states. 83 * @return Returns the list of devices. 84 */ 85 int32_t GetDevicesByStates(std::vector<int> states, std::vector<BluetoothRemoteDevice> &result); 86 87 /** 88 * @brief Get the connection state of the specified remote Pan device. 89 * 90 * @param device Remote device object. 91 * @return Returns the connection state of the remote device. 92 */ 93 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state); 94 95 /** 96 * @brief Release the connection from remote Pan device. 97 * 98 * @param device Remote device object. 99 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 100 */ 101 int32_t Disconnect(const BluetoothRemoteDevice &device); 102 103 /** 104 * @brief Register Pan observer instance. 105 * 106 * @param observer Pan observer instance. 107 */ 108 void RegisterObserver(PanObserver *observer); 109 110 /** 111 * @brief Deregister Pan observer instance. 112 * 113 * @param observer Pan observer instance. 114 */ 115 void DeregisterObserver(PanObserver *observer); 116 117 /** 118 * @brief Set Tethering 119 * 120 * @param value Set Network Sharing. 121 */ 122 int32_t SetTethering(bool value); 123 124 /** 125 * @brief Is Tethering On. 126 * 127 */ 128 int32_t IsTetheringOn(bool &value); 129 130 /** 131 * @brief The external process calls the Pan profile interface before the Bluetooth process starts. At this 132 * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the 133 * Pan proflie. 134 */ 135 void Init(); 136 137 /** 138 * @brief Static Pan observer instance. 139 * 140 */ 141 static PanObserver *instance_; 142 143 private: 144 Pan(); 145 ~Pan(); 146 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(Pan); 147 BLUETOOTH_DECLARE_IMPL(); 148 }; 149 } // namespace Bluetooth 150 } // namespace OHOS 151 #endif // BLUETOOTH_PAN_H