• 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_MOCK_H
44 #define SESSION_MOCK_H
45 
46 #include <cstdint>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 /**
52  * @brief business type of session
53  *
54  * @since 1.0
55  * @version 1.0
56  */
57 typedef enum {
58     TYPE_MESSAGE = 1,
59     TYPE_BYTES,
60     TYPE_FILE,
61     TYPE_STREAM,
62     TYPE_BUTT,
63 } SessionType;
64 
65 typedef enum {
66     INVALID = -1,
67     /*
68      * Send any segment of a frame each time.
69      */
70     RAW_STREAM,
71     /*
72      * Send a whole video frame each time.
73      */
74     COMMON_VIDEO_STREAM,
75     /*
76      * Send a whole audio frame each time.
77      */
78     COMMON_AUDIO_STREAM,
79     /*
80      * Slice frame mode.
81      */
82     VIDEO_SLICE_STREAM,
83 } StreamType;
84 
85 typedef enum {
86     LINK_TYPE_WIFI_WLAN_5G = 1,
87     LINK_TYPE_WIFI_WLAN_2G = 2,
88     LINK_TYPE_WIFI_P2P = 3,
89     LINK_TYPE_BR = 4,
90     LINK_TYPE_MAX = 4,
91 } LinkType;
92 
93 typedef struct {
94     /* @brief dataType{@link SessionType} */
95     int dataType;
96     int linkTypeNum;
97     LinkType linkType[LINK_TYPE_MAX];
98     union {
99         struct StreamAttr {
100             int streamType;
101         } streamAttr;
102     } attr;
103 } SessionAttribute;
104 
105 typedef struct {
106     char *buf;
107     int bufLen;
108 } StreamData;
109 
110 typedef struct {
111     int type;
112     int64_t value;
113 } TV;
114 
115 typedef struct {
116     int frameType;
117     int64_t timeStamp;
118     int seqNum;
119     int seqSubNum;
120     int level;
121     int bitMap;
122     int tvCount;
123     TV *tvList;
124 } FrameInfo;
125 
126 enum FrameType {
127     NONE,
128     VIDEO_I,
129     VIDEO_P,
130     VIDEO_MAX = 50,
131     RADIO = VIDEO_MAX + 1,
132     RADIO_MAX = 100,
133 };
134 
135 // APP should update StreamFrameInfo each time.
136 struct StreamFrameInfo {
137     uint32_t streamId = 0;
138     uint32_t seqNum = 0;
139     uint32_t level = 0;
140     FrameType frameType = NONE;
141     uint32_t timestamp = 0;
142     uint32_t bitrate = 0;
143 };
144 
145 constexpr uint32_t DEVICE_ID_SIZE_MAX = 65;
146 constexpr uint32_t CHAR_ARRAY_SIZE = 100;
147 
148 typedef struct {
149     int (*OnSessionOpened)(int sessionId, int result);
150     void (*OnSessionClosed)(int sessionId);
151     void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen);
152     void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen);
153     void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext,
154         const StreamFrameInfo *param);
155 } ISessionListener;
156 
157 typedef struct {
158     int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt);
159     int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal);
160     void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt);
161     void (*OnFileTransError)(int sessionId);
162 } IFileReceiveListener;
163 
164 typedef struct {
165     int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal);
166     int (*OnSendFileFinished)(int sessionId, const char *firstFile);
167     void (*OnFileTransError)(int sessionId);
168 } IFileSendListener;
169 
170 int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener);
171 
172 int RemoveSessionServer(const char *pkgName, const char *sessionName);
173 
174 int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, const char *groupId,
175     const SessionAttribute *attr);
176 void OpenSessionResult(void);
177 
178 void CloseSession(int sessionId);
179 
180 int SendBytes(int sessionId, const void *data, unsigned int len);
181 
182 int SendMessage(int sessionId, const void *data, unsigned int len);
183 
184 int SendStream(int sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param);
185 
186 int GetMySessionName(int sessionId, char *sessionName, unsigned int len);
187 
188 int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len);
189 
190 int GetPeerDeviceId(int sessionId, char *devId, unsigned int len);
191 
192 int GetSessionSide(int sessionId);
193 
194 int SetFileReceiveListener(const char *pkgName, const char *sessionName, const IFileReceiveListener *recvListener,
195     const char *rootDir);
196 
197 int SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener);
198 
199 int SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt);
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 #endif // SESSION_MOCK_H