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 /**
17  * @addtogroup SoftBus
18  * @{
19  *
20  * @brief Provides data level of distributed database transport by DSoftBus ble heratbeat.
21  *
22  * This module implements unified distributed communication management of nearby devices and provides link-independent
23  * device discovery and transmission interfaces to support service publishing and data transmission.
24  * @since 1.0
25  * @version 1.0
26  */
27 /** @} */
28 
29 #ifndef DATA_LEVEL_H
30 #define DATA_LEVEL_H
31 
32 #include <stdint.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * @brief Defines a callback that is invoked when receive the data level from remote device.
40  * For details, see {@link RegDataLevelChangeCb}.
41  *
42  * @since 1.0
43  * @version 1.0
44  */
45 typedef struct {
46     uint16_t dynamicLevel; /**< dynamic data level, 16bit */
47     uint16_t staticLevel; /**< static data level, 16bit */
48     uint32_t switchLevel; /**< switch data level, alterable length, 16bit, 24bit or 32bit */
49     uint16_t switchLength; /**< switch data length, max 24 switchs */
50 } DataLevel;
51 
52 typedef struct {
53     /**
54      * @brief Called when the Data level of a device received.
55      *
56      * @param networkId Indicates the network id of the device.
57      * @param dataLevel Indicates the received data level.
58      *
59      * @since 1.0
60      * @version 1.0
61      */
62     void (*onDataLevelChanged)(const char *networkId, const DataLevel dataLevel);
63 } IDataLevelCb;
64 
65 /**
66  * @brief Registers a callback for data level received.
67  *
68  * @param pkgName Indicates the package name of the caller.
69  * @param callback Indicates the function callback to be registered. For details, see {@link IDataLevelCb}.
70  * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise.
71  *
72  * @since 1.0
73  * @version 1.0
74  */
75 int32_t RegDataLevelChangeCb(const char *pkgName, IDataLevelCb *callback);
76 
77 /**
78  * @brief Unregisters a callback for data level received.
79  *
80  * @param pkgName Indicates the package name of the caller.
81  * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise.
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 int32_t UnregDataLevelChangeCb(const char *pkgName);
87 
88 /**
89  * @brief Set the DistributedDataBase Data Level. This interface CAN ONLY invoked by DistributedDataBase.
90  *
91  * @param dataLevel Indicates the data level.
92  * @return Returns <b>0</b> if the registeration is successful; returns any other value otherwise.
93  *
94  * @since 1.0
95  * @version 1.0
96  */
97 int32_t SetDataLevel(const DataLevel *dataLevel);
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 #endif