• 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 #ifndef NET_TRANS_COMMON_H
17 #define NET_TRANS_COMMON_H
18 
19 #include <cerrno>
20 #include <cstdarg>
21 #include <cstdint>
22 #include <cstdio>
23 #include <cstdlib>
24 #include <cstring>
25 #include <pthread.h>
26 #include <securec.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29 
30 #include "common_list.h"
31 #include "discovery_service.h"
32 #include "session.h"
33 #include "shm_utils.h"
34 #include "softbus_bus_center.h"
35 #include "softbus_def.h"
36 #include "softbus_errcode.h"
37 #include "softbus_utils.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 enum class WaitSessionType : int {
44     SESSION_4DATA = 1,
45     SESSION_4CTL,
46 };
47 
48 enum class DataType : int {
49     DATA_TYPE_MSG = 1,
50     DATA_TYPE_BYTE,
51 };
52 
53 enum class WaitNodeStateType : int {
54     STATE_ONLINE = 1,
55     STATE_OFFLINE,
56 };
57 
58 enum class ConcurrentType {
59     CONC_CLOSE_SESSION = 1,
60 };
61 
62 enum class CtrlCodeType : int {
63     CTRL_CODE_SOFTBUS_TYPE = 1000,
64     CTRL_CODE_DATAMGR_TYPE = 2000,
65     CTRL_CODE_DM_TYPE = 3000,
66     CTRL_CODE_FILEMGR_TYPE = 4000,
67     CTRL_CODE_DP_TYPE = 5000,
68     CTRL_CODE_SEC_TYPE = 6000,
69     CTRL_CODE_MEDIA_TYPE = 7000,
70     CTRL_CODE_RESULT_TYPE = 9999,
71 };
72 
73 namespace NetTrans {
74 int Wait4Session(int timeout, WaitSessionType type);
75 
76 int CheckRemoteDeviceIsNull(int isSetNetId);
77 
78 void OnDefNodeOnline(NodeBasicInfo* info);
79 
80 void OnDefNodeOffline(NodeBasicInfo* info);
81 
82 void OnDefNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo* info);
83 
84 int DataSessionOpened(int sessionId, int result);
85 
86 void ResetWaitFlag4Data(void);
87 
88 void ResetWaitCount4Offline(void);
89 
90 void ResetWaitCount4Online(void);
91 int GetCurrentSessionId4Data(void);
92 
93 void DataSessionClosed(int sessionId);
94 
95 void DataBytesReceived(int sessionId, const void* data, unsigned int dataLen);
96 
97 void DataMessageReceived(int sessionId, const void* data, unsigned int dataLen);
98 
99 int RegisterDeviceStateDefCallback(void);
100 
101 int UnRegisterDeviceStateDefCallback(void);
102 
103 int CreateSsAndOpenSession4Data();
104 
105 int OpenSession4Data(void);
106 
107 int SendDataMsgToRemote(CtrlCodeType code, char* data);
108 
109 int CloseSessionAndRemoveSs4Data(void);
110 
111 int IncrementSubId(void);
112 
113 void OnDataMessageReceived(int sessionId, const char* data, unsigned int dataLen);
114 
115 void* SendMsgTask(void* param);
116 
117 void* DataOperateTask(void* param);
118 
119 ISessionListener* GetSessionListenser4Data(void);
120 
121 void SetCurrentSessionId4Data(int sessionId);
122 
123 ConnectionAddr* GetConnectAddr(void);
124 
125 void init(void);
126 
127 void destroy(void);
128 }; // namespace NetTrans
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 #endif
134