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 /** 17 * @file softbus_broadcast_manager.h 18 * @brief 19 * 20 * @since 4.1 21 * @version 1.0 22 */ 23 24 #ifndef SOFTBUS_BROADCAST_MANAGER_H 25 #define SOFTBUS_BROADCAST_MANAGER_H 26 27 #include "softbus_broadcast_type.h" 28 29 #ifdef __cplusplus 30 extern "C"{ 31 #endif 32 33 /** 34 * @brief Defines the broadcast callback function. 35 * 36 * @since 4.1 37 * @version 1.0 38 */ 39 typedef struct { 40 void (*OnStartBroadcastingCallback)(int32_t bcId, int32_t status); 41 void (*OnStopBroadcastingCallback)(int32_t bcId, int32_t status); 42 void (*OnUpdateBroadcastingCallback)(int32_t bcId, int32_t status); 43 void (*OnSetBroadcastingCallback)(int32_t bcId, int32_t status); 44 void (*OnSetBroadcastingParamCallback)(int32_t bcId, int32_t status); 45 void (*OnEnableBroadcastingCallback)(int32_t bcId, int32_t status); 46 void (*OnDisableBroadcastingCallback)(int32_t bcId, int32_t status); 47 } BroadcastCallback; 48 49 /** 50 * @brief Defines the broadcast scan callback function. 51 * 52 * @since 4.1 53 * @version 1.0 54 */ 55 typedef struct { 56 void (*OnStartScanCallback)(int32_t listenerId, int32_t status); 57 void (*OnStopScanCallback)(int32_t listenerId, int32_t status); 58 void (*OnReportScanDataCallback)(int32_t listenerId, const BroadcastReportInfo *reportInfo); 59 void (*OnScanStateChanged)(int32_t resultCode, bool isStartScan); 60 void (*OnLpDeviceInfoCallback)(const BroadcastUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize); 61 } ScanCallback; 62 63 /** 64 * @brief init broadcast manager. 65 * 66 * @return Returns <b>0</b> If the broadcast management initialization fails; 67 * returns any other value if the request fails. 68 * @since 4.1 69 * @version 1.0 70 */ 71 int32_t InitBroadcastMgr(void); 72 73 /** 74 * @brief init broadcast manager. 75 * 76 * @return Returns <b>SOFTBUS_OK</b> If the broadcast management deinitialization fails; 77 * returns any other value if the request fails. 78 * @since 4.1 79 * @version 1.0 80 */ 81 int32_t DeInitBroadcastMgr(void); 82 83 /** 84 * @brief Register the service to the broadcast manager. 85 * 86 * @param type Indicates the service type {@link BaseServiceType}. 87 * @param bcId Indicates the service broadcast ID. 88 * @param cb Indicates the service broadcast callback {@link BroadcastCallback}. 89 * 90 * @return Returns <b>SOFTBUS_OK</b> if the service register is successful. 91 * returns any other value if the register fails. 92 * 93 * @since 4.1 94 * @version 1.0 95 */ 96 int32_t RegisterBroadcaster(BaseServiceType type, int32_t *bcId, const BroadcastCallback *cb); 97 98 /** 99 * @brief UnRegister the service to the broadcast manager. 100 * 101 * @param bcId Indicates the service broadcast ID. 102 * 103 * @return Returns <b>SOFTBUS_OK</b> if the service unregister is successful. 104 * returns any other value if the unregister fails. 105 * 106 * @since 4.1 107 * @version 1.0 108 */ 109 int32_t UnRegisterBroadcaster(int32_t bcId); 110 111 /** 112 * @brief Register the service listener to the broadcast manager. 113 * 114 * @param type Indicates the service type {@link BaseServiceType}. 115 * @param listenerId Indicates the service listener ID. 116 * @param cb Indicates the service listener callback {@link ScanCallback}. 117 * 118 * @return Returns <b>SOFTBUS_OK</b> if the service register is successful. 119 * returns any other value if the register fails. 120 * 121 * @since 4.1 122 * @version 1.0 123 */ 124 int32_t RegisterScanListener(BaseServiceType type, int32_t *listenerId, const ScanCallback *cb); 125 126 /** 127 * @brief UnRegister the service listener to the broadcast manager. 128 * 129 * @param listenerId Indicates the service listener ID. 130 * 131 * @return Returns <b>SOFTBUS_OK</b> if the service unregister is successful. 132 * returns any other value if the unregister fails. 133 * 134 * @since 4.1 135 * @version 1.0 136 */ 137 int32_t UnRegisterScanListener(int32_t listenerId); 138 139 /** 140 * @brief The service enable broadcast 141 * 142 * @param bcId Indicates the service broadcast ID. 143 * @param param Indicates the pointer to the service parameter information. For details, see {@link BroadcastParam}. 144 * @param packet Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 145 * 146 * @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully. 147 * returns any other value if the unregister fails. 148 * 149 * @since 4.1 150 * @version 1.0 151 */ 152 int32_t StartBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastPacket *packet); 153 154 /** 155 * @brief The service update broadcast data and parameters.When the broadcast is updated, 156 * the broadcast is stopped and then started. 157 * 158 * @param bcId Indicates the service broadcast ID. 159 * @param param Indicates the pointer to the service parameter information. For details, see {@link BroadcastParam}. 160 * @param bcData Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 161 * 162 * @return Returns <b>SOFTBUS_OK</b> if the service updates the broadcast successfully. 163 * returns any other value if the service fails to update the broadcast. 164 * 165 * @since 4.1 166 * @version 1.0 167 */ 168 int32_t UpdateBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastPacket *packet); 169 170 /** 171 * @brief The service set broadcast data. Set broadcast data when broadcast is advertising. 172 * 173 * @param bcId Indicates the service broadcast ID. 174 * @param packet Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 175 * 176 * @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully. 177 * returns any other value if the unregister fails. 178 * 179 * @since 4.1 180 * @version 1.0 181 */ 182 183 int32_t SetBroadcastingData(int32_t bcId, const BroadcastPacket *packet); 184 185 /** 186 * @brief The service set broadcast param. Set broadcast param when broadcast is advertising and disabled. 187 * 188 * @param bcId Indicates the service broadcast ID. 189 * @param param Indicates the pointer to the service parameter information. For details, see {@link BroadcastParam}. 190 * 191 * @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully. 192 * returns any other value if the unregister fails. 193 * 194 * @since 5.1 195 * @version 1.0 196 */ 197 int32_t SetBroadcastingParam(int32_t bcId, const BroadcastParam *param); 198 199 /** 200 * @brief The service stop broadcast 201 * 202 * @param bcId Indicates the service broadcast ID. 203 * 204 * @return Returns <b>SOFTBUS_OK</b> if the service stop the broadcast successfully. 205 * returns any other value if the service fails to stop the broadcast. 206 * 207 * @since 4.1 208 * @version 1.0 209 */ 210 int32_t StopBroadcasting(int32_t bcId); 211 212 /** 213 * @brief The service enable broadcast scanning 214 * 215 * @param listenerId Indicates the service listener ID. 216 * @param param Indicates the broadcast scan parameter {@link BcScanParams} 217 * 218 * @return Returns <b>SOFTBUS_OK</b> if the service start to scan the broadcast successfully. 219 * returns any other value if the service fails to scan the broadcast. 220 * 221 * @since 4.1 222 * @version 1.0 223 */ 224 int32_t StartScan(int32_t listenerId, const BcScanParams *param); 225 226 /** 227 * @brief The service stop broadcast scanning 228 * 229 * @param listenerId Indicates the service listener ID. 230 * 231 * @return Returns <b>SOFTBUS_OK</b> if the service stop to scan the broadcast successfully. 232 * returns any other value if the service fails to stop scanning the broadcast. 233 * 234 * @since 4.1 235 * @version 1.0 236 */ 237 int32_t StopScan(int32_t listenerId); 238 239 /** 240 * @brief Set the Scan Filter object 241 * 242 * @param listenerId Indicates the service listener ID. 243 * @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter} 244 * @param filterNum Indicates the number of the filter parameter 245 * 246 * @return Returns <b>SOFTBUS_OK</b> if the service set the Scan Filter successfully. 247 * returns any other value if the service fails to set the Scan Filter. 248 * 249 * @since 4.1 250 * @version 1.0 251 */ 252 int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t filterNum); 253 254 /** 255 * @brief Get the Scan Filter object 256 * 257 * @param listenerId Indicates the service listener ID. 258 * @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter} 259 * @param filterNum Indicates the number of the filter parameter 260 * 261 * @return Returns <b>SOFTBUS_OK</b> if the service get the Scan Filter successfully. 262 * returns any other value if the service fails to get the Scan Filter. 263 * 264 * @since 4.1 265 * @version 1.0 266 */ 267 int32_t GetScanFilter(int32_t listenerId, BcScanFilter **scanFilter, uint8_t *filterNum); 268 269 /** 270 * @brief Check whether available resources are available by using the bcid 271 * 272 * @param bcId Indicates the service broadcast ID, when the service register successfully 273 * @param status Indicates the status of available broadcast resources 274 * 275 * @return Returns <b>SOFTBUS_OK</b> if the service query status successfully. 276 * returns any other value if the service fails to query status. 277 * 278 * @since 4.1 279 * @version 1.0 280 */ 281 int32_t QueryBroadcastStatus(int32_t bcId, int32_t *status); 282 283 /** 284 * @brief Check whether the device is a low-power device. 285 * 286 * @return Returns <b>true</b> if the device is a low-power device. 287 * @return returns false value if the service fails to query a low-power device. 288 * 289 * @since 4.1 290 * @version 1.0 291 */ 292 bool BroadcastIsLpDeviceAvailable(void); 293 294 /** 295 * @brief Set low-power chip broadcast parameters, scanning parameters, scanning filters, and broadcast data. 296 * 297 * @param bcParam Indicates low-power chip broadcast parameters and broadcast data. 298 * @param scanParam Indicates low power chip scan parameters and filters. 299 * 300 * @return Returns <b>true</b> if the service set parameters successfully. 301 * @return returns false value if the service fails set parameters. 302 * 303 * @since 4.1 304 * @version 1.0 305 */ 306 bool BroadcastSetAdvDeviceParam(LpServerType type, const LpBroadcastParam *bcParam, 307 const LpScanParam *scanParam); 308 309 /** 310 * @brief Obtain the advHandle using advId. 311 * 312 * @param bcId Indicates the service broadcast ID, when the service register successfully 313 * @param bcHandle Indicates Convert to bcHandle via advId,. 314 * 315 * @return Returns <b>SOFTBUS_OK</b> if the service get the handle successfully. 316 * returns any other value if the service fails to get the handle. 317 * 318 * @since 4.1 319 * @version 1.0 320 */ 321 int32_t BroadcastGetBroadcastHandle(int32_t bcId, int32_t *bcHandle); 322 323 /** 324 * @brief Enables data synchronization to a low-power chip. 325 * 326 * @return Returns <b>SOFTBUS_OK</b> if the service enable SyncData successfully. 327 * returns any other value if the service fails to enable SyncData. 328 * 329 * @since 4.1 330 * @version 1.0 331 */ 332 int32_t BroadcastEnableSyncDataToLpDevice(void); 333 334 /** 335 * @brief Disables data synchronization to a low-power chip. 336 * 337 * @return Returns <b>SOFTBUS_OK</b> if the service disable syncData successfully. 338 * returns any other value if the service fails to disable syncData. 339 * 340 * @since 4.1 341 * @version 1.0 342 */ 343 int32_t BroadcastDisableSyncDataToLpDevice(void); 344 345 /** 346 * @brief set scanReport channel to a low-power chip. 347 * 348 * @return Returns <b>SOFTBUS_OK</b> if the service set scanReport channel successfully. 349 * returns any other value if the service fails to set scanReport channel. 350 * 351 * @since 4.1 352 * @version 1.0 353 */ 354 int32_t BroadcastSetScanReportChannelToLpDevice(int32_t listenerId, bool enable); 355 356 /** 357 * @brief set low-power broadcast channel parameters. 358 * 359 * @param duration Indicates broadcast duration. 360 * @param maxExtAdvEvents Indicates maximum number of extended broadcast events. 361 * @param window Indicates work window. 362 * @param interval Indicates work interval. 363 * @param bcHandle Indicates the broadcast handle. 364 * 365 * @return Returns <b>SOFTBUS_OK</b> if the service set low power broadcast parameters successfully. 366 * returns any other value if the service fails to set low power broadcast parameters. 367 * 368 * @since 1.0 369 * @version 1.0 370 */ 371 int32_t BroadcastSetLpAdvParam(int32_t duration, int32_t maxExtAdvEvents, int32_t window, 372 int32_t interval, int32_t bcHandle); 373 374 #ifdef __cplusplus 375 } 376 #endif 377 378 #endif /* SOFTBUS_BROADCAST_MANAGER_H */ 379