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