1 /* 2 * Copyright (c) 2021-2022 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 high-speed, secure communication between devices. 21 * 22 * This module implements unified distributed communication capability management between nearby devices, and provides 23 * link-independent device discovery and transmission interfaces to support service publishing and data transmission. 24 * 25 * @since 1.0 26 * @version 1.0 27 */ 28 /** @} */ 29 30 /** 31 * @file softbus_bus_center.h 32 * 33 * @brief Declares functions and constants for the bus center of the Intelligent Soft Bus. 34 * 35 * The functions are used to perform 36 * the following operations: \n 37 * <ul> 38 * <li>Adding a device to and removing a device from a LNN</li> 39 * <li>Listening for device online, offline, and information change events</li> 40 * 41 * @since 1.0 42 * @version 1.0 43 */ 44 45 #ifndef SOFTBUS_BUS_CENTER_H 46 #define SOFTBUS_BUS_CENTER_H 47 48 #include <stdbool.h> 49 #include <stdint.h> 50 51 #include "softbus_common.h" 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 /** 58 * @brief Indicates the length of a device name buffer, including the terminating null character <b>\0</b>. 59 * 60 * @since 1.0 61 * @version 1.0 62 */ 63 #define DEVICE_NAME_BUF_LEN 128 64 65 /** 66 * @brief Indicates the mask bit for a device online event. 67 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 68 * 69 * @since 1.0 70 * @version 1.0 71 */ 72 #define EVENT_NODE_STATE_ONLINE 0x1 73 74 /** 75 * @brief Indicates the mask bit for a device offline event. 76 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 77 * 78 * @since 1.0 79 * @version 1.0 80 */ 81 #define EVENT_NODE_STATE_OFFLINE 0x02 82 83 /** 84 * @brief Indicates the mask bit for a peer device information change event. 85 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 86 * 87 * @since 1.0 88 * @version 1.0 89 */ 90 #define EVENT_NODE_STATE_INFO_CHANGED 0x04 91 92 /** 93 * @brief Indicates the mask bit for a LNN node running status change event. 94 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 95 * 96 * @since 1.0 97 * @version 1.0 98 */ 99 #define EVENT_NODE_STATUS_CHANGED 0x08 100 101 /** 102 * @brief Indicates mask bits for {@link INodeStateCb.events}. 103 * 104 * @since 1.0 105 * @version 1.0 106 */ 107 #define EVENT_NODE_STATE_MASK 0xF 108 109 /** 110 * @brief The maximum length of meta node bypass info {@link MetaNodeConfigInfo.bypassInfo}. 111 * 112 * @since 1.0 113 * @version 1.0 114 */ 115 #define META_NODE_BYPASS_INFO_LEN 64 116 117 /** 118 * @brief Indicates the maximum length of the callerId, including the terminating null character <b>\0</b>. 119 * 120 * @since 1.0 121 * @version 1.0 122 */ 123 #define CALLER_ID_MAX_LEN 128 124 125 /** 126 * @brief Indicates the maximum length of the custom user data. 127 * 128 * @since 1.0 129 * @version 1.0 130 */ 131 #define USER_DATA_MAX_LEN 256 132 133 /** 134 * @brief The maximum of meta node {@link MetaNodeConfigInfo.bypassInfo}. 135 * 136 * @since 1.0 137 * @version 1.0 138 */ 139 #define MAX_META_NODE_NUM 3 140 141 /** 142 * @brief Enumerates keys for an online device. 143 * The key can be obtained via {@link GetNodeKeyInfo}. 144 * 145 * @since 1.0 146 * @version 1.0 147 */ 148 typedef enum { 149 NODE_KEY_UDID = 0, /**< UDID in string format*/ 150 NODE_KEY_UUID, /**< UUID in string format */ 151 NODE_KEY_MASTER_UDID, /**< UDID of device in string format */ 152 NODE_KEY_BR_MAC, /**< BR MAC in string format */ 153 NODE_KEY_IP_ADDRESS, /**< IP address in string format */ 154 NODE_KEY_DEV_NAME, /**< Device name in string format */ 155 NODE_KEY_NETWORK_CAPABILITY, /**< Network capability in number format */ 156 NODE_KEY_NETWORK_TYPE, /**< Network type in number format */ 157 NODE_KEY_BLE_OFFLINE_CODE, /**< Ble offlinecode in string format */ 158 NODE_KEY_DATA_CHANGE_FLAG, /**< Device info change flag in number format */ 159 NODE_KEY_NODE_ADDRESS, /**< Node address in string format */ 160 } NodeDeviceInfoKey; 161 162 /** 163 * @brief Enumerates supported network capabilities. 164 * 165 * @since 1.0 166 * @version 1.0 167 */ 168 typedef enum { 169 BIT_BLE = 0, /**< Support BLE */ 170 BIT_BR, /**< Support BR */ 171 BIT_WIFI, /**< Support WIFI */ 172 BIT_WIFI_P2P, /**< Support WIFI P2P */ 173 BIT_WIFI_24G, /**< Support WIFI 2.4G */ 174 BIT_WIFI_5G, /**< Support WIFI 5G */ 175 BIT_ETH, /**< Support ETH */ 176 BIT_COUNT, /**< Invalid type */ 177 } NetCapability; 178 179 /** 180 * @brief Enumerates network types for an online device. 181 * 182 * @since 1.0 183 * @version 1.0 184 */ 185 typedef enum { 186 BIT_NETWORK_TYPE_UNKNOWN = 0, /**< Unknown network type */ 187 BIT_NETWORK_TYPE_WIFI, /**< WIFI network type */ 188 BIT_NETWORK_TYPE_BLE, /**< BLE network type */ 189 BIT_NETWORK_TYPE_BR, /**< BR network type */ 190 BIT_NETWORK_TYPE_P2P, /**< P2P network type */ 191 BIT_NETWORK_TYPE_COUNT, /**< Invalid type */ 192 } NetworkType; 193 194 /** 195 * @brief Enumerates accuracy for time synchronize among device. 196 * 197 * @since 1.0 198 * @version 1.0 199 */ 200 typedef enum { 201 LOW_ACCURACY = 0, /**< Low accuracy */ 202 NORMAL_ACCURACY, /**< Normal accuracy */ 203 HIGH_ACCURACY, /**< High accuracy */ 204 SUPER_HIGH_ACCURACY, /**< Super high accuracy */ 205 UNAVAIL_ACCURACY = 0xFFFF, /**< Invalid accuracy */ 206 } TimeSyncAccuracy; 207 208 /** 209 * @brief Enumerates time synchronize period among device. 210 * 211 * @since 1.0 212 * @version 1.0 213 */ 214 typedef enum { 215 SHORT_PERIOD = 0, /**< Short accuracy */ 216 NORMAL_PERIOD, /**< Normal accuracy */ 217 LONG_PERIOD, /**< Long accuracy */ 218 } TimeSyncPeriod; 219 220 /** 221 * @brief Enumerates time synchronize flag. 222 * 223 * @since 1.0 224 * @version 1.0 225 */ 226 typedef enum { 227 NODE_SPECIFIC = 0, /**< Time sync in a specific mode */ 228 ALL_LNN, /**< Time sync during the entire networking */ 229 WRITE_RTC, /**< Write RTC synchronization */ 230 } TimeSyncFlag; 231 232 /** 233 * @brief Defines the basic information of a device. 234 * 235 * @since 1.0 236 * @version 1.0 237 */ 238 typedef struct { 239 char networkId[NETWORK_ID_BUF_LEN]; /**< Device network id */ 240 char deviceName[DEVICE_NAME_BUF_LEN]; /**< Device name */ 241 uint16_t deviceTypeId; /**< Device type id */ 242 } NodeBasicInfo; 243 244 /** 245 * @brief Enumerates device information change types. For details, see {@link INodeStateCb.onNodeBasicInfoChanged}. 246 * 247 * @since 1.0 248 * @version 1.0 249 */ 250 typedef enum { 251 TYPE_NETWORK_ID = 0, /**< Network ID change */ 252 TYPE_DEVICE_NAME, /**< Device name change */ 253 TYPE_NETWORK_INFO, /**< Network Info change */ 254 } NodeBasicInfoType; 255 256 /** 257 * @brief Defines the running status about a device. 258 * 259 * @since 1.0 260 * @version 1.0 261 */ 262 typedef struct { 263 NodeBasicInfo basicInfo; /**< The basic info of device */ 264 uint16_t authStatus; /**< The auth state of device */ 265 uint16_t dataBaseStatus; /**< The data base state of device */ 266 uint16_t meshType; /**< The mesh type of device */ 267 uint16_t reserved[NODE_STATUS_MAX_NUM - 3]; /**< The reserved data of device */ 268 } NodeStatus; 269 270 /** 271 * @brief Enumerates device information change types. For details, see {@link INodeStateCb.onNodeStatusChanged}. 272 * 273 * @since 1.0 274 * @version 1.0 275 */ 276 typedef enum { 277 TYPE_AUTH_STATUS = 2, /**< Certify status change */ 278 TYPE_DATABASE_STATUS = 3, /**< Database change */ 279 TYPE_MESH_TYPE = 4, /**< Lnn mesh typechange */ 280 TYPE_STATUS_MAX = 5, /**< Max num */ 281 } NodeStatusType; 282 283 /** 284 * @brief Defines time synchronize result. 285 * 286 * @since 1.0 287 * @version 1.0 288 */ 289 typedef struct { 290 int32_t millisecond; /**< Number of milli second */ 291 int32_t microsecond; /**< Number of micro second */ 292 TimeSyncAccuracy accuracy; /**< Time sync accuracy */ 293 } TimeSyncResult; 294 295 /** 296 * @brief Defines time synchronize result info. 297 * 298 * @since 1.0 299 * @version 1.0 300 */ 301 typedef struct { 302 TimeSyncResult result; /**< Time synchronize result */ 303 TimeSyncFlag flag; /**< Time synchronize flag */ 304 union { 305 char targetNetworkId[NETWORK_ID_BUF_LEN]; /**< The network id of time sync target device */ 306 char masterNetworkId[NETWORK_ID_BUF_LEN]; /**< The network id of node */ 307 } target; 308 } TimeSyncResultInfo; 309 310 /** 311 * @brief Enumerates error codes for service publishing failures. 312 * 313 * The error codes are returned to the caller through <b>IPublishCallback</b>. 314 * 315 * @since 1.0 316 * @version 1.0 317 */ 318 typedef enum { 319 PUBLISH_LNN_SUCCESS = 0, /**< Publish success */ 320 PUBLISH_LNN_NOT_SUPPORT_MEDIUM = 1, /**< Unsupported medium */ 321 PUBLISH_LNN_INTERNAL = 2, /**< Internal error */ 322 PUBLISH_LNN_UNKNOWN = 0xFF /**< Unknown reason */ 323 } PublishResult; 324 325 /** 326 * @brief Enumerates error codes for service subscription failures. 327 * 328 * The error codes are returned to the caller through <b>IDiscoveryCallback</b>. 329 * 330 * @since 1.0 331 * @version 1.0 332 */ 333 typedef enum { 334 REFRESH_LNN_SUCCESS = 0, /**< Refresh success */ 335 REFRESH_LNN_NOT_SUPPORT_MEDIUM = 1, /**< Unsupported medium */ 336 REFRESH_LNN_INTERNAL = 2, /**< Internal error */ 337 REFRESH_LNN_UNKNOWN = 0xFF /**< Unknown error */ 338 } RefreshResult; 339 340 /** 341 * @brief Defines the callbacks for successful and failed service publishing. 342 * 343 * @since 1.0 344 * @version 1.0 345 */ 346 typedef struct { 347 /** 348 * @brief Callback for publish result. 349 * 350 * @param publishId the publish Id which has been published. 351 * @param reason the publish result of this time. 352 * 353 * @since 1.0 354 * @version 1.0 355 */ 356 void (*OnPublishResult)(int publishId, PublishResult reason); 357 } IPublishCb; 358 359 /** 360 * @brief Defines a callback for service subscription. 361 * 362 * Three types of callbacks are available. 363 * 364 * @since 1.0 365 * @version 1.0 366 */ 367 typedef struct { 368 /** 369 * @brief Callback that is invoked when a device is found. 370 * 371 * @param device Indicates the pointer to the device info about device. 372 * For details, see {@link DeviceInfo}. 373 * 374 * @since 1.0 375 * @version 1.0 376 */ 377 void (*OnDeviceFound)(const DeviceInfo *device); 378 /** 379 * @brief Callback for a subscription result. 380 * 381 * @param refreshId Indicates the refresh Id which. 382 * @param reason Indicates the result of this time. For details, see {@link RefreshResult}. 383 * 384 * @since 1.0 385 * @version 1.0 386 */ 387 void (*OnDiscoverResult)(int32_t refreshId, RefreshResult reason); 388 } IRefreshCallback; 389 390 /** 391 * @brief Defines a callback that is invoked when the device state or information changes. 392 * For details, see {@link RegNodeDeviceStateCb}. 393 * 394 * @since 1.0 395 * @version 1.0 396 */ 397 typedef struct { 398 /** 399 * Mask of an event that is listened for. 400 * The event can be received only if the corresponding mask bit is set and the callback is specified. 401 */ 402 uint32_t events; 403 /** 404 * @brief Called when a specified device, rather than a specified ability, gets online. 405 * 406 * @param info Indicates the pointer to the basic information about the device. 407 * For details, see {@link NodeBasicInfo}. 408 * 409 * @since 1.0 410 * @version 1.0 411 */ 412 void (*onNodeOnline)(NodeBasicInfo *info); 413 /** 414 * @brief Called when a specified device, rather than a specified ability, gets offline. 415 * 416 * @param info Indicates the pointer to the basic information about the device. 417 * For details, see {@link NodeBasicInfo}. 418 * 419 * @since 1.0 420 * @version 1.0 421 */ 422 void (*onNodeOffline)(NodeBasicInfo *info); 423 /** 424 * @brief Called when the basic information of a device changes. 425 * 426 * @param type Indicates the device type. For details, see {@link NodeBasicInfoType}. 427 * @param info Indicates the pointer to the new basic information of the device. 428 * For details, see {@link NodeBasicInfo}. 429 * 430 * @since 1.0 431 * @version 1.0 432 */ 433 void (*onNodeBasicInfoChanged)(NodeBasicInfoType type, NodeBasicInfo *info); 434 /** 435 * @brief Called when the running status of a device changes. 436 * 437 * @param type Indicates the device type. For details, see {@link NodeStatusType}. 438 * @param status Indicates the pointer to the new status of the device. 439 * For details, see {@link NodeStatus}. 440 * 441 * @since 1.0 442 * @version 1.0 443 */ 444 void (*onNodeStatusChanged)(NodeStatusType type, NodeStatus *status); 445 } INodeStateCb; 446 447 /** 448 * @brief Defines a callback that is invoked when the time synchronize has result. 449 * 450 * @since 1.0 451 * @version 1.0 452 */ 453 typedef struct { 454 /** 455 * @brief Called when the time synchronize has result. 456 * 457 * @param info Contains the time synchronize result info, see {@link TimeSyncResultInfo}. 458 * @param retCode Indicates the result code. Value <b>0</b> indicates that the time synchronize is successful and 459 * result is valid, and any other value indicates the opposite. 460 * 461 * @since 1.0 462 * @version 1.0 463 */ 464 void (*onTimeSyncResult)(const TimeSyncResultInfo *info, int32_t retCode); 465 } ITimeSyncCb; 466 467 /** 468 * @brief Defines a meta node configuration, see {@link ActiveMetaNode}. 469 * 470 * @since 1.0 471 * @version 1.0 472 */ 473 typedef struct { 474 char udid[UDID_BUF_LEN]; /**< The udid of meta node */ 475 char deviceName[DEVICE_NAME_BUF_LEN]; /**< The name of meta node */ 476 uint16_t deviceTypeId; /**< The device type id of meta node */ 477 uint8_t addrNum; /**< The connection addr type of meta node */ 478 ConnectionAddr addr[CONNECTION_ADDR_MAX]; /**< The connection addr of meta node */ 479 char bypassInfo[META_NODE_BYPASS_INFO_LEN]; /**< The pass info of meta node */ 480 } MetaNodeConfigInfo; 481 482 /** 483 * @brief Defines a meta node information, see {@link MetaNodeInfo}. 484 * 485 * @since 1.0 486 * @version 1.0 487 */ 488 typedef struct { 489 char metaNodeId[NETWORK_ID_BUF_LEN]; /**< The id of meta node */ 490 bool isOnline; /**< The online state of meta node */ 491 MetaNodeConfigInfo configInfo; /**< The node ConfigInfo of meta node */ 492 } MetaNodeInfo; 493 494 /** 495 * @brief Defines heartbeat mode parameter, see {@link GearMode}. 496 * 497 * @since 1.0 498 * @version 1.0 499 */ 500 typedef struct { 501 ModeCycle cycle; /**< Heartbeat mode cycle */ 502 ModeDuration duration; /**< Heartbeat mode duration */ 503 bool wakeupFlag; /**< Heartbeat wakeup peer device or not */ 504 } GearMode; 505 506 /** 507 * @brief Enumerates secret key types. 508 * 509 * @since 1.0 510 * @version 1.0 511 */ 512 typedef enum { 513 PROXY_TRANSMISION = 0, /**< Proxy Transmision */ 514 PROXY_HEARTBEAT = 1, /**< Proxy Heartbeat */ 515 CUSTOM_UNKNOWN, /**< Proxy Unknown */ 516 } CustomType; 517 518 /** 519 * @brief Defines parameter, see {@link CustomData}. 520 * 521 * @since 1.0 522 * @version 1.0 523 */ 524 typedef struct { 525 CustomType type; /**< User type */ 526 uint8_t data[USER_DATA_MAX_LEN]; /**< User data */ 527 } CustomData; 528 529 /** 530 * @brief Called when a device is added to a LNN via {@link JoinLNN}. 531 * 532 * @param addr Indicates the pointer to the address of the peer device. 533 * @param networkId Indicates the pointer to the network ID of the device if it is successfully added to the LNN. 534 * This parameter makes no sense if the device fails to be added to the LNN. 535 * @param retCode Indicates the result code. Value <b>0</b> indicates that the device is successfully added to the LNN, 536 * and any other value indicates the opposite. 537 * 538 * @since 1.0 539 * @version 1.0 540 */ 541 typedef void (*OnJoinLNNResult)(ConnectionAddr *addr, const char *networkId, int32_t retCode); 542 543 /** 544 * @brief Called when a device is added to a LNN via {@link JoinLNN}. 545 * 546 * @param addr Indicates the pointer to the address of the peer device. 547 * @param networkId Indicates the pointer to the network ID of the device if it is successfully added to the LNN. 548 * This parameter makes no sense if the device fails to be added to the LNN. 549 * @param retCode Indicates the result code. Value <b>0</b> indicates that the device is successfully added to the LNN, 550 * and any other value indicates the opposite. 551 * 552 * @since 1.0 553 * @version 1.0 554 */ 555 typedef void (*OnJoinMetaNodeResult)(ConnectionAddr *addr, const char *networkId, int32_t retCode); 556 557 /** 558 * @brief Called when a device is removed from a LNN via {@link LeaveLNN}. 559 * 560 * @param networkId Indicates the pointer to the network ID of the device. 561 * @param retCode Indicates the result code. Value <b>0</b> indicates that the device is successfully 562 * removed from the LNN, and any other value indicates the opposite. 563 * 564 * @since 1.0 565 * @version 1.0 566 */ 567 typedef void (*OnLeaveLNNResult)(const char *networkId, int32_t retCode); 568 569 /** 570 * @brief Called when a device is removed from a LNN via {@link LeaveMetaNode}. 571 * 572 * @param networkId Indicates the pointer to the network ID of the device. 573 * @param retCode Indicates the result code. Value <b>0</b> indicates that the device is successfully 574 * removed from the LNN, and any other value indicates the opposite. 575 * 576 * @since 1.0 577 * @version 1.0 578 */ 579 typedef void (*OnLeaveMetaNodeResult)(const char *networkId, int32_t retCode); 580 581 /** 582 * @brief Adds the current device to the LNN where a specified device resides. 583 * 584 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 585 * For the same caller, the value of this parameter must be the same for all functions. 586 * @param target Indicates the pointer to the address of the specified device. For details, see {@link ConnectionAddr}. 587 * @param cb Indicates the callback for the result. If you set this parameter to NULL, you will not receive the result. 588 * 589 * @return Returns <b>0</b> if the request to add the device is accepted, and the result can be obtained from the 590 * callback; returns any other value if the device fails to be added to the network, in which case you will not receive 591 * the result. 592 * 593 * @since 1.0 594 * @version 1.0 595 */ 596 int32_t JoinLNN(const char *pkgName, ConnectionAddr *target, OnJoinLNNResult cb); 597 598 /** 599 * @brief Adds the current device to the MetaNode where a specified device resides. 600 * 601 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 602 * For the same caller, the value of this parameter must be the same for all functions. 603 * @param target Indicates the pointer to the address of the specified device. For details, see {@link ConnectionAddr}. 604 * @param customData Indicates the pointer to the key of the specified device. 605 * @param cb Indicates the callback for the result. If you set this parameter to NULL, you will not receive the result. 606 * 607 * @return Returns <b>0</b> if the request to add the device is accepted, and the result can be obtained from the 608 * callback; returns any other value if the device fails to be added to the network, in which case you will not receive 609 * the result. 610 * 611 * @since 1.0 612 * @version 1.0 613 */ 614 int32_t JoinMetaNode(const char *pkgName, ConnectionAddr *target, CustomData *customData, OnJoinMetaNodeResult cb); 615 616 /** 617 * @brief Removes the current device from the LNN. 618 * 619 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 620 * For the same caller, the value of this parameter must be the same for all functions. 621 * @param networkId Indicates the pointer to the network ID that is returned 622 * after the device is added to the LNN via {@link JoinLNN}. 623 * @param cb Indicates the callback for the result. If you set this parameter to <b>NULL</b>, 624 * you will not receive the result. 625 * 626 * @return Returns <b>0</b> if the request to remove the device is accepted, and the result can be obtained from the 627 * callback; returns any other value if the device fails to be removed from the network, in which case you will not 628 * receive the result. 629 * 630 * @since 1.0 631 * @version 1.0 632 */ 633 int32_t LeaveLNN(const char *pkgName, const char *networkId, OnLeaveLNNResult cb); 634 635 /** 636 * @brief Removes the current device from the MetaNode. 637 * 638 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 639 * For the same caller, the value of this parameter must be the same for all functions. 640 * @param networkId Indicates the pointer to the network ID that is returned 641 * after the device is added to the LNN via {@link JoinMetaNode}. 642 * @param cb Indicates the callback for the result. If you set this parameter to <b>NULL</b>, 643 * you will not receive the result. 644 * 645 * @return Returns <b>0</b> if the request to remove the device is accepted, and the result can be obtained from the 646 * callback; returns any other value if the device fails to be removed from the network, in which case you will not 647 * receive the result. 648 * 649 * @since 1.0 650 * @version 1.0 651 */ 652 int32_t LeaveMetaNode(const char *pkgName, const char *networkId, OnLeaveMetaNodeResult cb); 653 654 /** 655 * @brief Registers a callback for device state changes, rather than a specified ability, gets online. 656 * 657 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 658 * For the same caller, the value of this parameter must be the same for all functions. 659 * @param callback Indicates the pointer to the callback to register. For details, see {@link INodeStateCb}. 660 * 661 * @return Returns <b>0</b> if the registration is successful; returns any other value otherwise. 662 * 663 * @since 1.0 664 * @version 1.0 665 */ 666 int32_t RegNodeDeviceStateCb(const char *pkgName, INodeStateCb *callback); 667 668 /** 669 * @brief Unregisters a callback for device state changes. 670 * 671 * @param callback Indicates the pointer to the callback to unregister. For details, see {@link INodeStateCb}. 672 * 673 * @return Returns <b>0</b> if the unregistration is successful; returns any other value otherwise. 674 * 675 * @since 1.0 676 * @version 1.0 677 */ 678 int32_t UnregNodeDeviceStateCb(INodeStateCb *callback); 679 680 /** 681 * @brief Obtains basic information about all the online devices. 682 * 683 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 684 * For the same caller, the value of this parameter must be the same for all functions. 685 * @param info Indicates the double pointer to the memory that stores the obtained basic information. 686 * @param infoNum Indicates the pointer to the number of devices. 687 * 688 * @return Returns <b>0</b> if the basic information is obtained, in which case <b>info</b> and <b>infoNum</b> are 689 * valid; returns any other value otherwise. 690 * 691 * @since 1.0 692 * @version 1.0 693 */ 694 int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum); 695 696 /** 697 * @brief Releases the memory returned by {@link GetAllNodeDeviceInfo}. 698 * 699 * @param info Indicates the pointer to the memory returned by {@link GetAllNodeDeviceInfo}. 700 * 701 * @since 1.0 702 * @version 1.0 703 */ 704 void FreeNodeInfo(NodeBasicInfo *info); 705 706 /** 707 * @brief Obtains basic information about the current device. 708 * 709 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 710 * For the same caller, the value of this parameter must be the same for all functions. 711 * @param info Indicates the double pointer to the memory that stores the obtained basic information. 712 * 713 * @return Returns <b>0</b> if the basic information is obtained, in which case <b>info</b> is valid; 714 * returns any other value otherwise. 715 * 716 * @since 1.0 717 * @version 1.0 718 */ 719 int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info); 720 721 /** 722 * @brief Set the Node Data Change Flag object. 723 * 724 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 725 * For the same caller, the value of this parameter must be the same for all functions. 726 * @param networkId Indicates the pointer to the network ID of the device. 727 * @param dataChangeFlag Indicates the data change flag. 728 * 729 * @return Returns <b>0</b> if set change flag success, returns any other value otherwise. 730 * 731 * @since 1.0 732 * @version 1.0 733 */ 734 int32_t SetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag); 735 736 /** 737 * @brief Obtains a specified {@link NodeDeviceInfoKey} of an online device. 738 * 739 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 740 * For the same caller, the value of this parameter must be the same for all functions. 741 * @param networkId Indicates the pointer to the network ID of the device. 742 * @param key Indicates the key to be obtained. 743 * @param info Indicates the pointer to the buffer that stores the obtained key. 744 * @param infoLen Indicates the buffer length. 745 * 746 * @return Returns <b>0</b> if the {@link NodeDeviceInfoKey} is obtained, in which case <b>info</b> is valid; 747 * returns any other value otherwise. 748 * 749 * @since 1.0 750 * @version 1.0 751 */ 752 int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, 753 NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen); 754 755 /** 756 * @brief Start the time synchronize with specific target node. 757 * 758 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 759 * For the same caller, the value of this parameter must be the same for all functions. 760 * @param targetNetworkId Indicates the pointer to the address of the specified device. 761 * @param accuracy Time synchronize accuracy. 762 * @param period Time synchronize period 763 * @param cb Indicates the callback for the result. 764 * 765 * @return Returns <b>0</b> if the request is accepted, and the result can be obtained from the 766 * callback; returns any other value if the request fails, in which case you will not receive 767 * the result. 768 * 769 * @since 1.0 770 * @version 1.0 771 */ 772 int32_t StartTimeSync(const char *pkgName, const char *targetNetworkId, TimeSyncAccuracy accuracy, 773 TimeSyncPeriod period, ITimeSyncCb *cb); 774 775 /** 776 * @brief Stop the time synchronize with specific target node. 777 * 778 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 779 * For the same caller, the value of this parameter must be the same for all functions. 780 * @param targetNetworkId Indicates the pointer to the address of the specified device. 781 * 782 * @return Returns <b>0</b> if the request is removed; returns any other value if the request fails. 783 * 784 * @since 1.0 785 * @version 1.0 786 */ 787 int32_t StopTimeSync(const char *pkgName, const char *targetNetworkId); 788 789 /** 790 * @brief Publishes a specified service. 791 * 792 * Peer devices in the same LAN as the device that publishes this service can discover this service as needed. 793 * The service is identified by <b>publicId</b> and <b>pkgName</b>. 794 * 795 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 796 * @param info Indicates the pointer to the service publishing information. For details, see {@link PublishInfo}. 797 * @param cb Indicates the pointer to the service publishing callback {@link IPublishCb}. 798 * 799 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 800 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 801 * @return Returns <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked. 802 * @return Returns <b>SOFTBUS_OK</b> if the service is successfully published. 803 * 804 * @since 1.0 805 * @version 1.0 806 */ 807 int32_t PublishLNN(const char *pkgName, const PublishInfo *info, const IPublishCb *cb); 808 809 /** 810 * @brief stoppublishes a specified service. 811 * 812 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 813 * @param publishId Indicates the service ID. 814 * 815 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>pkgName</b> is invalid. 816 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 817 * @return Returns <b>SOFTBUS_OK</b> if the service is successfully unpublished. 818 * 819 * @since 1.0 820 * @version 1.0 821 */ 822 int32_t StopPublishLNN(const char *pkgName, int32_t publishId); 823 824 /** 825 * @brief Subscribes to a specified service. 826 * 827 * Information about the device that publishes the service will be reported to the device that subscribes to 828 * the service. 829 * The service is identified by <b>subscribeId</b> and <b>pkgName</b>. 830 * 831 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 832 * @param info Indicates the pointer to the service subscription information. For details, see {@link SubscribeInfo}. 833 * @param cb Indicates the service subscription callback {@link IRefreshCallback}. 834 * 835 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 836 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 837 * @return Returns <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked. 838 * @return Returns <b>SOFTBUS_OK</b> if the service subscription is successful. 839 * 840 * @since 1.0 841 * @version 1.0 842 */ 843 int32_t RefreshLNN(const char *pkgName, const SubscribeInfo *info, const IRefreshCallback *cb); 844 845 /** 846 * @brief Unsubscribes from a specified service. 847 * 848 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 849 * @param refreshId Indicates the service ID. 850 * 851 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>pkgName</b> is invalid. 852 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 853 * @return Returns <b>SOFTBUS_OK</b> if the service unsubscription is successful. 854 * 855 * @since 1.0 856 * @version 1.0 857 */ 858 int32_t StopRefreshLNN(const char *pkgName, int32_t refreshId); 859 860 /** 861 * @brief Active meta node. The meta node online status will be notified by {@link INodeStateCb} 862 * 863 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 864 * For the same caller, the value of this parameter must be the same for all functions. 865 * @param info Meta node configuration information, see {@link MetaNodeConfigInfo}. 866 * @param metaNodeId Save meta node ID when it is activated successfully, its buffer length must be not 867 * less then NETWORK_ID_BUF_LEN. 868 * 869 * @return Returns <b>0</b> if the meta node is activated; returns any other value if the request fails. 870 * 871 * @since 1.0 872 * @version 1.0 873 */ 874 int32_t ActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId); 875 876 /** 877 * @brief Deactive meta node. The meta node will be removed. 878 * 879 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 880 * For the same caller, the value of this parameter must be the same for all functions. 881 * @param metaNodeId The meta node ID which deactivated, it's obtained by {@link ActiveMetaNode}. 882 * 883 * @return Returns <b>0</b> if the meta node is deactivated; returns any other value if the request fails. 884 * 885 * @since 1.0 886 * @version 1.0 887 */ 888 int32_t DeactiveMetaNode(const char *pkgName, const char *metaNodeId); 889 890 /** 891 * @brief Get all meta node by {@link ActiveMetaNode}. 892 * 893 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 894 * For the same caller, the value of this parameter must be the same for all functions. 895 * @param infos The buffer for save meta node info. 896 * @param infoNum The infos buffer num which maximum is {@link MAX_META_NODE_NUM}. 897 * 898 * @return Returns <b>0</b> if the call is success; returns any other value if it fails. 899 * 900 * @since 1.0 901 * @version 1.0 902 */ 903 int32_t GetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum); 904 905 /** 906 * @brief Modify heartbeat parameters and trigger a temporary heartbeat. 907 * 908 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 909 * For the same caller, the value of this parameter must be the same for all functions. 910 * @param callerId The id of the caller, whitch cannot be <b>NULL</b>, and maxium length is {@link CALLER_ID_MAX_LEN}. 911 * @param targetNetworkId The networkId of the target device to refresh online state, and could be <b>NULL</b>. 912 * @param mode The duration or cycle parameter of heartbeat. For details, see {@link GearMode}. 913 * 914 * @return Returns <b>0</b> if the call is success; returns any other value if it fails. 915 * 916 * @since 1.0 917 * @version 1.0 918 */ 919 int32_t ShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId, const GearMode *mode); 920 921 #ifdef __cplusplus 922 } 923 #endif 924 925 #endif 926