1 /* 2 * Copyright (C) 2023 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 BLUETOOTH_PBAP_PSE_H 17 #define BLUETOOTH_PBAP_PSE_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 #include "bluetooth_def.h" 23 #include "bluetooth_remote_device.h" 24 #include "bluetooth_types.h" 25 26 namespace OHOS { 27 namespace Bluetooth { 28 /** 29 * @brief Class for Pbap PSE observer functions. 30 * 31 */ 32 class PbapPseObserver { 33 public: 34 /** 35 * @brief Destroy the PbapPseObserver object. 36 * 37 */ 38 virtual ~PbapPseObserver() = default; 39 40 /** 41 * @brief The observer function to notify connection state changed. 42 * 43 * @param device Remote device object. 44 * @param state Connection state. 45 */ OnConnectionStateChanged(const BluetoothRemoteDevice & device,int32_t state)46 virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int32_t state) 47 {} 48 }; 49 50 /** 51 * @brief Class for Pbap Server API. 52 * 53 */ 54 class BLUETOOTH_API PbapPse { 55 public: 56 /** 57 * @brief Get the instance of PbapPse object. 58 * 59 * @return Returns the pointer to the PbapPse instance. 60 */ 61 static PbapPse *GetProfile(); 62 63 /** 64 * @brief Register PbapPse observer instance. 65 * 66 * @param observer PbapPse observer instance. 67 */ 68 void RegisterObserver(std::shared_ptr<PbapPseObserver> observer); 69 70 /** 71 * @brief Deregister PbapPse observer instance. 72 * 73 * @param observer PbapPse observer instance. 74 */ 75 void DeregisterObserver(std::shared_ptr<PbapPseObserver> observer); 76 77 /** 78 * @brief Get remote pbap pse device list which are in the specified states. 79 * 80 * @param states List of remote device states. 81 * @param result the list of devices 82 * @return Returns operate result. 83 */ 84 int32_t GetDevicesByStates(const std::vector<int32_t> &states, std::vector<BluetoothRemoteDevice> &result) const; 85 86 /** 87 * @brief Get the connection state of the specified remote pbap device. 88 * 89 * @param device Remote device object. 90 * @param state the connection state of the remote device 91 * @return Returns operate result. 92 */ 93 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state) const; 94 95 /** 96 * @brief Release the connection from remote pbap device. 97 * 98 * @param device Remote device object. 99 * @return Returns operate result. 100 */ 101 int32_t Disconnect(const BluetoothRemoteDevice &device); 102 103 /** 104 * @brief Set connection strategy for remote bluetooth device. 105 * 106 * @param device Remote device object. 107 * @param strategy The device connect strategy. 108 * @return Returns operate result 109 */ 110 int32_t SetConnectionStrategy(const BluetoothRemoteDevice &device, int32_t strategy); 111 112 /** 113 * @brief Get connection strategy of remote bluetooth device. 114 * 115 * @param device The address of the peer bluetooth device. 116 * @param strategy The device connect strategy. 117 * @return Returns operate result. 118 */ 119 int32_t GetConnectionStrategy(const BluetoothRemoteDevice &device, int32_t &strategy) const; 120 121 /** 122 * @brief Set share type for remote bluetooth device. 123 * 124 * @param device Remote device object. 125 * @param shareType The share type. 126 * @return Returns operate result 127 */ 128 int32_t SetShareType(const BluetoothRemoteDevice &device, int32_t shareType); 129 130 /** 131 * @brief Get share type of remote bluetooth device. 132 * 133 * @param device The address of the peer bluetooth device. 134 * @param shareType The share type. 135 * @return Returns operate result. 136 */ 137 int32_t GetShareType(const BluetoothRemoteDevice &device, int32_t &shareType) const; 138 139 /** 140 * @brief Set accessAuthorization for remote bluetooth device. 141 * 142 * @param device Remote device object. 143 * @param accessAuthorization The accessAuthorization. 144 * @return Returns operate result 145 */ 146 int32_t SetPhoneBookAccessAuthorization(const BluetoothRemoteDevice &device, int32_t accessAuthorization); 147 148 /** 149 * @brief Get accessAuthorization of remote bluetooth device. 150 * 151 * @param device The address of the peer bluetooth device. 152 * @param accessAuthorization The accessAuthorization. 153 * @return Returns operate result. 154 */ 155 int32_t GetPhoneBookAccessAuthorization(const BluetoothRemoteDevice &device, int32_t &accessAuthorization) const; 156 157 void Init(); 158 void Uinit(); 159 160 private: 161 /** 162 * @brief constructor. 163 * 164 */ 165 PbapPse(); 166 167 /** 168 * @brief deconstructor. 169 * 170 */ 171 ~PbapPse(); 172 173 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(PbapPse); 174 BLUETOOTH_DECLARE_IMPL(); 175 }; 176 } // namespace Bluetooth 177 } // namespace OHOS 178 #endif // BLUETOOTH_PBAP_PSE_H