22 #ifndef __PLUGINS_OPENPRS_AGENT_MOD_UTILS_H_ 23 #define __PLUGINS_OPENPRS_AGENT_MOD_UTILS_H_ 27 #include <constant-pub.h> 28 #include <opaque-pub.h> 29 #include <oprs-type-pub.h> 30 #include <oprs-type_f-pub.h> 31 #include <macro-pub.h> 32 #include <slistPack-pub.h> 33 #include <shashPack_f.h> 34 #include <user-end-hook_f-pub.h> 35 #include <action_f-pub.h> 36 #include <intention_f-pub.h> 37 #include <ev-function_f-pub.h> 38 #include <ev-predicate_f-pub.h> 47 typedef Slist *List_Envar;
48 List_Envar global_var_list;
51 typedef struct type Type;
52 typedef Slist *TypeList;
53 typedef Slist *SymList;
57 typedef enum {LOGICAL_VARIABLE, PROGRAM_VARIABLE} Variable_Type;
63 Variable_Type type BITFIELDS(:8);
82 get_fawkes_host_port(std::string &fawkes_host,
unsigned short &fawkes_port)
85 sl_loop_through_slist(global_var_list, env, Envar *) {
86 if (strcmp(env->name,
"@@FAWKES_HOST") == 0 || strcmp(env->name,
"@@fawkes_host") == 0) {
87 if (env->value->type != STRING) {
88 fprintf(stderr,
"Error: @@FAWKES_HOST is not of type STRING\n");
91 fawkes_host = env->value->u.string;
92 }
else if (strcmp(env->name,
"@@FAWKES_PORT") == 0 || strcmp(env->name,
"@@fawkes_port") == 0) {
93 if (env->value->type != STRING) {
94 fprintf(stderr,
"Error: @@FAWKES_PORT is not of type STRING\n");
97 fawkes_port = atoi(env->value->u.string);
101 if (fawkes_host.empty()) {
102 fawkes_host = getenv(
"FAWKES_HOST");
104 if (fawkes_port == 0) {
105 fawkes_port = atoi(getenv(
"FAWKES_PORT"));
108 return (! fawkes_host.empty() && fawkes_port != 0);
114 # define ACTION_RETURN(value) \ 116 if (value == nil_sym || value == lisp_t_sym) { \ 117 printf("Action returns: %s\n", value == nil_sym ? "FAIL" : (value == wait_sym ? ":WAIT" : "FINAL")); \ 119 Term *res = MAKE_OBJECT(Term); res->type = ATOM; res->u.id = value; return res; \ 122 # define ACTION_RETURN(value) \ 123 do { Term *res = MAKE_OBJECT(Term); res->type = ATOM; res->u.id = value; return res; } while (0); 125 #define ACTION_FAIL() ACTION_RETURN(nil_sym); 126 #define ACTION_WAIT() ACTION_RETURN(wait_sym); 127 #define ACTION_FINAL() ACTION_RETURN(lisp_t_sym); 130 assert_arg_type(
const char *func_name, TermList &tl,
int index, Term_Type t_type)
132 Term *t = (Term *)get_list_pos(tl, index);
133 if (t->type != t_type) {
134 const char *type =
"UNKNOWN";
136 case INTEGER: type =
"INTEGER";
break;
137 case LONG_LONG: type =
"LONG_LONG";
break;
138 case TT_FLOAT: type =
"TT_FLOAT";
break;
139 case STRING: type =
"STRING";
break;
140 case TT_ATOM: type =
"TT_ATOM";
break;
141 case EXPRESSION: type =
"EXPRESSION";
break;
142 case VARIABLE: type =
"VARIABLE";
break;
143 case LISP_LIST: type =
"LISP_LIST";
break;
144 case INT_ARRAY: type =
"INT_ARRAY";
break;
145 case FLOAT_ARRAY: type =
"FLOAT_ARRAY";
break;
146 case C_LIST: type =
"C_LIST";
break;
147 case TT_FACT: type =
"TT_FACT";
break;
148 case TT_GOAL: type =
"FF_GOAL";
break;
149 case TT_INTENTION: type =
"TT_INTENTION";
break;
150 case TT_OP_INSTANCE: type =
"TT_OP_INSTANCE";
break;
151 case U_POINTER: type =
"U_POINTER";
break;
152 case U_MEMORY: type =
"U_MEMORY";
break;
154 fprintf(stderr,
"Error[%s]: argument type is not a %s\n",
162 #define ACTION_ASSERT_ARG_LENGTH(func_name, tl, length) \ 164 int terms_len = sl_slist_length(tl); \ 165 if (terms_len != length) { \ 166 fprintf(stderr, "Error[%s]: invalid number of arguments:" \ 167 " req %i, got %i\n", func_name, length, terms_len); \ 172 #define ACTION_SET_AND_ASSERT_ARG_TYPE(func_name, var, tl, index, t_type) \ 174 if (! assert_arg_type(func_name, tl, index, t_type)) ACTION_FAIL(); \ 175 var = (Term *)get_list_pos(tl, index); \ 180 #define ACTION_ASSERT_B_ARG_LENGTH(func_name, tl, length) \ 182 int terms_len = sl_slist_length(tl); \ 183 if (terms_len != length) { \ 184 fprintf(stderr, "Error[%s]: invalid number of arguments:" \ 185 " req %i, got %i\n", func_name, length, terms_len); \ 190 #define ACTION_SET_AND_ASSERT_B_ARG_TYPE(func_name, var, tl, index, t_type) \ 192 if (! assert_arg_type(func_name, tl, index, t_type)) return false; \ 193 var = (Term *)get_list_pos(tl, index); \ 196 #define ACTION_ASSERT_B_ARG_TYPE(func_name, var, tl, index, t_type) \ 197 do { if (! assert_arg_type(func_name, tl, index, t_type)) return false; } while (0);