node_base.h
8.48 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
* Copyright 2002-2014 the original author or authors.
*
* 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
*
* CC/LICENSE
*
* 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.
*/
#ifndef _NODE_BASE_H_
#define _NODE_BASE_H_
#include "common.h"
#include "fs_operator.h"
#include "tools.h"
struct base_script_t;
class NodeBase {
public:
NodeBase(const uint32_t id, const string& name,
const string& type, const string& desc, const key_map_t& keymap);
virtual ~NodeBase(void);
virtual NodeBase* run(base_script_t* param) = 0;
virtual bool load_other();
public:
/**
* @brief 判断map中是否有需要的变量,如果有,则赋值给out
*
* @param [in/out] vars : key_map_t&
* @param [in/out] key : const char*
* @param [in/out] out : std::string&
* @return bool
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/06 14:17:04
**/
bool valid_str(key_map_t& vars, const char* key, std::string& out, bool trim = true);
/**
* @brief
*
* @param [in/out] vars : key_map_t&
* @param [in/out] key : const char*
* @param [in/out] out : int32_t&
* @return bool
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/06 15:55:47
**/
bool valid_str(key_map_t& vars, const char* key, uint32_t& out);
static bool get_sys_var(const map<string, variable_t>& vars, uint32_t type,
std::string& out) {
bool result = false;
if (type >= _sys_var_t::END) {
return false;
}
map<string, variable_t>::const_iterator it = vars.find(SYS_VAR[type]);
if (it != vars.end() && NULL != it->second.pvalue) {
out = *(string*)(it->second.pvalue);
result = true;
}
return result;
}
/**
* @brief 进入节点
*
* @param [in/out] map<string : const
* @param [in/out] vars : variable_t>&
* @return const char*
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/01 14:31:23
**/
virtual std::string enter(const map<string, variable_t>& vars)const ;
/**
* @brief 离开节点
*
* @param [in/out] map<string : const
* @param [in/out] vars : variable_t>&
* @return const char*
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/01 14:31:34
**/
virtual std::string leave(const map<string, variable_t>& vars)const ;
/**
* @brief 封装了key_map的查找函数
*
* @param [in/out] key : string&
* @return bool
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/02 10:54:36
**/
bool key_map_find(string& key);
/**
* @brief 封装了节点事件出口的检测
*
* @param [in/out] exit : string
* @return bool
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/02 10:54:52
**/
bool check_exit(string exit);
/**
* @brief 系统调用
*
* @param [in/out] system : string&
* @return string
* @retval
* @see
* @note 目前支持的系统调用:
* _DATE:当前日期
* _TIME:当前时间
* _SECOND:1970-1-1 08:00:00 之后经过的秒数
* _INBOUND_NUM:呼入占用的通道数
* _AUTORUN_NUM:外呼占用的通道数
* @author chenyuzhen
* @date 2011/09/02 10:38:09
**/
bool system_invoke(const std::string& system, std::string& out);
/**
* @brief 字符串函数
*
* @param [in/out] func : string&
* @param [in/out] param : string&
* @return bool 仅仅在找到了函数,且函数执行失败的时候发挥false
* 其他情况下返回true
* @retval
* @see
* @note 目前支持的字符串函数有:
* LENGTH:获取字符串的长度 LENGTH(str)
* LEFT:获取字符串左边n个字符LEFT(str,n)
* RIGHT:获取字符串右边n个字符RIGHT(str,n)
* @author chenyuzhen
* @date 2011/09/02 10:48:04
**/
bool str_func_invoke(const string& func, const string& param, std::string& out);
bool db_func_invoke(const string& func, const string& name, uint32_t param,
const map<string, variable_t>& name_var_map, std::string& out);
bool map_func_invoke(const string& func, const string& name, const string& param,
const map<string, variable_t>& name_var_map, std::string& out);
/**
* @brief 解析表达式,转换为系统函数的调用
*
* @param [in] exp : string&
* @param [in] name_var_map : map<string,variable_t>&
* @return string&
* @retval
* @see system_invoke
* @note
* @author chenyuzhen
* @date 2011/09/02 10:48:04
**/
bool parse_sys_invoke(const string& exp, const map<string, variable_t>& name_var_map,
string& out);
/**
* @brief 解析流程级别的表达式,替换为流程级别的变量值
*
* @param [in] exp : string&
* @param [in] name_var_map : map<string,variable_t>&
* @return string&
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/02 10:48:04
**/
bool parse_variable(const string& exp_, const map<string, variable_t>& name_var_map,
string& out);
/**
* @brief 解析函数调用,然后调用相关函数完成相关功能
*
* @param [in] exp : string&
* @param [in] name_var_map : map<string,variable_t>&
* @return string&
* @retval
* @see str_func_invoke,db_func_invoke,map_func_invoke
* @note
* @author chenyuzhen
* @date 2011/09/02 10:48:04
**/
bool parse_function(const string& exp_, const map<string, variable_t>& name_var_map,
string& out);
/**
* @brief 解析表达式的统一入口
*
* @param [in] exp : string&
* @param [in] name_var_map : map<string,variable_t>&
* @return string&
* @retval
* @see parse_function,parse_variable,parse_sys_invoke
* @note
* @author chenyuzhen
* @date 2011/09/02 10:48:04
**/
bool parse_expression(const string exp, const map<string, variable_t>& name_var_map,
string& out);
/**
* @brief 所有表达式进行转换
*
* @param [in/out] exp : const std::string
* @param [in/out] map<string : const
* @param [in/out] name_var_map : variable_t>&
* @param [in/out] out : string&
* @return bool
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/09/21 12:35:35
**/
bool parse_all(const std::string exp, const map<string, variable_t>& name_var_map,
string& out);
public:
uint32_t _id;
string _name;
string _desc;
string _type;
key_map_t _key_map;
map<string, uint32_t> _exit_id_map; //事件出口到节点ID的映射
map<string, NodeBase*> _exit_node_map; //事件出口到节点对象的映射
vector<string> _system_invoke_vec;
vector<string> _function_vec;
protected:
const static char* EXIT_SUCC; ///<
const static char* EXIT_FAIL; ///<
const static char* SYS_DATE; ///<
const static char* SYS_TIME; ///<
const static char* SYS_SEC; ///<
const static char* SYS_INBOUND_NUM; ///<
const static char* SYS_OUTBOUND_NUM; ///<
const static char* SYS_ANSWER_TIME; ///<
const static char* SYS_HANGUP_CAUSE; ///<
const static char* FUNC_STR_LEN; ///<
const static char* FUNC_STR_LEFT; ///<
const static char* FUNC_STR_RIGHT; ///<
const static char* FUNC_STR_FIND; ///<
const static char* FUNC_STR_SUB; ///<
const static char* FUNC_STR_REPLACE; ///<
const static char* FUNC_INT_RAND; ///<
const static char* FUNC_DB_NEXT; ///<
const static char* FUNC_DB_VAL; ///<
const static char* FUNC_MAP_VAL; ///<
const static char* HANGUP_CAUSE_SYS;
const static char* HANGUP_CAUSE_USER;
const static char* HANGUP_CAUSE_THIRD;
};
#endif