1 /* 2 * Copyright (c) 2024 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 BROADCAST_SCHEDULER_H 17 #define BROADCAST_SCHEDULER_H 18 19 #include "broadcast_scheduler_type.h" 20 #include "softbus_broadcast_manager.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * @brief Init broadcast scheduler. 28 * 29 * @return Returns <b>SOFTBUS_OK</b> if the broadcast scheduler initialize succ; 30 * returns any other value if initialize failed. 31 * @since 5.0 32 * @version 1.0 33 */ 34 int32_t SchedulerInitBroadcast(void); 35 36 /** 37 * @brief Deinit broadcast scheduler. 38 * 39 * @return Returns <b>SOFTBUS_OK</b> if the broadcast scheduler deinitialize succ; 40 * returns any other value if deinitialize failed. 41 * @since 5.0 42 * @version 1.0 43 */ 44 int32_t SchedulerDeinitBroadcast(void); 45 46 /** 47 * @brief Register the service to the broadcast scheduler. 48 * 49 * @param type Indicates the service type {@link BaseServiceType}. 50 * @param bcId Indicates the service broadcast ID. 51 * @param cb Indicates the service broadcast callback {@link BroadcastCallback}. 52 * 53 * @return Returns <b>SOFTBUS_OK</b> if the service register succ. 54 * returns any other value if the service register failed. 55 * 56 * @since 5.0 57 * @version 1.0 58 */ 59 int32_t SchedulerRegisterBroadcaster(BaseServiceType type, int32_t *bcId, const BroadcastCallback *cb); 60 61 /** 62 * @brief Unregister the service to the broadcast scheduler. 63 * 64 * @param bcId Indicates the service broadcast ID. 65 * 66 * @return Returns <b>SOFTBUS_OK</b> if the service unregister succ. 67 * returns any other value if the service unregister failed. 68 * 69 * @since 5.0 70 * @version 1.0 71 */ 72 int32_t SchedulerUnregisterBroadcaster(int32_t bcId); 73 74 /** 75 * @brief Register the service listener to the broadcast scheduler. 76 * 77 * @param type Indicates the service type {@link BaseServiceType}. 78 * @param listenerId Indicates the service listener ID. 79 * @param cb Indicates the service listener callback {@link ScanCallback}. 80 * 81 * @return Returns <b>SOFTBUS_OK</b> if the service register succ. 82 * returns any other value if the service register failed. 83 * 84 * @since 5.0 85 * @version 1.0 86 */ 87 int32_t SchedulerRegisterScanListener(BaseServiceType type, int32_t *listenerId, const ScanCallback *cb); 88 89 /** 90 * @brief Unregister the service listener to the broadcast scheduler. 91 * 92 * @param listenerId Indicates the service listener ID. 93 * 94 * @return Returns <b>SOFTBUS_OK</b> if the service unregister succ. 95 * returns any other value if the service unregister failed. 96 * 97 * @since 5.0 98 * @version 1.0 99 */ 100 int32_t SchedulerUnregisterListener(int32_t listenerId); 101 102 /** 103 * @brief The service start send broadcast by scheduler. 104 * 105 * @param bcId Indicates the service broadcast ID. 106 * @param param Indicates the pointer to the service parameter information. For details, see {@link BroadcastParam}. 107 * @param packet Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 108 * 109 * @return Returns <b>SOFTBUS_OK</b> if the service start send broadcast succ. 110 * returns any other value for failed. 111 * 112 * @since 5.0 113 * @version 1.0 114 */ 115 int32_t SchedulerStartBroadcast(int32_t bcId, BroadcastContentType contentType, const BroadcastParam *param, 116 const BroadcastPacket *packet); 117 118 /** 119 * @brief The service update broadcast data and parameters. 120 * The broadcast will be stopped and then started if the broadcast info is updated. 121 * 122 * @param bcId Indicates the service broadcast ID. 123 * @param param Indicates the pointer to the service parameter info. For details, see {@link BroadcastParam}. 124 * @param bcData Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 125 * 126 * @return Returns <b>SOFTBUS_OK</b> if the service update broadcast info succ. 127 * returns any other value for failed. 128 * 129 * @since 5.0 130 * @version 1.0 131 */ 132 int32_t SchedulerUpdateBroadcast(int32_t bcId, const BroadcastParam *param, const BroadcastPacket *packet); 133 134 /** 135 * @brief The service set broadcast data. Set broadcast data when broadcast is advertising. 136 * 137 * @param bcId Indicates the service broadcast ID. 138 * @param packet Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 139 * 140 * @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully. 141 * returns any other value for failed. 142 * 143 * @since 5.0 144 * @version 1.0 145 */ 146 int32_t SchedulerSetBroadcastData(int32_t bcId, const BroadcastPacket *packet); 147 148 /** 149 * @brief The service set broadcast param. Set broadcast param when broadcast is advertising and disabled. 150 * 151 * @param bcId Indicates the service broadcast ID. 152 * @param packet Indicates the pointer to the service advertising data. For details, see {@link BroadcastPacket}. 153 * 154 * @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully. 155 * returns any other value for failed. 156 * 157 * @since 5.1 158 * @version 1.0 159 */ 160 int32_t SchedulerSetBroadcastParam(int32_t bcId, const BroadcastParam *param); 161 162 /** 163 * @brief The service stop broadcast. 164 * 165 * @param bcId Indicates the service broadcast ID. 166 * 167 * @return Returns <b>SOFTBUS_OK</b> if the service stop the broadcast successfully. 168 * returns any other value for failed. 169 * 170 * @since 5.0 171 * @version 1.0 172 */ 173 int32_t SchedulerStopBroadcast(int32_t bcId); 174 175 /** 176 * @brief The service enable broadcast scanning 177 * 178 * @param listenerId Indicates the service listener ID. 179 * @param param Indicates the broadcast scan parameter {@link BcScanParams} 180 * 181 * @return Returns <b>SOFTBUS_OK</b> if the service start to scan succ. 182 * returns any other value for failed. 183 * 184 * @since 5.0 185 * @version 1.0 186 */ 187 int32_t SchedulerStartScan(int32_t listenerId, const BcScanParams *param); 188 189 /** 190 * @brief The service stop broadcast scanning 191 * 192 * @param listenerId Indicates the service listener ID. 193 * 194 * @return Returns <b>SOFTBUS_OK</b> if the service stop scan succ. 195 * returns any other value for failed. 196 * 197 * @since 5.0 198 * @version 1.0 199 */ 200 int32_t SchedulerStopScan(int32_t listenerId); 201 202 /** 203 * @brief Set the scan filter object 204 * 205 * @param listenerId Indicates the service listener ID. 206 * @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter} 207 * @param filterNum Indicates the number of the filter parameter 208 * 209 * @return Returns <b>SOFTBUS_OK</b> if the service set the scan filter succ. 210 * returns any other value for failed. 211 * 212 * @since 5.0 213 * @version 1.0 214 */ 215 int32_t SchedulerSetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t filterNum); 216 217 /** 218 * @brief Get the scan filter object 219 * 220 * @param listenerId Indicates the service listener ID. 221 * @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter} 222 * @param filterNum Indicates the number of the filter parameter 223 * 224 * @return Returns <b>SOFTBUS_OK</b> if the service get the scan filter succ. 225 * returns any other value for failed. 226 * 227 * @since 5.0 228 * @version 1.0 229 */ 230 int32_t SchedulerGetScanFilter(int32_t listenerId, BcScanFilter **scanFilter, uint8_t *filterNum); 231 232 /** 233 * @brief Check whether available resources are available by using the bcid 234 * 235 * @param bcId Indicates the service broadcast ID, when the service register successfully 236 * @param status Indicates the status of available broadcast resources 237 * 238 * @return Returns <b>SOFTBUS_OK</b> if the service query status succ. 239 * returns any other value for failed. 240 * 241 * @since 5.0 242 * @version 1.0 243 */ 244 int32_t SchedulerQueryBroadcastStatus(int32_t bcId, int32_t *status); 245 246 /** 247 * @brief Check whether the device is a low-power device. 248 * 249 * @return Returns <b>true</b> if the device is a low-power device. 250 * @return Returns false for not. 251 * 252 * @since 5.0 253 * @version 1.0 254 */ 255 bool SchedulerIsLpDeviceAvailable(void); 256 257 /** 258 * @brief Set low-power chip broadcast parameters, scanning parameters, scanning filters, and broadcast data. 259 * 260 * @param bcParam Indicates low-power chip broadcast parameters and broadcast data. 261 * @param scanParam Indicates low power chip scan parameters and filters. 262 * 263 * @return Returns <b>true</b> if the service set parameters succ. 264 * @return Returns false for failed. 265 * 266 * @since 5.0 267 * @version 1.0 268 */ 269 bool SchedulerSetAdvDeviceParam(LpServerType type, const LpBroadcastParam *bcParam, 270 const LpScanParam *scanParam); 271 272 /** 273 * @brief Obtain the advHandle by advId. 274 * 275 * @param bcId Indicates the service broadcast ID, when the service register successfully 276 * @param bcHandle Indicates Convert to bcHandle via advId. 277 * 278 * @return Returns <b>SOFTBUS_OK</b> if the service get the handle succ. 279 * returns any other value for failed. 280 * 281 * @since 5.0 282 * @version 1.0 283 */ 284 int32_t SchedulerGetBroadcastHandle(int32_t bcId, int32_t *bcHandle); 285 286 /** 287 * @brief Enables data synchronization to a low-power chip. 288 * 289 * @return Returns <b>SOFTBUS_OK</b> if the service enable SyncData succ. 290 * returns any other value for failed. 291 * 292 * @since 5.0 293 * @version 1.0 294 */ 295 int32_t SchedulerEnableSyncDataToLpDevice(void); 296 297 /** 298 * @brief Disables data synchronization to a low-power chip. 299 * 300 * @return Returns <b>SOFTBUS_OK</b> if the service disable syncData succ. 301 * returns any other value for failed. 302 * 303 * @since 5.0 304 * @version 1.0 305 */ 306 int32_t SchedulerDisableSyncDataToLpDevice(void); 307 308 /** 309 * @brief set scanReport channel to a low-power chip. 310 * 311 * @return Returns <b>SOFTBUS_OK</b> if the service set scanReport channel succ. 312 * returns any other value for failed. 313 * 314 * @since 5.0 315 * @version 1.0 316 */ 317 int32_t SchedulerSetScanReportChannelToLpDevice(int32_t listenerId, bool enable); 318 319 /** 320 * @brief set low-power broadcast channel parameters. 321 * 322 * @param duration Indicates broadcast duration. 323 * @param maxExtAdvEvents Indicates maximum number of extended broadcast events. 324 * @param window Indicates work window. 325 * @param interval Indicates work interval. 326 * @param bcHandle Indicates the broadcast handle. 327 * 328 * @return Returns <b>SOFTBUS_OK</b> if the service set low power broadcast parameters succ. 329 * returns any other value for failed. 330 * 331 * @since 5.0 332 * @version 1.0 333 */ 334 int32_t SchedulerSetLpAdvParam(int32_t duration, int32_t maxExtAdvEvents, int32_t window, 335 int32_t interval, int32_t bcHandle); 336 337 #ifdef __cplusplus 338 } 339 #endif // __cplusplus 340 #endif // BROADCAST_SCHEDULER_H 341 342