• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Softbus
18  * @{
19  *
20  * @brief Provides high-speed, secure communication between devices.
21  *
22  * This module implements unified distributed communication capability management between
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  * After multiple nearby devices are discovered and networked, these interfaces can be used to
38  * transmit data across devices. \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 #include "trans_type.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 /**
53  * @brief business type of session
54  *
55  * @since 1.0
56  * @version 1.0
57  */
58 typedef enum {
59     TYPE_MESSAGE = 1,
60     TYPE_BYTES,
61     TYPE_FILE,
62     TYPE_STREAM,
63     TYPE_BUTT,
64 } SessionType;
65 
66 typedef enum {
67     INVALID = -1,
68     /*
69      * Send any segment of a frame each time.
70      */
71     RAW_STREAM,
72     /*
73      * Send a whole video frame each time.
74      */
75     COMMON_VIDEO_STREAM,
76     /*
77      * Send a whole audio frame each time.
78      */
79     COMMON_AUDIO_STREAM,
80     /*
81      * Slice frame mode.
82      */
83     VIDEO_SLICE_STREAM,
84 } StreamType;
85 
86 typedef enum {
87     LINK_TYPE_WIFI_WLAN_5G = 1,
88     LINK_TYPE_WIFI_WLAN_2G = 2,
89     LINK_TYPE_WIFI_P2P = 3,
90     LINK_TYPE_BR = 4,
91     LINK_TYPE_MAX = 4,
92 } LinkType;
93 
94 typedef struct {
95     /** @brief dataType{@link SessionType} */
96     int dataType;
97     int linkTypeNum;
98     LinkType linkType[LINK_TYPE_MAX];
99     union {
100         struct StreamAttr {
101             int streamType;
102         } streamAttr;
103     } attr;
104 } SessionAttribute;
105 
106 typedef struct {
107     int frameType;
108     int64_t timeStamp;
109     int seqNum;
110     int seqSubNum;
111     int level;
112     int bitMap;
113     int tvCount;
114     TV *tvList;
115 } FrameInfo;
116 
117 typedef struct {
118     int (*OnSessionOpened)(int sessionId, int result);
119     void (*OnSessionClosed)(int sessionId);
120     void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen);
121     void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen);
122     void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param);
123 } ISessionListener;
124 
125 typedef struct {
126     int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt);
127     int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal);
128     void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt);
129     void (*OnFileTransError)(int sessionId);
130 } IFileReceiveListener;
131 
132 typedef struct {
133     int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal);
134     int (*OnSendFileFinished)(int sessionId, const char *firstFile);
135     void (*OnFileTransError)(int sessionId);
136 } IFileSendListener;
137 
138 int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener);
139 
140 int RemoveSessionServer(const char *pkgName, const char *sessionName);
141 
142 int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, const char *groupId,
143                 const SessionAttribute *attr);
144 
145 void CloseSession(int sessionId);
146 
147 int SendBytes(int sessionId, const void *data, unsigned int len);
148 
149 int SendMessage(int sessionId, const void *data, unsigned int len);
150 
151 int GetMySessionName(int sessionId, char *sessionName, unsigned int len);
152 
153 int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len);
154 
155 int GetPeerDeviceId(int sessionId, char *devId, unsigned int len);
156 
157 int GetSessionSide(int sessionId);
158 
159 int SetFileReceiveListener(const char *pkgName, const char *sessionName, const IFileReceiveListener *recvListener,
160                            const char *rootDir);
161 
162 int SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener);
163 
164 int SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt);
165 #ifdef __cplusplus
166 }
167 #endif
168 #endif // SESSION_H
169