• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #ifndef CLIENT_TRANS_SESSION_MANAGER_STRUCT_H
17 #define CLIENT_TRANS_SESSION_MANAGER_STRUCT_H
18 
19 #include "session.h"
20 #include "socket.h"
21 #include "softbus_app_info.h"
22 #include "softbus_def.h"
23 #include "softbus_trans_def.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define IS_SERVER 0
30 #define IS_CLIENT 1
31 #define ISHARE_AUTH_SESSION "IShareAuthSession"
32 #define DM_AUTH_SESSION "ohos.distributedhardware.devicemanager.resident"
33 #define ISHARE_AUTH_SESSION_MAX_IDLE_TIME 5000 // 5s
34 #define DM_AUTH_SESSION_MAX_IDLE_TIME 275000 // 275s
35 
36 typedef struct {
37     char peerSessionName[SESSION_NAME_SIZE_MAX];
38     char peerDeviceId[DEVICE_ID_SIZE_MAX];
39     char groupId[GROUP_ID_SIZE_MAX];
40     int flag; // TYPE_MESSAGE & TYPE_BYTES & TYPE_FILE
41     int streamType;
42 } SessionTag;
43 
44 typedef enum {
45     SESSION_ROLE_INIT,
46     SESSION_ROLE_CLIENT,
47     SESSION_ROLE_SERVER,
48     SESSION_ROLE_BUTT,
49 } SessionRole;
50 
51 typedef enum {
52     SESSION_STATE_INIT,
53     SESSION_STATE_OPENING,
54     SESSION_STATE_OPENED,
55     SESSION_STATE_CALLBACK_FINISHED,
56     SESSION_STATE_CANCELLING,
57     SESSION_STATE_BUTT,
58 } SessionState;
59 
60 typedef struct {
61     SessionState sessionState;
62     SoftBusCond callbackCond;
63     bool condIsWaiting;
64     int32_t bindErrCode;
65     uint32_t maxWaitTime; // 0 means no check time out, for Bind end
66     uint32_t waitTime;
67 } SocketLifecycleData;
68 
69 typedef enum {
70     ENABLE_STATUS_INIT,
71     ENABLE_STATUS_SUCCESS,
72     ENABLE_STATUS_FAILED,
73     ENABLE_STATUS_BUTT,
74 } SessionEnableStatus;
75 
76 typedef struct {
77     QoSEvent event;
78     QosTV qos[QOS_TYPE_BUTT];
79     uint32_t count;
80 } CachedQosEvent;
81 
82 typedef struct {
83     ListNode node;
84     int32_t sessionId;
85     int32_t channelId;
86     ChannelType channelType;
87     SessionTag info;
88     bool isServer;
89     bool isD2D;
90     bool isEncyptedRawStream;
91     bool isAsync;
92     bool isClosing;
93     bool isPagingRoot;
94     SessionRole role;
95     uint32_t maxIdleTime;
96     uint32_t timeout;
97     SessionEnableStatus enableStatus;
98     int32_t peerUid;
99     int32_t peerPid;
100     bool isEncrypt;
101     int32_t routeType;
102     int32_t businessType;
103     int32_t fileEncrypt;
104     int32_t algorithm;
105     int32_t crc;
106     LinkType linkType[LINK_TYPE_MAX];
107     uint32_t dataConfig;
108     SocketLifecycleData lifecycle;
109     uint32_t actionId;
110     int32_t osType;
111     CachedQosEvent cachedQosEvent;
112     bool isSupportTlv;
113     bool needAck;
114     int32_t tokenType;
115     int32_t peerUserId;
116     uint64_t peerTokenId;
117     uint32_t dataLen;
118     char extraData[EXTRA_DATA_MAX_LEN];
119     char peerBusinessAccountId[ACCOUNT_UID_LEN_MAX];
120     char peerExtraAccessInfo[EXTRA_ACCESS_INFO_LEN_MAX];
121     char peerPagingAccountId[ACCOUNT_UID_LEN_MAX];
122     bool isLowLatency;
123     TransFlowInfo flowInfo;
124 } SessionInfo;
125 
126 typedef struct {
127     bool isSocketListener;
128     ISessionListener session;
129     ISocketListener socketClient;
130     ISocketListener socketServer;
131 } SessionListenerAdapter;
132 
133 typedef struct {
134     ListNode node;
135     SoftBusSecType type;
136     char sessionName[SESSION_NAME_SIZE_MAX];
137     char pkgName[PKG_NAME_SIZE_MAX];
138     SessionListenerAdapter listener;
139     ListNode sessionList;
140     bool permissionState;
141     bool isSrvEncryptedRawStream;
142     int32_t sessionAddingCnt;
143 } ClientSessionServer;
144 
145 typedef enum {
146     KEY_SESSION_NAME = 1,
147     KEY_PEER_SESSION_NAME,
148     KEY_PEER_DEVICE_ID,
149     KEY_IS_SERVER,
150     KEY_PEER_PID,
151     KEY_PEER_UID,
152     KEY_PKG_NAME,
153     KEY_ACTION_ID,
154 } TransSessionKey;
155 
156 typedef struct {
157     ListNode node;
158     char pkgName[PKG_NAME_SIZE_MAX];
159     char sessionName[SESSION_NAME_SIZE_MAX];
160 } SessionServerInfo;
161 
162 typedef enum {
163     TIMER_ACTION_START,
164     TIMER_ACTION_STOP,
165     TIMER_ACTION_BUTT
166 } TimerAction;
167 
168 typedef struct {
169     ListNode node;
170     int32_t sessionId;
171     int32_t channelId;
172     ChannelType channelType;
173     bool isAsync;
174     void (*OnSessionClosed)(int sessionId);
175     void (*OnShutdown)(int32_t socket, ShutdownReason reason);
176     char sessionName[SESSION_NAME_SIZE_MAX];
177     char pkgName[PKG_NAME_SIZE_MAX];
178     SocketLifecycleData lifecycle;
179 } DestroySessionInfo;
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 #endif // CLIENT_TRANS_SESSION_MANAGER_STRUCT_H
185