aboutsummaryrefslogtreecommitdiffstats
path: root/src/framework/ipc/mgr_com/mgr_com.h
blob: 02e46c12a87e808a5eda45c4f8d992d48b7832fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*****************************************************************************
*   Prototype    : ifndef _NSFW_MGRCOM_MODULE_H
*   Description  : mgr com module definition
*   Input        : None
*   Output       : None
*   Return Value : #
*   Calls        :
*   Called By    :
 *****************************************************************************/
#ifndef _NSFW_MGRCOM_MODULE_H
#define _NSFW_MGRCOM_MODULE_H

#include "pthread.h"
#include "nsfw_mem_api.h"
#include "common_mem_api.h"
#include "common_mem_memzone.h"
#include "common_func.h"

#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
/* *INDENT-ON* */
#endif /* __cplusplus */

#define NSFW_MGRCOM_PATH_LEN 128
#define NSFW_MGRCOM_MAX_SOCKET 1024
#define NSFW_MGRCOM_MAX_PROC_FUN 8

#define MAX_RECV_BUF_DEF         0x34000*2

#define MGR_COM_MSG_COUNT_DEF 1023      /*g_mgr_com_cfg */
#define MGR_COM_RECV_TIMEOUT_DEF 5
#define MGR_COM_MAX_DROP_MSG_DEF 1024

#define MGR_COM_MSG_COUNT       (g_mgr_com_cfg.msg_size)
#define MGR_COM_RECV_TIMEOUT    (g_mgr_com_cfg.max_recv_timeout)
#define MGR_COM_MAX_DROP_MSG    (g_mgr_com_cfg.max_recv_drop_msg)

#define NSFW_MAIN_FILE "/ip_module/nStackMainMgr"
#define NSFW_MASTER_FILE "/ip_module/nStackMasterMgr"
#define NSFW_ALARM_FILE "/HuskyAlarm.domain"

#define NSFW_MGRCOM_THREAD "nStackMgrCom"

typedef struct _nsfw_mgr_init_cfg
{
  u8 proc_type;                 /*fw_poc_type */
  u8 max_recv_timeout;
  u16 max_recv_drop_msg;
  u32 msg_size;
  common_mem_atomic32_t cur_idx;
  u64 u64reserve;
  mring_handle msg_pool;
  char domain_path[NSFW_MGRCOM_PATH_LEN];
} nsfw_mgr_init_cfg;

typedef struct _nsfw_mgrcom_stat
{
  u64 msg_send[MGR_MSG_MAX];
  u64 msg_recv[MGR_MSG_MAX];
  u64 recv_drop[MGR_MSG_MAX];
  u64 msg_alloc;
  u64 msg_free;
  u64 msg_send_failed;
  u64 reconnect_count;
} nsfw_mgrcom_stat;

typedef struct _nsfw_mgr_sock_info
{
  u8 proc_type;       /*_ns_poc_type*/
  u32 host_pid;
  common_mem_spinlock_t opr_lock;
} nsfw_mgr_sock_info;

typedef struct _nsfw_mgr_sock_map
{
  i32 proc_cache[NSFW_PROC_MAX];
  nsfw_mgr_sock_info *sock;
} nsfw_mgr_sock_map;

#define NSFW_SOCK_MAX_PROC_FUN 4

typedef struct _nsfw_mgrcom_proc_fun
{
  i32 fd;
  nsfw_mgr_sock_fun fun;
} nsfw_mgrcom_proc_fun;

typedef struct _nsfw_mgrcom_proc
{
  i32 epfd;
  u32 hbt_count;
  pthread_t ep_thread;
  nsfw_mgr_sock_fun *ep_fun;
} nsfw_mgrcom_proc;

i32 nsfw_set_sock_block (i32 sock, u8 flag);

u8 nsfw_rmv_sock_from_ep (i32 fd);
u8 nsfw_add_sock_to_ep (i32 fd);

int nsfw_mgr_new_msg (i32 epfd, i32 socket, u32 events);

u8 nsfw_mgr_ep_start ();
u8 nsfw_mgr_stop ();

#define LOCK_MGR_FD(_fd){\
    if ((i32)NSFW_MGR_FD_MAX > _fd)\
    {\
        common_mem_spinlock_lock(&g_mgr_socket_map.sock[_fd].opr_lock);\
    }\
}

#define UNLOCK_MGR_FD(_fd){\
    if ((i32)NSFW_MGR_FD_MAX > _fd)\
    {\
        common_mem_spinlock_unlock(&g_mgr_socket_map.sock[_fd].opr_lock);\
    }\
}

#define NSFW_MGR_FD_MAX   g_mgr_sockfdmax

extern void set_thread_attr (pthread_attr_t * pattr, int stacksize, int pri,
                             int policy);

extern void nsfw_com_attr_set (int policy, int pri);

#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif /* __cplusplus */

#endif /* _NSFW_MGRCOM_MODULE_H  */