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 enabled.
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 stop broadcast.
150  *
151  * @param bcId Indicates the service broadcast ID.
152  *
153  * @return Returns <b>SOFTBUS_OK</b> if the service stop the broadcast successfully.
154  * returns any other value for failed.
155  *
156  * @since 5.0
157  * @version 1.0
158  */
159 int32_t SchedulerStopBroadcast(int32_t bcId);
160 
161 /**
162  * @brief The service enable broadcast scanning
163  *
164  * @param listenerId Indicates the service listener ID.
165  * @param param Indicates the broadcast scan parameter {@link BcScanParams}
166  *
167  * @return Returns <b>SOFTBUS_OK</b> if the service start to scan succ.
168  * returns any other value for failed.
169  *
170  * @since 5.0
171  * @version 1.0
172  */
173 int32_t SchedulerStartScan(int32_t listenerId, const BcScanParams *param);
174 
175 /**
176  * @brief The service stop broadcast scanning
177  *
178  * @param listenerId Indicates the service listener ID.
179  *
180  * @return Returns <b>SOFTBUS_OK</b> if the service stop scan succ.
181  * returns any other value for failed.
182  *
183  * @since 5.0
184  * @version 1.0
185  */
186 int32_t SchedulerStopScan(int32_t listenerId);
187 
188 /**
189  * @brief Set the scan filter object
190  *
191  * @param listenerId Indicates the service listener ID.
192  * @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter}
193  * @param filterNum Indicates the number of the filter parameter
194  *
195  * @return Returns <b>SOFTBUS_OK</b> if the service set the scan filter succ.
196  * returns any other value for failed.
197  *
198  * @since 5.0
199  * @version 1.0
200  */
201 int32_t SchedulerSetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t filterNum);
202 
203 /**
204  * @brief Get the scan filter object
205  *
206  * @param listenerId Indicates the service listener ID.
207  * @param scanFilter Indicates the broadcast scan filter parameter {@link BcScanFilter}
208  * @param filterNum Indicates the number of the filter parameter
209  *
210  * @return Returns <b>SOFTBUS_OK</b> if the service get the scan filter succ.
211  * returns any other value for failed.
212  *
213  * @since 5.0
214  * @version 1.0
215  */
216 int32_t SchedulerGetScanFilter(int32_t listenerId, BcScanFilter **scanFilter, uint8_t *filterNum);
217 
218 /**
219  * @brief Check whether available resources are available by using the bcid
220  *
221  * @param bcId Indicates the service broadcast ID, when the service register successfully
222  * @param status Indicates the status of available broadcast resources
223  *
224  * @return Returns <b>SOFTBUS_OK</b> if the service query status succ.
225  * returns any other value for failed.
226  *
227  * @since 5.0
228  * @version 1.0
229  */
230 int32_t SchedulerQueryBroadcastStatus(int32_t bcId, int32_t *status);
231 
232 /**
233  * @brief Check whether the device is a low-power device.
234  *
235  * @return Returns <b>true</b> if the device is a low-power device.
236  * @return Returns false for not.
237  *
238  * @since 5.0
239  * @version 1.0
240  */
241 bool SchedulerIsLpDeviceAvailable(void);
242 
243 /**
244  * @brief Set low-power chip broadcast parameters, scanning parameters, scanning filters, and broadcast data.
245  *
246  * @param bcParam Indicates low-power chip broadcast parameters and broadcast data.
247  * @param scanParam Indicates low power chip scan parameters and filters.
248  *
249  * @return Returns <b>true</b> if the service set parameters succ.
250  * @return Returns false for failed.
251  *
252  * @since 5.0
253  * @version 1.0
254  */
255 bool SchedulerSetAdvDeviceParam(LpServerType type, const LpBroadcastParam *bcParam,
256     const LpScanParam *scanParam);
257 
258 /**
259  * @brief Obtain the advHandle by advId.
260  *
261  * @param bcId Indicates the service broadcast ID, when the service register successfully
262  * @param bcHandle Indicates Convert to bcHandle via advId.
263  *
264  * @return Returns <b>SOFTBUS_OK</b> if the service get the handle succ.
265  * returns any other value for failed.
266  *
267  * @since 5.0
268  * @version 1.0
269  */
270 int32_t SchedulerGetBroadcastHandle(int32_t bcId, int32_t *bcHandle);
271 
272 /**
273  * @brief Enables data synchronization to a low-power chip.
274  *
275  * @return Returns <b>SOFTBUS_OK</b> if the service enable SyncData succ.
276  * returns any other value for failed.
277  *
278  * @since 5.0
279  * @version 1.0
280  */
281 int32_t SchedulerEnableSyncDataToLpDevice(void);
282 
283 /**
284  * @brief Disables data synchronization to a low-power chip.
285  *
286  * @return Returns <b>SOFTBUS_OK</b> if the service disable syncData succ.
287  * returns any other value for failed.
288  *
289  * @since 5.0
290  * @version 1.0
291  */
292 int32_t SchedulerDisableSyncDataToLpDevice(void);
293 
294 /**
295  * @brief set scanReport channel to a low-power chip.
296  *
297  * @return Returns <b>SOFTBUS_OK</b> if the service set scanReport channel succ.
298  * returns any other value for failed.
299  *
300  * @since 5.0
301  * @version 1.0
302  */
303 int32_t SchedulerSetScanReportChannelToLpDevice(int32_t listenerId, bool enable);
304 
305 /**
306  * @brief set low-power broadcast channel parameters.
307  *
308  * @param duration Indicates broadcast duration.
309  * @param maxExtAdvEvents Indicates maximum number of extended broadcast events.
310  * @param window Indicates work window.
311  * @param interval Indicates work interval.
312  * @param bcHandle Indicates the broadcast handle.
313  *
314  * @return Returns <b>SOFTBUS_OK</b> if the service set low power broadcast parameters succ.
315  * returns any other value for failed.
316  *
317  * @since 5.0
318  * @version 1.0
319  */
320 int32_t SchedulerSetLpAdvParam(int32_t duration, int32_t maxExtAdvEvents, int32_t window,
321     int32_t interval, int32_t bcHandle);
322 
323 #ifdef __cplusplus
324 }
325 #endif // __cplusplus
326 #endif // BROADCAST_SCHEDULER_H
327 
328