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 /** 17 * @addtogroup SoftBus 18 * @{ 19 * 20 * @brief Provides high-speed, secure communications between devices. 21 * 22 * This module implements unified distributed communication management of 23 * nearby devices, and provides link-independent device discovery and transmission interfaces 24 * to support service publishing and data transmission. 25 * 26 * @since 1.0 27 * @version 1.0 28 */ 29 30 /** 31 * @file session.h 32 * 33 * @brief Declares unified data transmission interfaces. 34 * 35 * This file provides data transmission capabilities, including creating and removing a session server, 36 * opening and closing sessions, receiving data, and querying basic session information. \n 37 * You can use the interfaces to transmit data across the nearby devices that are discovered and networked. 38 * \n 39 * 40 * @since 1.0 41 * @version 1.0 42 */ 43 #ifndef SESSION_H 44 #define SESSION_H 45 46 #include <stdint.h> 47 48 #include "trans_type.h" 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 /** 55 * @brief Enumerates the session types. 56 * 57 * @since 1.0 58 * @version 1.0 59 */ 60 typedef enum { 61 TYPE_MESSAGE = 1, /**< Message */ 62 TYPE_BYTES, /**< Bytes */ 63 TYPE_FILE, /**< File */ 64 TYPE_STREAM, /**< Stream */ 65 TYPE_D2D_MESSAGE = 10, /**< D2D Message */ 66 TYPE_D2D_VOICE, /**< D2D Voice */ 67 TYPE_BUTT, 68 } SessionType; 69 70 /** 71 * @brief Enumerates the stream types. 72 * 73 * @since 1.0 74 * @version 1.0 75 */ 76 typedef enum { 77 INVALID = -1, /**< Invalid stream type. */ 78 RAW_STREAM, /**< Send any segment of a frame each time. */ 79 COMMON_VIDEO_STREAM, /**< Send a whole video frame each time. */ 80 COMMON_AUDIO_STREAM, /**< Send a whole audio frame each time. */ 81 VIDEO_SLICE_STREAM, /**< Slice frame mode. */ 82 } StreamType; 83 84 /** 85 * @brief Enumerates the link types. 86 * 87 * @since 1.0 88 * @version 1.0 89 */ 90 typedef enum { 91 LINK_TYPE_WIFI_WLAN_5G = 1, /**< 5 GHz Wi-Fi link */ 92 LINK_TYPE_WIFI_WLAN_2G = 2, /**< 2.4 GHz Wi-Fi link */ 93 LINK_TYPE_WIFI_P2P = 3, /**< P2P link */ 94 LINK_TYPE_BR = 4, /**< BR link */ 95 LINK_TYPE_BLE = 5, 96 LINK_TYPE_WIFI_P2P_REUSE = 6, 97 LINK_TYPE_BLE_DIRECT = 7, 98 LINK_TYPE_COC = 8, 99 LINK_TYPE_COC_DIRECT = 9, 100 LINK_TYPE_HML = 10, 101 LINK_TYPE_SLE = 11, 102 LINK_TYPE_SLE_DIRECT = 12, 103 LINK_TYPE_MAX = 12, 104 } LinkType; 105 106 /** 107 * @brief Defines the session attributes. 108 * 109 * @since 1.0 110 * @version 1.0 111 */ 112 typedef struct { 113 int dataType; /**< Session type {@link SessionType} */ 114 int linkTypeNum; /**< Number of link types */ 115 LinkType linkType[LINK_TYPE_MAX]; /**< Link type {@link LinkType} */ 116 /** 117 * @brief Defines the attributes. 118 * 119 * @since 1.0 120 * @version 1.0 121 */ 122 union { 123 /** 124 * @brief Defines the stream attributes. 125 * 126 * @since 1.0 127 * @version 1.0 128 */ 129 struct StreamAttr { 130 int streamType; /**< Stream type {@link StreamType} */ 131 } streamAttr; 132 } attr; 133 uint8_t *fastTransData; 134 uint16_t fastTransDataSize; 135 } SessionAttribute; 136 137 /** 138 * @brief Enumerates the quality of service (QoS) types. 139 * 140 * @since 1.0 141 * @version 1.0 142 */ 143 typedef enum { 144 QOS_IMPROVE = 0, /**< Improve QoS */ 145 QOS_RECOVER = 1, /**< Recover QoS */ 146 } QosQuality; 147 148 /** 149 * @brief Enumerates the QoS feedback types. 150 * 151 * @since 1.0 152 * @version 1.0 153 */ 154 typedef enum { 155 TRANS_STREAM_QUALITY_EVENT = 1, /**< Feedback on stream transmission quality */ 156 TRANS_CHANNEL_QUALITY_EVENT, /**< Feedback on transmission channel quality */ 157 TRANS_CAN_DELAY_EVENT, /**< Feedback on deferrable transmission */ 158 TRANS_CANT_DELAY_EVENT, /**< Feedback on non-deferrable transmission */ 159 QOS_EVENT_MAX /**< Invalid feedback */ 160 } QosEvent; 161 162 /** 163 * @brief Enumerates the stream transmission QoS event types. 164 * 165 * @since 1.0 166 * @version 1.0 167 */ 168 typedef enum { 169 WIFI_CHANNEL_QUALITY = 1, /**< Wi-Fi channel quality */ 170 FRAME_REALTIME_STATUS = 2, /**< Real-time status of frame transmission */ 171 BANDWIDTH_ESTIMATE_VALUE = 3, /**< Bandwidth estimation */ 172 JITTER_DETECTION_VALUE = 4, /**< Jitter detection */ 173 STREAM_TRAFFIC_STASTICS = 5, /**< Stream traffic statistics */ 174 } TransEnumEventType; 175 176 /** 177 * @brief Defines the Wi-Fi channel quality. 178 * 179 * @since 1.0 180 * @version 1.0 181 */ 182 typedef struct { 183 int32_t channel; /**< Wi-Fi channel */ 184 int32_t score; /**< Wi-Fi channel score */ 185 } WifiChannelQuality; 186 187 /** 188 * @brief Defines the frame information. 189 * 190 * @since 1.0 191 * @version 1.0 192 */ 193 typedef struct { 194 int32_t streamId; /**< Stream ID */ 195 int32_t seqNum; /**< Sequence number of the frame */ 196 int32_t level; /**< Frame layer number */ 197 int32_t transStatus; /**< Frame status */ 198 int32_t interval; /**< Duration that unsent frames in the queue are cached */ 199 } FrameStatus; 200 201 /** 202 * @brief Defines the bandwidth detection information. 203 * 204 * @since 1.0 205 * @version 1.0 206 */ 207 typedef struct { 208 uint32_t trend; /**< Bandwidth change trend */ 209 uint32_t rate; /**< Bandwidth rate */ 210 } BandwidthDetection; 211 212 /** 213 * @brief Defines the jitter estimation information. 214 * 215 * @since 1.0 216 * @version 1.0 217 */ 218 typedef struct { 219 int32_t jitterLevel; /**< Estimated network status */ 220 uint32_t bufferTime; /**< Required buffer time */ 221 } JitterEstimation; 222 223 /** 224 * @brief Defines the stream transmission statistics information. 225 * 226 * @since 1.0 227 * @version 1.0 228 */ 229 typedef struct { 230 uint64_t statisticsGotTime; /**< Time when the statistics information is obtained */ 231 uint64_t periodRecvBits; /**< Number of bits received in a transmission period */ 232 uint32_t pktNum; /**< Number of packets */ 233 uint32_t periodRecvPkts; /**< Number of packets received in a transmission period */ 234 uint32_t periodRecvPktLoss; /**< Number of RX packets lost in a transmission period */ 235 uint32_t periodRecvRate; /**< Receive rate in a transmission period, in kbit/s */ 236 uint64_t periodRecvRateBps; /**< RX rate in a transmission period, in bit/s */ 237 uint32_t periodRtt; /**< Round-trip time (RTT), in ms */ 238 239 /**< RX packet loss rate displayed for high precision. 240 For example, if the packet loss rate is 1.10%, the value is <b>110</b>. */ 241 uint32_t periodRecvPktLossHighPrecision; 242 uint32_t periodSendLostPkts; /**< Number of TX packets lost in a transmission period */ 243 uint32_t periodSendPkts; /**< Number of packets sent in a transmission period */ 244 245 /**< TX packet loss rate displayed for high precision. 246 For example, if the packet loss rate is 1.10%, the value is <b>110</b>. */ 247 uint32_t periodSendPktLossHighPrecision; 248 uint64_t periodSendBits; /**< Number of bits sent in a transmission period */ 249 uint64_t periodSendRateBps; /**< TX rate in a transmission period, in bps */ 250 } StreamStatistics; 251 252 /** 253 * @brief Defines the video stream transmission QoS. 254 * 255 * @since 1.0 256 * @version 1.0 257 */ 258 typedef struct { 259 TransEnumEventType type; /**< Stream transmission QoS event type {@link TransEnumEventType} */ 260 union { 261 WifiChannelQuality wifiChannelInfo; /**< Wi-Fi channel quality {@link WifiChannelQuality} */ 262 FrameStatus frameStatusInfo; /**< Frame information {@link FrameStatus} */ 263 BandwidthDetection bandwidthInfo; /**< Bandwidth detection {@link BandwidthDetection} */ 264 JitterEstimation jitterInfo; /**< Network jitter estimation {@link JitterEstimation} */ 265 StreamStatistics appStatistics; /**< Stream transmission statistics {@link StreamStatistics} */ 266 } info; 267 } QosTv; 268 269 typedef enum { 270 SESSION_OPTION_MAX_SENDBYTES_SIZE = 0, /**< Value type of this option is uint32_t, this option only can be get */ 271 SESSION_OPTION_MAX_SENDMESSAGE_SIZE, /**< Value type of this option is uint32_t, this option only can be get */ 272 SESSION_OPTION_LINK_TYPE, /**< Value type of this option is int32_t, this option only can be get */ 273 274 SESSION_OPTION_BUTT, 275 } SessionOption; 276 277 /** 278 * @brief Defines session callbacks. 279 * 280 * When a session is opened or closed, or there is data to process, the related callback is invoked. 281 * 282 * @since 1.0 283 * @version 1.0 284 */ 285 typedef struct { 286 /** 287 * @brief Called when a session is opened. 288 * 289 * This callback is invoked to verify the session or initialize resources related to the session. 290 * 291 * @param sessionId Indicates the unique session ID. 292 * @param result Indicates the result to return. 293 * @return Returns <b>0</b> if the session is set up; returns a non-zero value 294 * otherwise. You do not need to call {@link CloseSession} to close the session. 295 * @since 1.0 296 * @version 1.0 297 */ 298 int (*OnSessionOpened)(int sessionId, int result); 299 300 /** 301 * @brief Called when a session is closed. 302 * 303 * This callback is invoked to release resources related to the session. 304 * You do not need to call {@link CloseSession}. 305 * 306 * @param sessionId Indicates the unique session ID. 307 * @since 1.0 308 * @version 1.0 309 */ 310 void (*OnSessionClosed)(int sessionId); 311 312 /** 313 * @brief Called when data is received. 314 * 315 * This callback is invoked to notify that data is received. 316 * 317 * @param sessionId Indicates the unique session ID. 318 * @param data Indicates the pointer to the data received. 319 * User-defined data type, users should apply for memory by themselves. 320 * @param dataLen Indicates the length of the data received. 321 * @since 1.0 322 * @version 1.0 323 */ 324 void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen); 325 326 /** 327 * @brief Called when a message is received. 328 * 329 * This callback is invoked to notify that a message is received. 330 * 331 * @param sessionId Indicates the unique session ID. 332 * @param data Indicates the pointer to the message received. 333 * @param dataLen Indicates the length of the message received. 334 * @since 1.0 335 * @version 1.0 336 */ 337 void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen); 338 339 /** 340 * @brief Called when stream data is received. 341 * 342 * This callback is invoked to notify that stream data is received. 343 * 344 * @param sessionId Indicates the unique session ID. 345 * @param data Indicates the pointer to the stream data received. 346 * @param ext Indicates the pointer to the extended service data received. 347 * @param param Indicates the pointer to the stream data frame information. 348 * @since 1.0 349 * @version 1.0 350 */ 351 void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext, 352 const StreamFrameInfo *param); 353 354 /** 355 * @brief Called when QoS information is retrieved. 356 * 357 * This callback is invoked to notify that QoS information is retrieved. 358 * 359 * @param sessionId Indicates the unique session ID. 360 * @param eventId Indicates the type of QoS information, such as the channel quality and stream quality. 361 * @param tvCount Indicates the number of TVs returned in the fourth parameter <b>tvList</b>. 362 * @param tvList Indicates the pointer to the TV list. 363 * @since 1.0 364 * @version 1.0 365 */ 366 void (*OnQosEvent)(int sessionId, int eventId, int tvCount, const QosTv *tvList); 367 } ISessionListener; 368 369 /** 370 * @brief Defines the callbacks for file receiving. 371 * 372 * The callbacks are invoked to notify the file receiving status. 373 * 374 * @since 1.0 375 * @version 1.0 376 */ 377 typedef struct { 378 /** 379 * @brief Called when a file starts to be received. 380 * 381 * This callback is invoked to notify the start of file receiving. 382 * 383 * @param sessionId Indicates the unique session ID. 384 * @param files Indicates the pointer to the files to receive. 385 * @param fileCnt Indicates the number of files to receive. 386 * @return Returns <b>0</b> if the file receiving starts; returns a non-zero value otherwise. 387 * @since 1.0 388 * @version 1.0 389 */ 390 int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt); 391 392 /** 393 * @brief Called when a file is being received. 394 * 395 * This callback is invoked to notify that a file is being received. 396 * 397 * @param sessionId Indicates the unique session ID. 398 * @param files Indicates the pointer to the first file received. 399 * @param bytesUpload Indicates the size of the files received. 400 * @param bytesTotal Indicates the total size of the files to receive, in bytes. 401 * @return Returns <b>0</b> if a file is being received; returns a non-zero value otherwise. 402 * @since 1.0 403 * @version 1.0 404 */ 405 int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal); 406 407 /** 408 * @brief Called when the file receiving ends. 409 * 410 * This callback is invoked to notify the end of file receiving. 411 * 412 * @param sessionId Indicates the unique session ID. 413 * @param files Indicates the pointer to the files received. 414 * @param fileCnt Indicates the number of files received. 415 * @since 1.0 416 * @version 1.0 417 */ 418 void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt); 419 420 /** 421 * @brief Called when an error occurs during the file receiving process. 422 * 423 * This callback is invoked to notify a file receiving error. 424 * 425 * @param sessionId Indicates the unique session ID. 426 * @since 1.0 427 * @version 1.0 428 */ 429 void (*OnFileTransError)(int sessionId); 430 } IFileReceiveListener; 431 432 /** 433 * @brief Defines callbacks for file sending. 434 * 435 * The callbacks are invoked to notify the file sending status. 436 * 437 * @since 1.0 438 * @version 1.0 439 */ 440 typedef struct { 441 /** 442 * @brief Called when a file is being sent. 443 * 444 * This callback is invoked to notify that a file is being sent. 445 * 446 * @param sessionId Indicates the unique session ID. 447 * @param bytesUpload Indicates the size of the file sent, in bytes. 448 * @param bytesTotal Indicates the total size of the file to send, in bytes. 449 * @return Returns <b>0</b> if the file is being sent; returns a non-zero value otherwise. 450 * @since 1.0 451 * @version 1.0 452 */ 453 int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal); 454 455 /** 456 * @brief Called when the file sending ends. 457 * 458 * This callback is invoked to notify the end of file sending. 459 * 460 * @param sessionId Indicates the unique session ID. 461 * @param firstFile Indicates the pointer to the first file to send. 462 * @return Returns<b>0</b> if the file sending is complete; returns a non-zero value otherwise. 463 * @since 1.0 464 * @version 1.0 465 */ 466 int (*OnSendFileFinished)(int sessionId, const char *firstFile); 467 468 /** 469 * @brief Called when an error occurs during the file sending process. 470 * 471 * This callback is invoked to notify a file sending error. 472 * 473 * @param sessionId Indicates the unique session ID. 474 * @since 1.0 475 * @version 1.0 476 */ 477 void (*OnFileTransError)(int sessionId); 478 } IFileSendListener; 479 480 /** 481 * @brief Creates a session server. 482 * 483 * A maximum of 32 session servers can be created. 484 * 485 * @param pkgName Indicates the pointer to the service bundle name. 486 * It is the unique identifier of the upper-layer service. The value cannot be empty or exceed 64 characters. 487 * @param sessionName Indicates the pointer to the session name, which is the unique ID of the session server. 488 * The value cannot be empty or exceed 255 characters. 489 * @param listener Indicates the pointer to the session callback, which cannot be empty. 490 * 491 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 492 * @see RemoveSessionServer 493 * @since 1.0 494 * @version 1.0 495 */ 496 int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener); 497 498 /** 499 * @brief Removes a session server. 500 * 501 * @param pkgName Indicates the pointer to the service bundle name. 502 * It is the unique identifier of the upper-layer service. The value cannot be empty or exceed 64 characters. 503 * @param sessionName Indicates the pointer to the session name. The value cannot be empty or exceed 255 characters. 504 * 505 * @return Returns <b>0</b> if the operation is successful, returns <b>-1</b> otherwise. 506 * @see CreateSessionServer 507 * @since 1.0 508 * @version 1.0 509 */ 510 int RemoveSessionServer(const char *pkgName, const char *sessionName); 511 512 /** 513 * @brief Opens a session, which is an asynchronous process. 514 * 515 * The session is opened to trigger the first packet interaction process. 516 * {@link OnSessionOpened} is invoked to return whether the session is successfully opened. 517 * Data can be transmitted only after the session is successfully opened. 518 * 519 * @param mySessionName Indicates the pointer to the local session name. 520 * @param peerSessionName Indicates the pointer to the remote session name. 521 * @param peerNetworkId Indicates the pointer to the remote device ID. 522 * @param groupId Indicates the pointer to the group ID. This parameter can be left empty in automatic networking. 523 * In manual networking, you need to apply for a valid group ID from HiChain. 524 * @param attr Indicates the pointer to the session attributes {@link SessionAttribute}. 525 * 526 * @return Returns <b>SOFTBUS_TRANS_INVALID_PARAM</b> if invalid parameters are detected. 527 * @return Returns <b>INVALID_SESSION_ID</b> if the operation fails. 528 * @return Returns the session ID (an integer greater than <b>0</b>) if the session is opened; 529 * returns an error code otherwise. 530 * @since 1.0 531 * @version 1.0 532 */ 533 int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerNetworkId, 534 const char *groupId, const SessionAttribute* attr); 535 536 /** 537 * @brief Closes a session. 538 * 539 * @param sessionId Indicates the unique session ID. 540 * @return Returns no value. 541 * @since 1.0 542 * @version 1.0 543 */ 544 void CloseSession(int sessionId); 545 546 /** 547 * @example sendbytes_message_demo.c 548 */ 549 550 /** 551 * @brief Sends data. 552 * 553 * @param sessionId Indicates the unique session ID. 554 * @param data Indicates the pointer to the data to send, which cannot be <b>NULL</b>. 555 * @param len Indicates the length of the data to send. 556 * 557 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected. 558 * @return Returns <b>SOFTBUS_TRANS_SEND_LEN_BEYOND_LIMIT</b> if the data exceeds the maximum limit. 559 * @return Returns <b>SOFTBUS_TRANS_INVALID_SESSION_ID</b> if <b>sessionId</b> is invalid. 560 * @return Returns <b>SOFTBUS_TRANS_SESSION_NO_ENABLE</b> if the session is not open. 561 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 562 * @since 1.0 563 * @version 1.0 564 */ 565 int SendBytes(int sessionId, const void *data, unsigned int len); 566 567 /** 568 * @brief Sends a message. 569 * 570 * @param sessionId Indicates the unique session ID. 571 * @param data Indicates the pointer to the message to send, which cannot be <b>NULL</b>. 572 * @param len Indicates the length of the message to send. 573 * 574 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>data</b> is <b>NULL</b> or <b>len</b> is zero. 575 * @return Returns <b>SOFTBUS_TRANS_SEND_LEN_BEYOND_LIMIT</b> if the message length exceeds the limit. 576 * @return Returns <b>SOFTBUS_INVALID_SESSION_ID</b> if <b>sessionId</b> is invalid. 577 * @return Returns <b>SOFTBUS_TRANS_SESSION_NO_ENABLE</b> if the session is not open. 578 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 579 * @since 1.0 580 * @version 1.0 581 */ 582 int SendMessage(int sessionId, const void *data, unsigned int len); 583 584 /** 585 * @example sendstream_demo.c 586 */ 587 588 /** 589 * @brief Sends stream data. 590 * 591 * @param sessionId Indicates the unique session ID. 592 * @param data Indicates the pointer to the stream data to send, which cannot be <b>NULL</b>. 593 * @param ext Indicates the pointer to the extended stream data to send, which cannot be <b>NULL</b>. 594 * @param param Indicates the pointer to the stream frame information, which cannot be <b>NULL</b>. 595 * 596 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if any of the input parameters is <b>NULL</b>. 597 * @return Returns <b>SOFTBUS_INVALID_SESSION_ID</b> if <b>sessionId</b> is invalid. 598 * @return Returns <b>SOFTBUS_TRANS_SESSION_NO_ENABLE</b> if the session is not open. 599 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 600 * @since 1.0 601 * @version 1.0 602 */ 603 int SendStream(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *param); 604 605 /** 606 * @example getsessioninfo_demo.c 607 */ 608 609 /** 610 * @brief Obtains the session name registered by the local device. 611 * 612 * @param sessionId Indicates the unique session ID. 613 * @param sessionName Indicates the pointer to the buffer for storing the session name. 614 * @param len Indicates the length of the buffer. 615 * 616 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected. 617 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 618 * @since 1.0 619 * @version 1.0 620 */ 621 int GetMySessionName(int sessionId, char *sessionName, unsigned int len); 622 623 /** 624 * @brief Obtains the session name registered by the peer device. 625 * 626 * @param sessionId Indicates the unique session ID. 627 * @param sessionName Indicates the pointer to the buffer for storing the session name. 628 * @param len Indicates the length of the buffer. 629 * 630 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected. 631 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 632 * @since 1.0 633 * @version 1.0 634 */ 635 int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len); 636 637 /** 638 * @brief Obtains the peer device ID. 639 * 640 * @param sessionId Indicates the unique session ID. 641 * @param networkId Indicates the pointer to the buffer for storing the device ID. 642 * @param len Indicates the length of the buffer. 643 * 644 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected. 645 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 646 * @since 1.0 647 * @version 1.0 648 */ 649 int GetPeerDeviceId(int sessionId, char *networkId, unsigned int len); 650 651 /** 652 * @brief Obtains the session role. 653 * 654 * @param sessionId Indicates the unique session ID. 655 * @return Returns <b>-1</b> if the operation fails. 656 * @return Returns <b>0</b> if the session role is a server. 657 * @return Returns <b>1</b> if the session role is a client. 658 * @since 1.0 659 * @version 1.0 660 */ 661 int GetSessionSide(int sessionId); 662 663 /** 664 * @brief Sets a listener for file receiving. 665 * 666 * @param pkgName Indicates the pointer to the registered bundle name, which can be used to check 667 * whether the session server is in this package. The value cannot be empty or exceed 64 characters. 668 * @param sessionName Indicates the pointer to the buffer for storing the session name. 669 * @param recvListener Indicates the pointer to the file receive listener, which cannot be <b>NULL</b>. 670 * @param rootDir Indicates the pointer to the root directory of the file. The length cannot exceed 255 bits. 671 * 672 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected. 673 * @return Returns <b>SOFTBUS_TRANS_SESSION_ADDPKG_FAILED</b> if the bundle specified by <b>pkgName</b> 674 * fails to be added. 675 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 676 * @since 1.0 677 * @version 1.0 678 */ 679 int SetFileReceiveListener(const char *pkgName, const char *sessionName, 680 const IFileReceiveListener *recvListener, const char *rootDir); 681 682 /** 683 * @brief Sets a listener for file sending. 684 * 685 * @param pkgName Indicates the pointer to the service bundle name. 686 * It is the unique identifier of the upper-layer service. The value cannot be empty or exceed 64 characters. 687 * @param sessionName Indicates the pointer to the buffer for storing the session name. 688 * @param sendListener Indicates the pointer to the file send listener, which cannot be <b>NULL</b>. 689 * 690 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if invalid parameters are detected. 691 * @return Returns <b>SOFTBUS_TRANS_SESSION_ADDPKG_FAILED</b> if the bundle specified by <b>pkgName</b> 692 * fails to be added. 693 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 694 * @since 1.0 695 * @version 1.0 696 */ 697 int SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener); 698 699 /** 700 * @example sendfile_demo.c 701 */ 702 703 /** 704 * @brief Sends files. 705 * 706 * @param sessionId Indicates the unique session ID. 707 * @param sFileList Indicates the pointer to the source files to send, which cannot be <b>NULL</b>. 708 * @param dFileList Indicates the pointer to the destination files, which cannot be <b>NULL</b>. 709 * @param fileCnt Indicates the number of files to send, which cannot be <b>0</b>. 710 * 711 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>sFileList</b> is <b>NULL</b> or <b>fileCnt</b> is <b>0</b>. 712 * @return Returns <b>SOFTBUS_INVALID_SESSION_ID</b> if <b>sessionId</b> is invalid. 713 * @return Returns <b>SOFTBUS_TRANS_SESSION_NO_ENABLE</b> if the session is not open. 714 * @return Returns <b>SOFTBUS_OK</b> if the operation is successful; returns an error code otherwise. 715 * @since 1.0 716 * @version 1.0 717 */ 718 int SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt); 719 720 /** 721 * @brief Get Session based on a session ID. 722 * 723 * @param sessionId Indicates the session ID. 724 * @param option Indicates the session option type to get. 725 * @param optionValue Indicates the session option value to get, which cannot be <b>NULL</b>. 726 * @param valueSize Indicates the size of data which optionValue point to, which cannot be <b>0</b>. 727 * The common error codes are as follows: 728 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if the option is invalid, optionValue is NULL or valueSize is Zero. 729 * @return Returns <b>SOFTBUS_INVALID_SESSION_ID</b> if the sessionId is invalid. 730 * @return Returns <b>SOFTBUS_TRANS_SESSION_NO_ENABLE</b> if the session current be not enabled. 731 * @return Returns <b>SOFTBUS_OK</b>if the function is called successfully, return other internal errorcodes otherwise. 732 * @since 1.0 733 * @version 1.0 734 */ 735 int GetSessionOption(int sessionId, SessionOption option, void* optionValue, uint32_t valueSize); 736 737 #ifdef __cplusplus 738 } 739 #endif 740 #endif // SESSION_H 741