1 /*
2  * Copyright (c) 2021 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 DISC_MANAGER_INTERFACE_H
17 #define DISC_MANAGER_INTERFACE_H
18 
19 #include "softbus_common.h"
20 #include "stdint.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 /**
29  * @ingroup softbus_disc_manager
30  * Inner Module.
31  *
32  */
33 typedef enum {
34     MODULE_MIN = 1,
35     MODULE_LNN = MODULE_MIN,
36     MODULE_CONN = 2,
37     MODULE_MAX = MODULE_CONN
38 } DiscModule;
39 
40 typedef enum {
41     LINK_STATUS_UP = 0,
42     LINK_STATUS_DOWN,
43 } LinkStatus;
44 
45 typedef enum {
46     TYPE_LOCAL_DEVICE_NAME,
47     TYPE_ACCOUNT,
48 } InfoTypeChanged;
49 
50 /**
51  * @ingroup softbus_disc_manager
52  * Inner Callback.
53  *
54  */
55 typedef struct {
56     void (*OnDeviceFound)(const DeviceInfo *device, const InnerDeviceInfoAddtions *addtions);
57 } DiscInnerCallback;
58 
59 /**
60  * @ingroup softbus_disc_manager
61  * @brief Initialization of discovery management. Set the necessary environment for the discovery side.
62  * This interface is only called once when the softbus service is created.
63  * @see {@link DiscMgrDeinit}
64  * @return <b>SOFTBUS_DISCOVER_MANAGER_INIT_FAIL</b> Create Softbus list failed.
65  * @return <b>SOFTBUS_OK</b> Manager is Successfully inited
66  */
67 int32_t DiscMgrInit(void);
68 
69 /**
70  * @ingroup softbus_disc_manager
71  * @brief Discovery managed deinitialization. Clear the corresponding configuration of the discovery terminal.
72  * This interface is only called once when the softbus service is destroyed.
73  * @see {@link DiscMgrInit}
74  */
75 void DiscMgrDeinit(void);
76 
77 /**
78  * @ingroup softbus_disc_manager
79  * @brief Found management module information destroy callback function.
80  * Destroy the configuration related to the discovery release and clear it.
81  * @param[in] pkgName Indicates the pointer to package name, which can contain a maximum of 64 bytes.
82  */
83 void DiscMgrDeathCallback(const char *pkgName);
84 
85 /**
86  * @ingroup softbus_disc_manager
87  * @brief Set the discovery callback and set the discovery client environment.
88  * @param[in] moduleId Mouble Id. For details, see {@link DiscModule}.
89  * @param[in] callback Indicates a pointer to the discovery internal callback.
90  * For details, see {@link DiscInnerCallback}.
91  * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid.
92  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> if the Intelligent Soft Bus server fails to be initialized.
93  * @return <b>SOFTBUS_MEM_ERR</b> if Memcpy failed.
94  * @return <b>SOFTBUS_LOCK_ERR</b> if Mutex lock failed.
95  * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> if duplicate info.
96  * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> if item node create failed.
97  * @return <b>SOFTBUS_OK</b> if the set discovery callback is successful.
98  */
99 int32_t DiscSetDiscoverCallback(DiscModule moduleId, const DiscInnerCallback *callback);
100 
101 /**
102  * @ingroup softbus_disc_manager
103  * @brief Publish capabilities and create the necessary environment for their own capabilities information.
104  * @see {@link DiscUnpublish}.
105  * @param[in] moduleId Mouble Id. For details, see {@link DiscModule}.
106  * @param[in] info Indicates the pointer to the service publishing information.
107  * For details, see {@link PublishInfo}.
108  * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid.
109  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> if the Intelligent Soft Bus server fails to be initialized.
110  * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_CREATE</b> if the creation of the information node fails.
111  * @return <b>SOFTBUS_MEM_ERR</b> if Memcpy failed.
112  * @return <b>SOFTBUS_LOCK_ERR</b> if Mutex lock failed.
113  * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> if duplicate info.
114  * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> if item node create failed.
115  * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> if InnerFunction failed.
116  * @return <b>SOFTBUS_OK</b> if the active release is successful.
117  */
118 int32_t DiscPublish(DiscModule moduleId, const PublishInfo *info);
119 
120 /**
121  * @ingroup softbus_disc_manager
122  * @brief Start the scan and set the corresponding environment according to the scan information.
123  * @param[in] moduleId Mouble Id. For details, see {@link DiscModule}.
124  * @param[in] info Indicates the pointer to the service publishing information.
125  * For details, see {@link PublishInfo}.
126  * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid.
127  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> if the Intelligent Soft Bus server fails to be initialized.
128  * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_CREATE</b> if the creation of the information node fails.
129  * @return <b>SOFTBUS_MEM_ERR</b> if Memcpy failed.
130  * @return <b>SOFTBUS_LOCK_ERR</b> if Mutex lock failed.
131  * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> if duplicate info.
132  * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> if item node create failed.
133  * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> if InnerFunction failed.
134  * @return <b>SOFTBUS_OK</b> if the passive publish is successful.
135  */
136 int32_t DiscStartScan(DiscModule moduleId, const PublishInfo *info);
137 
138 /**
139  * @ingroup softbus_disc_manager
140  * @brief Cancel the ability to publish, and clear the configuration environment where it publishes information.
141  * @see {@link DiscPublish}.
142  * @param[in] moduleId module ID. For details, see {@link DiscModule}.
143  * @param[in] publishId the publish ID which will be stopped.
144  * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid.
145  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> if the Intelligent Soft Bus server fails to be initialized.
146  * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_DELETE</b> if info node delete failed.
147  * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> if InnerFunction failed.
148  * @return <b>SOFTBUS_OK</b> if the stop publish is successful.
149  */
150 int32_t DiscUnpublish(DiscModule moduleId, int32_t publishId);
151 
152 /**
153  * @ingroup softbus_disc_manager
154  * @brief Start the broadcast and create the necessary environment for its own broadcast information.
155  * @see {@link DiscStopAdvertise}.
156  * @param[in] moduleId module ID. For details, see {@link DiscModule}.
157  * @param[in] info Indicates the pointer to the service subscribe information.
158  * For details, see {@link SubscribeInfo}.
159  * @return <b>SOFTBUS_INVALID_PARAM</b> Invalid moduleId or info parameter.
160  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Discovery manager is not initialised.
161  * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_CREATE</b> InfoNode create failed.
162  * @return <b>SOFTBUS_MEM_ERR</b> Memcpy failed.
163  * @return <b>SOFTBUS_LOCK_ERR</b> Mutex lock failed.
164  * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> Duplicate info.
165  * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> ItemNode create failed.
166  * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> InnerFunction failed.
167  * @return <b>SOFTBUS_OK</b> Active discover successfully.
168  */
169 int32_t DiscStartAdvertise(DiscModule moduleId, const SubscribeInfo *info);
170 
171 /**
172  * @ingroup softbus_disc_manager
173  * @brief Subscription capability, configure the environment required for its own subscription information.
174  * @param[in] moduleId module ID. For details, see {@link DiscModule}.
175  * @param[in] info Indicates the pointer to the service subscribe information.
176  * For details, see {@link SubscribeInfo}.
177  * @return <b>SOFTBUS_INVALID_PARAM</b> Invalid moduleId or info parameter.
178  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Discovery manager is not initialised.
179  * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_CREATE</b> InfoNode create failed.
180  * @return <b>SOFTBUS_MEM_ERR</b> Memcpy failed.
181  * @return <b>SOFTBUS_LOCK_ERR</b> Mutex lock failed.
182  * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> Duplicate info.
183  * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> ItemNode create failed.
184  * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> InnerFunction failed.
185  * @return <b>SOFTBUS_OK</b> Passive discover successfully.
186  */
187 int32_t DiscSubscribe(DiscModule moduleId, const SubscribeInfo *info);
188 
189 /**
190  * @ingroup softbus_disc_manager
191  * @brief Stop the broadcast and clear the environment configured by the start broadcast.
192  * @see {@link DiscStartAdvertise}.
193  * @param[in] moduleId module ID. For details, see {@link DiscModule}.
194  * @param[in] subscribeId the subscribe ID which will be stop broadcast.
195  * @return <b>SOFTBUS_INVALID_PARAM</b> Invalid moduleId or info parameter.
196  * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Discovery manager is not initialised.
197  * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_DELETE</b> InfoNode delete failed.
198  * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> InnerFunction failed.
199  * @return <b>SOFTBUS_OK</b> Stop discover successfully.
200  */
201 int32_t DiscStopAdvertise(DiscModule moduleId, int32_t subscribeId);
202 
203 /**
204  * @brief Modify the connection state.
205  * @param[in] status Used to indicate a certain connection state discovered. For details, see {@link LinkStatus}.
206  * @param[in] medium A medium for sending information that can be used in a connection route.
207  * For details, see {@link ExchangeMedium}.
208  */
209 void DiscLinkStatusChanged(LinkStatus status, ExchangeMedium medium);
210 
211 /**
212  * @ingroup softbus_disc_manager
213  * @brief Update broadcast packets when the local device information changes.
214  * @param[in] type Information that changes
215  */
216 void DiscDeviceInfoChanged(InfoTypeChanged type);
217 
218 #ifdef __cplusplus
219 #if __cplusplus
220 }
221 #endif /* __cplusplus */
222 #endif /* __cplusplus */
223 
224 #endif /* DISC_MANAGER_INTERFACE_H */