22 #ifndef _PLUGINS_OPENPRS_AGENT_MOD_UTILS_H_ 23 #define _PLUGINS_OPENPRS_AGENT_MOD_UTILS_H_ 32 #include <opaque-pub.h> 33 #include <action_f-pub.h> 34 #include <constant-pub.h> 35 #include <ev-function_f-pub.h> 36 #include <ev-predicate_f-pub.h> 37 #include <intention_f-pub.h> 38 #include <macro-pub.h> 39 #include <oprs-type-pub.h> 40 #include <oprs-type_f-pub.h> 41 #include <shashPack_f.h> 42 #include <slistPack-pub.h> 43 #include <user-end-hook_f-pub.h> 48 typedef Slist *List_Envar;
49 List_Envar global_var_list;
52 typedef struct type Type;
53 typedef Slist * TypeList;
54 typedef Slist * SymList;
58 typedef enum { LOGICAL_VARIABLE, PROGRAM_VARIABLE } Variable_Type;
65 Variable_Type type BITFIELDS( : 8);
85 get_fawkes_host_port(std::string &fawkes_host,
unsigned short &fawkes_port)
88 sl_loop_through_slist(global_var_list, env, Envar *)
90 if (strcmp(env->name,
"@@FAWKES_HOST") == 0 || strcmp(env->name,
"@@fawkes_host") == 0) {
91 if (env->value->type != STRING) {
92 fprintf(stderr,
"Error: @@FAWKES_HOST is not of type STRING\n");
95 fawkes_host = env->value->u.string;
96 }
else if (strcmp(env->name,
"@@FAWKES_PORT") == 0 || strcmp(env->name,
"@@fawkes_port") == 0) {
97 if (env->value->type != STRING) {
98 fprintf(stderr,
"Error: @@FAWKES_PORT is not of type STRING\n");
101 fawkes_port = atoi(env->value->u.string);
105 if (fawkes_host.empty()) {
106 fawkes_host = getenv(
"FAWKES_HOST");
108 if (fawkes_port == 0) {
109 fawkes_port = atoi(getenv(
"FAWKES_PORT"));
112 return (!fawkes_host.empty() && fawkes_port != 0);
118 # define ACTION_RETURN(value) \ 120 if (value == nil_sym || value == lisp_t_sym) { \ 121 printf("Action returns: %s\n", \ 122 value == nil_sym ? "FAIL" : (value == wait_sym ? ":WAIT" : "FINAL")); \ 124 Term *res = MAKE_OBJECT(Term); \ 130 # define ACTION_RETURN(value) \ 132 Term *res = MAKE_OBJECT(Term); \ 138 #define ACTION_FAIL() ACTION_RETURN(nil_sym); 139 #define ACTION_WAIT() ACTION_RETURN(wait_sym); 140 #define ACTION_FINAL() ACTION_RETURN(lisp_t_sym); 143 assert_arg_type(
const char *func_name, TermList &tl,
int index, Term_Type t_type)
145 Term *t = (Term *)get_list_pos(tl, index);
146 if (t->type != t_type) {
147 const char *type =
"UNKNOWN";
149 case INTEGER: type =
"INTEGER";
break;
150 case LONG_LONG: type =
"LONG_LONG";
break;
151 case TT_FLOAT: type =
"TT_FLOAT";
break;
152 case STRING: type =
"STRING";
break;
153 case TT_ATOM: type =
"TT_ATOM";
break;
154 case EXPRESSION: type =
"EXPRESSION";
break;
155 case VARIABLE: type =
"VARIABLE";
break;
156 case LISP_LIST: type =
"LISP_LIST";
break;
157 case INT_ARRAY: type =
"INT_ARRAY";
break;
158 case FLOAT_ARRAY: type =
"FLOAT_ARRAY";
break;
159 case C_LIST: type =
"C_LIST";
break;
160 case TT_FACT: type =
"TT_FACT";
break;
161 case TT_GOAL: type =
"FF_GOAL";
break;
162 case TT_INTENTION: type =
"TT_INTENTION";
break;
163 case TT_OP_INSTANCE: type =
"TT_OP_INSTANCE";
break;
164 case U_POINTER: type =
"U_POINTER";
break;
165 case U_MEMORY: type =
"U_MEMORY";
break;
167 fprintf(stderr,
"Error[%s]: argument type is not a %s\n", func_name, type);
174 #define ACTION_ASSERT_ARG_LENGTH(func_name, tl, length) \ 176 int terms_len = sl_slist_length(tl); \ 177 if (terms_len != length) { \ 179 "Error[%s]: invalid number of arguments:" \ 180 " req %i, got %i\n", \ 188 #define ACTION_SET_AND_ASSERT_ARG_TYPE(func_name, var, tl, index, t_type) \ 190 if (!assert_arg_type(func_name, tl, index, t_type)) \ 192 var = (Term *)get_list_pos(tl, index); \ 196 #define ACTION_ASSERT_B_ARG_LENGTH(func_name, tl, length) \ 198 int terms_len = sl_slist_length(tl); \ 199 if (terms_len != length) { \ 201 "Error[%s]: invalid number of arguments:" \ 202 " req %i, got %i\n", \ 210 #define ACTION_SET_AND_ASSERT_B_ARG_TYPE(func_name, var, tl, index, t_type) \ 212 if (!assert_arg_type(func_name, tl, index, t_type)) \ 214 var = (Term *)get_list_pos(tl, index); \ 217 #define ACTION_ASSERT_B_ARG_TYPE(func_name, var, tl, index, t_type) \ 219 if (!assert_arg_type(func_name, tl, index, t_type)) \