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_MAP_MSE_H 17 #define BLUETOOTH_MAP_MSE_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 #include "bluetooth_no_destructor.h" 26 27 namespace OHOS { 28 namespace Bluetooth { 29 /** 30 * @brief Class for MAP MSE observer functions. 31 * 32 */ 33 class MapMseObserver { 34 public: 35 /** 36 * @brief Destroy the MapMseObserver object. 37 * 38 */ 39 virtual ~MapMseObserver() = default; 40 41 /** 42 * @brief The observer function to notify connection state changed. 43 * 44 * @param device Remote device object. 45 * @param state Connection state. 46 * @param cause Connection cause. 47 */ OnConnectionStateChanged(const BluetoothRemoteDevice & device,int32_t state,int32_t cause)48 virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int32_t state, int32_t cause) 49 {} 50 }; 51 52 /** 53 * @brief Class for MapMse Server API. 54 * 55 */ 56 class BLUETOOTH_API MapMse { 57 public: 58 /** 59 * @brief Get the instance of MapMse object. 60 * 61 * @return Returns the pointer to the MapMse instance. 62 */ 63 static MapMse *GetProfile(); 64 65 /** 66 * @brief Register MapMse observer instance. 67 * 68 * @param observer MapMse observer instance. 69 */ 70 void RegisterObserver(std::shared_ptr<MapMseObserver> observer); 71 72 /** 73 * @brief Deregister MapMse observer instance. 74 * 75 * @param observer MapMse observer instance. 76 */ 77 void DeregisterObserver(std::shared_ptr<MapMseObserver> observer); 78 79 /** 80 * @brief Get remote map mse device list which are in the specified states. 81 * 82 * @param states List of remote device states. 83 * @param result the list of devices 84 * @return Returns operate result. 85 */ 86 int32_t GetDevicesByStates(const std::vector<int32_t> &states, std::vector<BluetoothRemoteDevice> &result) const; 87 88 /** 89 * @brief Get the connection state of the specified remote map device. 90 * 91 * @param device Remote device object. 92 * @param state the connection state of the remote device 93 * @return Returns operate result. 94 */ 95 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state) const; 96 97 /** 98 * @brief Release the connection from remote map device. 99 * 100 * @param device Remote device object. 101 * @return Returns operate result. 102 */ 103 int32_t Disconnect(const BluetoothRemoteDevice &device); 104 105 /** 106 * @brief Set connection strategy for remote bluetooth device. 107 * 108 * @param device Remote device object. 109 * @param strategy The device connect strategy. 110 * @return Returns operate result 111 */ 112 int32_t SetConnectionStrategy(const BluetoothRemoteDevice &device, int32_t strategy); 113 114 /** 115 * @brief Get connection strategy of remote bluetooth device. 116 * 117 * @param device The address of the peer bluetooth device. 118 * @param strategy The device connect strategy. 119 * @return Returns operate result. 120 */ 121 int32_t GetConnectionStrategy(const BluetoothRemoteDevice &device, int32_t &strategy) const; 122 123 /** 124 * @brief Set meta data for remote bluetooth device. 125 * 126 * @param device Remote device object. 127 * @param accessAuthorization The accessAuthorization. 128 * @return Returns operate result 129 */ 130 int32_t SetMessageAccessAuthorization(const BluetoothRemoteDevice &device, int32_t accessAuthorization); 131 132 /** 133 * @brief Get meta data strategy of remote bluetooth device. 134 * 135 * @param device The address of the peer bluetooth device. 136 * @param accessAuthorization out accessAuthorization. 137 * @return Returns operate result. 138 */ 139 int32_t GetMessageAccessAuthorization(const BluetoothRemoteDevice &device, int32_t &accessAuthorization) const; 140 141 void Init(); 142 void Uinit(); 143 144 private: 145 MapMse(); 146 ~MapMse(); 147 148 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(MapMse); 149 BLUETOOTH_DECLARE_IMPL(); 150 151 #ifdef DTFUZZ_TEST 152 friend class BluetoothNoDestructor<MapMse>; 153 #endif 154 }; 155 } // namespace Bluetooth 156 } // namespace OHOS 157 #endif // BLUETOOTH_MAP_MSE_H