1 /*
2  * Copyright (c) 2021-2024 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 TRANS_LANE_MANAGER_H
17 #define TRANS_LANE_MANAGER_H
18 
19 #include <stdint.h>
20 #include "lnn_lane_interface.h"
21 #include "softbus_app_info.h"
22 #include "softbus_conn_interface.h"
23 #include "softbus_trans_def.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 typedef enum {
30     CORE_SESSION_STATE_INIT,
31     CORE_SESSION_STATE_WAIT_LANE,
32     CORE_SESSION_STATE_LAN_COMPLETE,
33     CORE_SESSION_STATE_CHANNEL_OPENED,
34     CORE_SESSION_STATE_CANCELLING,
35     CORE_SESSION_STATE_BUTT,
36 } CoreSessionState;
37 
38 typedef struct {
39     ListNode node;
40     bool isQosLane;
41     char pkgName[PKG_NAME_SIZE_MAX];
42     int32_t channelId;
43     int32_t channelType;
44     int32_t pid;
45     uint32_t laneHandle;
46     LaneConnInfo laneConnInfo;
47 } TransLaneInfo;
48 
49 int32_t TransLaneMgrInit(void);
50 
51 int32_t TransSocketLaneMgrInit(void);
52 
53 void TransLaneMgrDeinit(void);
54 
55 void TransSocketLaneMgrDeinit(void);
56 
57 int32_t TransLaneMgrAddLane(
58     const TransInfo *transInfo, const LaneConnInfo *connInfo, uint32_t laneHandle, bool isQosLane, AppInfoData *myData);
59 
60 int32_t TransLaneMgrDelLane(int32_t channelId, int32_t channelType, bool isAsync);
61 
62 void TransLaneMgrDeathCallback(const char *pkgName, int32_t pid);
63 
64 int32_t TransGetLaneHandleByChannelId(int32_t channelId, uint32_t *laneHandle);
65 
66 int32_t TransGetLaneIdByChannelId(int32_t channelId, uint64_t *laneId);
67 
68 int32_t TransGetChannelInfoByLaneHandle(uint32_t laneHandle, int32_t *channelId, int32_t *channelType);
69 
70 int32_t TransAddSocketChannelInfo(
71     const char *sessionName, int32_t sessionId, int32_t channelId, int32_t channelType, CoreSessionState state);
72 
73 int32_t TransUpdateSocketChannelInfoBySession(
74     const char *sessionName, int32_t sessionId, int32_t channelId, int32_t channelType);
75 
76 int32_t TransUpdateSocketChannelLaneInfoBySession(
77     const char *sessionName, int32_t sessionId, uint32_t laneHandle, bool isQosLane, bool isAsync);
78 
79 int32_t TransDeleteSocketChannelInfoBySession(const char *sessionName, int32_t sessionId);
80 
81 int32_t TransDeleteSocketChannelInfoByChannel(int32_t channelId, int32_t channelType);
82 
83 int32_t TransDeleteSocketChannelInfoByPid(int32_t pid);
84 
85 int32_t TransSetSocketChannelStateBySession(const char *sessionName, int32_t sessionId, CoreSessionState state);
86 
87 int32_t TransSetSocketChannelStateByChannel(int32_t channelId, int32_t channelType, CoreSessionState state);
88 
89 int32_t TransGetSocketChannelStateBySession(const char *sessionName, int32_t sessionId, CoreSessionState *state);
90 
91 int32_t TransGetSocketChannelStateByChannel(int32_t channelId, int32_t channelType, CoreSessionState *state);
92 
93 int32_t TransGetSocketChannelLaneInfoBySession(
94     const char *sessionName, int32_t sessionId, uint32_t *laneHandle, bool *isQosLane, bool *isAsync);
95 
96 int32_t TransGetPidFromSocketChannelInfoBySession(const char *sessionName, int32_t sessionId, int32_t *pid);
97 
98 int32_t TransGetConnectTypeByChannelId(int32_t channelId, ConnectType *connectType);
99 
100 int32_t TransGetTransLaneInfoByLaneHandle(uint32_t laneHandle, TransLaneInfo *laneInfo);
101 
102 #ifdef __cplusplus
103 }
104 #endif /* __cplusplus */
105 #endif
106