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_H 17 #define DISC_MANAGER_H 18 19 #include "disc_interface.h" 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif 25 #endif 26 27 #define CAPABILITY_NUM 1 28 #define CAPABILITY_MAX_BITNUM 16 29 30 typedef struct { 31 int32_t freq; 32 uint32_t capabilityBitmap[CAPABILITY_NUM]; 33 uint8_t *capabilityData; 34 uint32_t dataLen; 35 bool ranging; 36 } PublishOption; 37 38 typedef struct { 39 int32_t freq; 40 bool isSameAccount; 41 bool isWakeRemote; 42 uint32_t capabilityBitmap[CAPABILITY_NUM]; 43 uint8_t *capabilityData; 44 uint32_t dataLen; 45 } SubscribeOption; 46 47 typedef enum { 48 PUBLISH_FUNC = 0, 49 UNPUBLISH_FUNC = 1, 50 STARTDISCOVERTY_FUNC = 2, 51 STOPDISCOVERY_FUNC = 3 52 } InterfaceFuncType; 53 54 typedef struct { 55 int32_t (*Publish)(const PublishOption *option); 56 int32_t (*StartScan)(const PublishOption *option); 57 int32_t (*Unpublish)(const PublishOption *option); 58 int32_t (*StopScan)(const PublishOption *option); 59 int32_t (*StartAdvertise)(const SubscribeOption *option); 60 int32_t (*Subscribe)(const SubscribeOption *option); 61 int32_t (*Unsubscribe)(const SubscribeOption *option); 62 int32_t (*StopAdvertise)(const SubscribeOption *option); 63 void (*LinkStatusChanged)(LinkStatus status); 64 void (*UpdateLocalDeviceInfo)(InfoTypeChanged type); 65 } DiscoveryFuncInterface; 66 67 typedef struct { 68 int32_t (*OnServerDeviceFound)(const char *packageName, const DeviceInfo *device, 69 const InnerDeviceInfoAddtions *additions); 70 } IServerDiscInnerCallback; 71 72 /** 73 * @brief Publish service to start publishing its own information to other devices. 74 * @see {@link DiscUnPublishService} 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 ndicates the pointer to the published information, 78 * which is used to publish the information body of its own information. For details, see {@link PublishInfo}. 79 * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 80 * @return <b>SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM</b> Error in message medium during message check. 81 * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Softbus found that management variables are not initialized. 82 * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_CREATE</b> The new publishing node corresponding to the discovery 83 * information has not been created 84 * @return <b>SOFTBUS_LOCK_ERR</b> Failed to lock. 85 * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> The information to be published is already in the list. 86 * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> The new project node corresponding to the discovery 87 * information was not created. 88 * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> Internal function error. 89 * @return <b>SOFTBUS_OK</b> Published self information successfully. 90 */ 91 int32_t DiscPublishService(const char *packageName, const PublishInfo *info); 92 93 /** 94 * @brief If the service is cancelled, the remote device cannot obtain its own information. 95 * @see {@link DiscPublishService} 96 * @param[in] packageName Indicates the pointer to the package name, 97 * and the name of the relevant package carrying its own capabilities. 98 * @param[in] publishId ID of the internal release information to be cancelled this time. 99 * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 100 * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Softbus found that management variables are not initialized. 101 * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_DELETE</b> Delete the inode corresponding to the publication id 102 * from the list. 103 * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> Internal function error. 104 * @return <b>SOFTBUS_OK</b> Unpublished service succeeded. 105 */ 106 int32_t DiscUnPublishService(const char *packageName, int32_t publishId); 107 108 /** 109 * @brief Start discovery, other devices can be discovered. 110 * @see {@link DiscStopDiscovery} 111 * @param[in] packageName Indicates the pointer to the package name, 112 * and the name of the relevant package carrying its own capabilities. 113 * @param[in] info Indicates a pointer to published information used 114 * to discover the body of information for a specific capability. For more information, see {@link SubscribeInfo}. 115 * @param[in] cb Indicates the pointer to the discovery callback, It is used to inform yourself, 116 * Whether the discovery capability is successfully started after the discovery function is triggered. 117 * For more information, see {@link IServerDiscInnerCallback}. 118 * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 119 * @return <b>SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM</b> Error in message medium during message check. 120 * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Softbus found that management variables are not initialized. 121 * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_CREATE</b> The new publishing node corresponding to the discovery 122 * information has not been created. 123 * @return <b>SOFTBUS_LOCK_ERR</b> Failed to lock. 124 * @return <b>SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM</b> The information to be published is already in the list. 125 * @return <b>SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE</b> The new project node corresponding to the discovery 126 * information was not created. 127 * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> Internal function error. 128 * @return <b>SOFTBUS_OK</b> Passive discovery function successfully started. 129 */ 130 int32_t DiscStartDiscovery(const char *packageName, const SubscribeInfo *info, const IServerDiscInnerCallback *cb); 131 132 /** 133 * @brief Stop discovering, stop discovering other devices. 134 * @see {@link DiscStartDiscovery} 135 * @param[in] packageName Indicates the pointer to the package name, 136 * and the name of the relevant package carrying its own capabilities. 137 * @param[in] subscribeId ID to stop discovery this time. 138 * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 139 * @return <b>SOFTBUS_DISCOVER_MANAGER_NOT_INIT</b> Softbus found that management variables are not initialized. 140 * @return <b>SOFTBUS_DISCOVER_MANAGER_INFO_NOT_DELETE</b> Delete the inode corresponding to the publication id 141 * from the list. 142 * @return <b>SOFTBUS_DISCOVER_MANAGER_INNERFUNCTION_FAIL</b> Internal function error. 143 * @return <b>SOFTBUS_OK</b> Passive stop discovery function stopped successfully 144 */ 145 int32_t DiscStopDiscovery(const char *packageName, int32_t subscribeId); 146 147 #ifdef __cplusplus 148 #if __cplusplus 149 } 150 #endif /* __cplusplus */ 151 #endif /* __cplusplus */ 152 153 #endif /* DISC_MANAGER_H */