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