• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef CHANNEL_RES_H
17 #define CHANNEL_RES_H
18 
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <unistd.h>
25 #include <stdbool.h>
26 #include <fcntl.h>
27 #include "lock.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define CONTROL_CHANNEL_MAX_MSG_LEN (20 * 1024)
34 #define DOMAIN_PATH_LEN (128)
35 #define MAX_SEND_BUFFER_NUM (100)
36 #define MAX_RCV_BUFFER_NUM (100)
37 
38 typedef struct {
39     uint8_t *data;
40     uint32_t dataLen;
41 } DataBuf;
42 
43 typedef struct {
44     char data[CONTROL_CHANNEL_MAX_MSG_LEN];
45     uint32_t dataLen;
46 } ControlChannelBuf;
47 
48 typedef struct {
49     char srcDomainPath[DOMAIN_PATH_LEN];
50     char peerDomainPath[DOMAIN_PATH_LEN];
51     struct sockaddr_un srcAddr;
52     struct sockaddr_un peerAddr;
53     int32_t sockFd;
54     char sendBuffer[MAX_SEND_BUFFER_NUM][CONTROL_CHANNEL_MAX_MSG_LEN];
55     char rcvBuffer[MAX_RCV_BUFFER_NUM][CONTROL_CHANNEL_MAX_MSG_LEN];
56     uint8_t sendBufferNum;
57     Lock *sendBufferLock;
58     uint8_t rcvBufferNum;
59     Lock *rcvBufferLock;
60     pthread_t tid;
61     bool isExit;
62 } ControlChannelRes;
63 
64 /**
65 * @brief  Control Link Resource Initialization
66 */
67 int InitControlChannelRes(char *srcDomainPath, int srcDomainPathLen, char *peerDomainPath, int peerDomainPathLen);
68 
69 /**
70 * @brief  Release control link resources.
71 */
72 void FreeControlChannelRes(void);
73 
74 /**
75 * @brief  Obtaining Control Link Resources
76 */
77 ControlChannelRes* GetControlChannelRes(void);
78 
79 /**
80 * @brief  Writes data to the control link
81 */
82 int PushResultToChannelSendBuffer(ControlChannelRes *channelInfo, char *result);
83 
84 /**
85 * @brief  Read data from the control link
86 */
87 int PushResultToChannelRcvBuffer(ControlChannelRes *channelInfo, char *result);
88 
89 /**
90 * @brief  Writes data to the control link by ID
91 */
92 int PushResultToChannelIdBuffer(ControlChannelRes *channelInfo, char *result, int id);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif // CHANNEL_RES_H
99