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_opp.h 27 * 28 * @brief Declares OPP role framework functions, including basic and observer functions. 29 * 30 */ 31 #ifndef BLUETOOTH_OPP_H 32 #define BLUETOOTH_OPP_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 #include "bluetooth_no_destructor.h" 42 namespace OHOS { 43 namespace Bluetooth { 44 /** 45 * @brief Bluetooth Opp Transfer Information. 46 * 47 * @since 9 48 */ 49 class BLUETOOTH_API BluetoothOppTransferInformation { 50 public: 51 /** 52 * @brief A constructor used to create a <b>BluetoothOppTransferInformation</b> instance. 53 * 54 * @since 6 55 */ 56 BluetoothOppTransferInformation(); 57 58 /** 59 * @brief A destructor used to delete the <b>BluetoothOppTransferInformation</b> instance. 60 * 61 * @since 6 62 */ 63 ~BluetoothOppTransferInformation(); 64 65 /** 66 * @brief Get Id. 67 * 68 * @return Returns Id. 69 * @since 6 70 */ 71 int GetId() const; 72 73 /** 74 * @brief Get File Name. 75 * 76 * @return File Name. 77 * @since 6 78 */ 79 std::string GetFileName() const; 80 81 /** 82 * @brief Get File Path. 83 * 84 * @return Returns File Path. 85 * @since 6 86 */ 87 std::string GetFilePath() const; 88 89 /** 90 * @brief Get Mime Type. 91 * 92 * @since 6 93 */ 94 std::string GetMimeType() const; 95 96 /** 97 * @brief Get Device Name. 98 * 99 * @return Returns Device Name. 100 * @since 6 101 */ 102 std::string GetDeviceName() const; 103 104 /** 105 * @brief Get Device Address. 106 * 107 * @return Returns Device Address. 108 * @since 6 109 */ 110 std::string GetDeviceAddress() const; 111 112 /** 113 * @brief Get Direction. 114 * 115 * @return Returns Direction. 116 * @since 6 117 */ 118 int GetDirection() const; 119 120 /** 121 * @brief Get Status. 122 * 123 * @return Returns Status. 124 * @since 6 125 */ 126 int GetStatus() const; 127 128 /** 129 * @brief Get Failed Reason. 130 * 131 * @return Returns Failed Reason. 132 * @since 6 133 */ 134 int GetFailedReason() const; 135 136 /** 137 * @brief Get Time Stamp. 138 * 139 * @return TimeStamp. 140 * @since 6 141 */ 142 uint64_t GetTimeStamp() const; 143 144 /** 145 * @brief Get Current Bytes. 146 * 147 * @return Returns Current Bytes. 148 * @since 6 149 */ 150 uint64_t GetCurrentBytes() const; 151 152 /** 153 * @brief Get Total Bytes. 154 * 155 * @return Returns TotalBytes. 156 * @since 6 157 */ 158 uint64_t GetTotalBytes() const; 159 160 /** 161 * @brief Set Id. 162 * 163 * @param interval Id. 164 * @since 6 165 */ 166 void SetId(int id); 167 168 /** 169 * @brief Set File Name. 170 * 171 * @param interval File Name. 172 * @since 6 173 */ 174 void SetFileName(std::string fileName); 175 176 /** 177 * @brief Set File Path. 178 * 179 * @param interval File Path. 180 * @since 6 181 */ 182 void SetFilePath(std::string filePath); 183 184 /** 185 * @brief Set Mime Type. 186 * 187 * @param interval Mime Type. 188 * @since 6 189 */ 190 void SetMimeType(std::string mimeType); 191 192 /** 193 * @brief Set Device Name. 194 * 195 * @param interval Device Name. 196 * @since 6 197 */ 198 void SetDeviceName(std::string deviceName); 199 200 /** 201 * @brief Set Device Address. 202 * 203 * @param interval Device Address. 204 * @since 6 205 */ 206 void SetDeviceAddress(std::string deviceAddress); 207 208 /** 209 * @brief Set Direction. 210 * 211 * @param interval Direction. 212 * @since 6 213 */ 214 void SetDirection(int direction); 215 216 /** 217 * @brief Set Status. 218 * 219 * @param interval Status. 220 * @since 6 221 */ 222 void SetStatus(int status); 223 224 /** 225 * @brief Set Failed Reason. 226 * 227 * @param interval Failed Reason. 228 * @since 6 229 */ 230 void SetFailedReason(int failedReason); 231 232 /** 233 * @brief Set Time Stamp. 234 * 235 * @param interval Time Stamp. 236 * @since 6 237 */ 238 void SetTimeStamp(uint64_t timeStamp); 239 240 /** 241 * @brief Set Current Bytes. 242 * 243 * @param interval Current Bytes. 244 * @since 6 245 */ 246 void SetCurrentBytes(uint64_t currentBytes); 247 248 /** 249 * @brief Set Total Bytes. 250 * 251 * @param interval Total Bytes. 252 * @since 6 253 */ 254 void SetTotalBytes(uint64_t totalBytes); 255 256 private: 257 int id_ = -1; 258 std::string fileName_; 259 std::string filePath_; 260 std::string mimeType_; 261 std::string deviceName_; 262 std::string deviceAddress_; 263 int direction_ = 0; 264 int status_ = 0; 265 int failedReason_ = 0; 266 uint64_t timeStamp_ = 0; 267 uint64_t currentBytes_ = 0; 268 uint64_t totalBytes_ = 0; 269 }; 270 271 /** 272 * @brief Class for Opp Host observer functions. 273 * 274 */ 275 class OppObserver { 276 public: 277 /** 278 * @brief The observer function to notify receive incoming file changed. 279 * 280 * @param transferInformation transfer Information. 281 */ OnReceiveIncomingFileChanged(const BluetoothOppTransferInformation & transferInformation)282 virtual void OnReceiveIncomingFileChanged(const BluetoothOppTransferInformation &transferInformation) 283 {} 284 285 /** 286 * @brief The observer function to notify transfer state changed. 287 * 288 * @param transferInformation transfer Information. 289 */ OnTransferStateChanged(const BluetoothOppTransferInformation & transferInformation)290 virtual void OnTransferStateChanged(const BluetoothOppTransferInformation &transferInformation) 291 {} 292 293 /** 294 * @brief Destroy the OppObserver object. 295 * 296 */ ~OppObserver()297 virtual ~OppObserver() 298 {} 299 }; 300 301 /** 302 * @brief Class for Opp API. 303 * 304 */ 305 class BLUETOOTH_API Opp { 306 public: 307 /** 308 * @brief Get the instance of Opp object. 309 * 310 * @return Returns the pointer to the Opp instance. 311 */ 312 static Opp *GetProfile(); 313 314 /** 315 * @brief Send File. 316 * 317 * @return Return operate result to confirm whether the file is successfully sent. 318 */ 319 int32_t SendFile(std::string device, std::vector<std::string> filePaths, 320 std::vector<std::string> mimeTypes, bool& result); 321 322 /** 323 * @brief Set Incoming File Confirmation. 324 * 325 * @return Return operate result to confirm whether the setting is successful. 326 */ 327 int32_t SetIncomingFileConfirmation(bool accept); 328 329 /** 330 * @brief Get Current Transfer Information. 331 * 332 * @return Return operate result to getCurrentTransferInformation. 333 */ 334 int32_t GetCurrentTransferInformation(BluetoothOppTransferInformation &transferInformation); 335 336 /** 337 * @brief Cancel Transfer. 338 * 339 * @return Return operate result to confirm whether the cancellation is set successfully. 340 */ 341 int32_t CancelTransfer(bool& result); 342 343 /** 344 * @brief Get remote opp device list which are in the specified states. 345 * 346 * @param states List of remote device states. 347 * @param result the list of devices 348 * @return Returns operate result. 349 */ 350 int32_t GetDevicesByStates(const std::vector<int32_t> &states, std::vector<BluetoothRemoteDevice> &result) const; 351 352 /** 353 * @brief Get the connection state of the specified remote opp device. 354 * 355 * @param device Remote device object. 356 * @param result the connection state of the remote device 357 * @return Returns operate result. 358 */ 359 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &result) const; 360 361 /** 362 * @brief Register Opp observer instance. 363 * 364 * @param observer Opp observer instance. 365 */ 366 void RegisterObserver(std::shared_ptr<OppObserver> observer); 367 368 /** 369 * @brief Deregister Opp observer instance. 370 * 371 * @param observer Opp observer instance. 372 */ 373 void DeregisterObserver(std::shared_ptr<OppObserver> observer); 374 375 /** 376 * @brief The external process calls the Opp profile interface before the Bluetooth process starts. At this 377 * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the 378 * Opp proflie. 379 */ 380 void Init(); 381 382 /** 383 * @brief Static Opp observer instance. 384 * 385 */ 386 static OppObserver *instance_; 387 388 private: 389 Opp(); 390 ~Opp(); 391 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(Opp); 392 BLUETOOTH_DECLARE_IMPL(); 393 394 #ifdef DTFUZZ_TEST 395 friend class BluetoothNoDestructor<Opp>; 396 #endif 397 }; 398 } // namespace Bluetooth 399 } // namespace OHOS 400 #endif // BLUETOOTH_OPP_H