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