• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SOFTBUS_CLIENT_SERVICE_MANAGER_H
17 #define SOFTBUS_CLIENT_SERVICE_MANAGER_H
18 
19 #include "discovery_service.h"
20 #include "stdint.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @brief Client initialization. Configure the storage information environment,
28  * this interface is only called once when the softbus service is created.
29  * @see {@link DiscClientDeinit}
30  * @return <b>SOFTBUS_MALLOC_ERR</b> Failed to allocate space for global variable of discovery information.
31  * @return <b>SOFTBUS_ERR</b> Failed to initialize the server agent on the discovery side.
32  * @return <b>SOFTBUS_OK</b> The discoverer client was initialized successfully.
33  */
34 int32_t DiscClientInit(void);
35 
36 /**
37  * @brief The client deinitializes, releasing the stored information.
38  * This interface is only called once when the softbus service is destroyed.
39  * @see {@link DiscClientInit}
40  */
41 void DiscClientDeinit(void);
42 
43 /**
44  * @brief Internal publishing service. Publish its own capability information to other devices,
45  * and other devices can capture this information to establish connections.
46  * @see {@link UnPublishServiceInner}
47  * @param[in] packageName Indicates the pointer to the package name,
48  * and the name of the relevant package carrying its own capabilities.
49  * @param[in] info Indicates the pointer to the published information,
50  * which is used to publish the information body of its own information. For details, see {@link PublishInfo}.
51  * @param[in] cb Indicates the pointer to the callback of the publishing function,
52  * which is used to notify itself whether the publishing of its
53  * own information is successful after the publishing function is triggered. For details, see {@link IPublishCallback}.
54  * @return <b>SOFTBUS_ERR</b> Failed to publish internal information function.
55  * @return <b>SOFTBUS_OK</b> The function of internal publishing self information was published successfully.
56  */
57 int32_t PublishServiceInner(const char *packageName, const PublishInfo *info, const IPublishCallback *cb);
58 
59 /**
60  * @brief Internal unpublish service. Stop publishing its own information,
61  * and external devices cannot capture this device's capability information.
62  * @see {@link PublishServiceInner}
63  * @param[in] packageName Indicates the pointer to the package name,
64  * and the name of the relevant package carrying its own capabilities.
65  * @param[in] publishId ID of the internal release information to be cancelled this time.
66  * @return <b>SOFTBUS_ERR</b> Internal unpublishing function failed. Other devices can still find the device.
67  * @return <b>SOFTBUS_OK</b> The internal unpublishing function is successful,
68  * and the party cannot publish its own information.
69  */
70 int32_t UnPublishServiceInner(const char *packageName, int32_t publishId);
71 
72 /**
73  * @brief Internal discovery service. Other devices can be discovered.
74  * @see {@link StopDiscoveryInner}
75  * @param[in] packageName Indicates the pointer to the package name,
76  * and the name of the relevant package carrying its own capabilities.
77  * @param[in] info Indicates a pointer to published information used
78  * to discover the body of information for a specific capability. For more information, see {@link SubscribeInfo}.
79  * @param[in] cb Indicates the pointer to the discovery callback, It is used to inform yourself,
80  * Whether the discovery capability is successfully started after the discovery function is triggered.
81  * For more information, see {@link IDiscoveryCallback}.
82  * @return <b>SOFTBUS_ERR</b> The internal start Discovery Function failed to start. No other devices can be found.
83  * @return <b>SOFTBUS_OK</b> The internal start discovery function is started successfully.
84  * You can discover specific capability devices.
85  */
86 int32_t StartDiscoveryInner(const char *packageName, const SubscribeInfo *info, const IDiscoveryCallback *cb);
87 
88 /**
89  * @brief Stop discovery service internally. Stop discovering other devices,
90  * after which other devices cannot be discovered.
91  * @see {@link StartDiscoveryInner}
92  * @param[in] packageName Indicates the pointer to the package name,
93  * and the name of the relevant package carrying its own capabilities.
94  * @param[in] subscribeId ID to stop discovery this time.
95  * @return <b>SOFTBUS_ERR</b> The internal stop discovery function cannot be started. Other devices can still be found.
96  * @return <b>SOFTBUS_OK</b> Internal stop discovery function started successfully.
97  * You cannot discover devices with specific functions.
98  */
99 int32_t StopDiscoveryInner(const char *packageName, int32_t subscribeId);
100 
101 /**
102  * @brief The server discovers the local device and calls this callback.
103  * @see {@link DiscClientOnDiscoverySuccess} or {@link DiscClientOnDiscoverFailed}.
104  * @param[in] device Indicates a pointer to device information to record the devices on
105  * which the discovery client was discovered. For more information, see {@link DeviceInfo}.
106  */
107 void DiscClientOnDeviceFound(const DeviceInfo *device);
108 
109 /**
110  * @brief When the server subscribes to the local device successfully,
111  * this callback is called to notify the local device.
112  * @see {@link DiscClientOnDeviceFound} or {@link DiscClientOnDiscoverFailed}.
113  * @param[in] subscribeId The id of the subscription information used to record
114  * the successful discovery of the discovered peer.
115  */
116 void DiscClientOnDiscoverySuccess(int32_t subscribeId);
117 
118 /**
119  * @brief When the server fails to subscribe to the local device, this callback is called to notify the local device.
120  * @see {@link DiscClientOnDiscoverySuccess} or {@link DiscClientOnDeviceFound}.
121  * @param[in] subscribeId The id of the subscription information used to record the discovered peer discovery failure.
122  * @param[in] failReason reason of failure. For more information, see {@link DiscoveryFailReason}.
123  */
124 void DiscClientOnDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason);
125 
126 /**
127  * @brief The local end publishes the service successfully, and the callback is called to notify the local end.
128  * @see {@link DiscClientOnPublishFail}.
129  * @param[in] publishId The information id used for the client to publish successfully.
130  */
131 void DiscClientOnPublishSuccess(int32_t publishId);
132 
133 /**
134  * @brief The local end fails to publish the service, and this callback is called to notify the local end.
135  * @see {@link DiscClientOnPublishSuccess}.
136  * @param[in] publishId The information id used for the client to publish failed.
137  * @param[in] reason reason of failure. For more information, see {@link PublishFailReason}.
138  */
139 void DiscClientOnPublishFail(int32_t publishId, PublishFailReason reason);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif // SOFTBUS_CLIENT_SERVICE_MANAGER_H
146