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