Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Data Structures | Macros | Typedefs | Functions
io_soar.h File Reference
#include "callback.h"

Go to the source code of this file.

Data Structures

struct  io_wme_struct
struct  output_call_info_struct
struct  output_link_struct

Macros

#define ADDED_OUTPUT_COMMAND   1
#define MODIFIED_OUTPUT_COMMAND   2
#define NORMAL_INPUT_CYCLE   2
#define REMOVED_OUTPUT_COMMAND   3
#define TOP_STATE_JUST_CREATED   1
#define TOP_STATE_JUST_REMOVED   3

Typedefs

typedef struct agent_struct agent
typedef char Bool
typedef unsigned char byte
typedef struct cons_struct cons
typedef struct io_wme_struct io_wme
typedef cons list
typedef struct
output_call_info_struct 
output_call_info
typedef struct output_link_struct output_link
typedef void * soar_call_data
typedef struct callback_struct soar_callback
typedef void * soar_callback_data
typedef union symbol_union Symbol
typedef struct wme_struct wme

Functions

void add_input_function (agent *a, soar_callback_fn f, soar_callback_data cb_data, soar_callback_free_fn free_fn, const char *name)
wmeadd_input_wme (agent *thisAgent, Symbol *id, Symbol *attr, Symbol *value)
void add_output_function (agent *thisAgent, soar_callback_fn f, soar_callback_data cb_data, soar_callback_free_fn free_fn, int eventID, const char *output_link_name)
void deallocate_io_wme_list (agent *thisAgent, io_wme *iw)
void do_input_cycle (agent *thisAgent)
void do_output_cycle (agent *thisAgent)
Symbolget_io_float_constant (agent *thisAgent, double value)
Symbolget_io_identifier (agent *thisAgent, char first_letter, uint64_t number)
Symbolget_io_int_constant (agent *thisAgent, int64_t value)
Symbolget_io_sym_constant (agent *thisAgent, char const *name)
io_wmeget_io_wmes_for_output_link (agent *thisAgent, output_link *ol)
Symbolget_new_io_identifier (agent *thisAgent, char first_letter)
Symbolget_next_io_symbol_from_text_input_line (agent *thisAgent, char **text_read_position)
Symbolget_output_value (io_wme *outputs, Symbol *id, Symbol *attr)
void inform_output_module_of_wm_changes (agent *thisAgent,::list *wmes_being_added,::list *wmes_being_removed)
void init_soar_io (agent *thisAgent)
uint64_t release_io_symbol (agent *thisAgent, Symbol *sym)
void remove_input_function (agent *a, const char *name)
Bool remove_input_wme (agent *thisAgent, wme *w)
void remove_output_function (agent *thisAgent, const char *name)

Macro Definition Documentation

#define ADDED_OUTPUT_COMMAND   1

Definition at line 187 of file io_soar.h.

Referenced by do_output_cycle().

#define MODIFIED_OUTPUT_COMMAND   2

Definition at line 188 of file io_soar.h.

Referenced by do_output_cycle().

#define NORMAL_INPUT_CYCLE   2

Definition at line 118 of file io_soar.h.

Referenced by do_input_cycle().

#define REMOVED_OUTPUT_COMMAND   3

Definition at line 189 of file io_soar.h.

Referenced by do_output_cycle().

#define TOP_STATE_JUST_CREATED   1

Definition at line 117 of file io_soar.h.

#define TOP_STATE_JUST_REMOVED   3

Definition at line 119 of file io_soar.h.

Referenced by do_input_cycle().

Typedef Documentation

typedef struct agent_struct agent

Definition at line 40 of file io_soar.h.

typedef char Bool

Definition at line 36 of file io_soar.h.

typedef unsigned char byte

Definition at line 37 of file io_soar.h.

typedef struct cons_struct cons

Definition at line 38 of file io_soar.h.

typedef struct io_wme_struct io_wme
typedef cons list

Definition at line 42 of file io_soar.h.

typedef void* soar_call_data

Definition at line 46 of file io_soar.h.

Definition at line 41 of file io_soar.h.

typedef void* soar_callback_data

Definition at line 45 of file io_soar.h.

typedef union symbol_union Symbol

Definition at line 43 of file io_soar.h.

typedef struct wme_struct wme

Definition at line 39 of file io_soar.h.

Function Documentation

void add_input_function ( agent a,
soar_callback_fn  f,
soar_callback_data  cb_data,
soar_callback_free_fn  free_fn,
const char *  name 
)

Definition at line 81 of file io.cpp.

References INPUT_PHASE_CALLBACK, and soar_add_callback().

{
soar_add_callback(thisAgent, INPUT_PHASE_CALLBACK, f, INPUT_PHASE_CALLBACK, cb_data, free_fn, name);
}
wme* add_input_wme ( agent thisAgent,
Symbol id,
Symbol attr,
Symbol value 
)

Definition at line 199 of file io.cpp.

References add_wme_to_wm(), FALSE, symbol_union::id, identifier_struct::input_wmes, insert_at_head_of_dll, make_wme(), pi_struct::next, NIL, pi_struct::prev, print(), wma_activate_wme(), and wma_enabled().

Referenced by init_agent_memory().

{
wme *w;
/* --- a little bit of error checking --- */
if (! (id && attr && value)) {
print (thisAgent, "Error: an input routine gave a NULL argument to add_input_wme.\n");
return NIL;
}
/* --- go ahead and add the wme --- */
w = make_wme (thisAgent, id, attr, value, FALSE);
insert_at_head_of_dll (id->id.input_wmes, w, next, prev);
if ( wma_enabled( thisAgent ) )
{
wma_activate_wme( thisAgent, w );
}
add_wme_to_wm (thisAgent, w);
//PrintDebugFormat("Added wme with timetag %d to id %c%d ",w->timetag,id->id.name_letter,id->id.name_number) ;
return w;
}
void add_output_function ( agent thisAgent,
soar_callback_fn  f,
soar_callback_data  cb_data,
soar_callback_free_fn  free_fn,
int  eventID,
const char *  output_link_name 
)

Definition at line 91 of file io.cpp.

References OUTPUT_PHASE_CALLBACK, print(), soar_add_callback(), and soar_exists_callback_id().

{
if (soar_exists_callback_id (thisAgent, OUTPUT_PHASE_CALLBACK, output_link_name)
!= NULL)
{
print (thisAgent, "Error: tried to add_output_function with duplicate name %s\n",
output_link_name);
/* Replaced deprecated control_c_handler with an appropriate assertion */
//control_c_handler(0);
assert(0 && "error in io.cpp (control_c_handler() used to be called here)");
}
else
{
soar_add_callback(thisAgent, OUTPUT_PHASE_CALLBACK, f, eventID, cb_data, free_fn,
output_link_name);
}
}
void deallocate_io_wme_list ( agent thisAgent,
io_wme iw 
)

Definition at line 645 of file io.cpp.

Referenced by do_output_cycle().

{
io_wme *next;
while (iw) {
next = iw->next;
free_with_pool (&thisAgent->io_wme_pool, iw);
void do_input_cycle ( agent thisAgent)

Definition at line 287 of file io.cpp.

References do_buffered_wm_and_ownership_changes(), FALSE, INPUT_PHASE_CALLBACK, agent_struct::io_header, agent_struct::io_header_input, agent_struct::io_header_link, agent_struct::io_header_output, NIL, NORMAL_INPUT_CYCLE, agent_struct::output_link_changed, agent_struct::prev_top_state, release_io_symbol(), soar_invoke_callbacks(), agent_struct::top_state, and TOP_STATE_JUST_REMOVED.

Referenced by clear_goal_stack(), do_one_top_level_phase(), and init_agent_memory().

{
if (thisAgent->prev_top_state && (!thisAgent->top_state)) {
/* --- top state was just removed --- */
reinterpret_cast<soar_call_data>(TOP_STATE_JUST_REMOVED) );
release_io_symbol (thisAgent, thisAgent->io_header);
release_io_symbol (thisAgent, thisAgent->io_header_input);
release_io_symbol (thisAgent, thisAgent->io_header_output);
thisAgent->io_header = NIL; /* RBD added 3/25/95 */
thisAgent->io_header_input = NIL; /* RBD added 3/25/95 */
thisAgent->io_header_output = NIL; /* KJC added 3/3/99 */
thisAgent->io_header_link = NIL; /* KJC added 3/3/99 */
} else if ((!thisAgent->prev_top_state) && thisAgent->top_state) {
/* --- top state was just created --- */
/* Create io structure on top state. */
/*
thisAgent->io_header = get_new_io_identifier (thisAgent, 'I');
thisAgent->io_header_link = add_input_wme (thisAgent,
thisAgent->top_state,
thisAgent->io_symbol,
thisAgent->io_header);
thisAgent->io_header_input = get_new_io_identifier (thisAgent, 'I');
thisAgent->io_header_output = get_new_io_identifier (thisAgent, 'I');
add_input_wme (thisAgent, thisAgent->io_header,
make_sym_constant(thisAgent, "input-link"),
thisAgent->io_header_input);
add_input_wme (thisAgent, thisAgent->io_header,
make_sym_constant(thisAgent, "output-link"),
thisAgent->io_header_output);
*/
/* --- add top state io link before calling input phase callback so
* --- code can use "wmem" command.
*/
/*
do_buffered_wm_and_ownership_changes(thisAgent);
soar_invoke_callbacks(thisAgent, thisAgent, INPUT_PHASE_CALLBACK,
(soar_call_data) TOP_STATE_JUST_CREATED);
*/
}
/* --- if there is a top state, do the normal input cycle --- */
if (thisAgent->top_state) {
reinterpret_cast<soar_call_data>(NORMAL_INPUT_CYCLE) );
}
/* --- do any WM resulting changes --- */
/* --- save current top state for next time --- */
thisAgent->prev_top_state = thisAgent->top_state;
/* --- reset the output-link status flag to FALSE
* --- when running til output, only want to stop if agent
* --- does add-wme to output. don't stop if add-wme done
* --- during input cycle (eg simulator updates sensor status)
* KJC 11/23/98
*/
thisAgent->output_link_changed = FALSE;
}
void do_output_cycle ( agent thisAgent)

Definition at line 665 of file io.cpp.

References ADDED_OUTPUT_COMMAND, calculate_output_link_tc_info(), output_link_struct::cb, agent_struct::current_phase, callback_struct::data, deallocate_io_wme_list(), callback_struct::eventid, agent_struct::existing_output_links, callback_struct::function, get_io_wmes_for_output_link(), output_link_struct::link_wme, output_call_info_struct::mode, MODIFIED_BUT_SAME_TC_OL_STATUS, MODIFIED_OL_STATUS, MODIFIED_OUTPUT_COMMAND, NEW_OL_STATUS, pi_struct::next, output_link_struct::next, NIL, agent_struct::output_link_pool, output_call_info_struct::outputs, pi_struct::prev, remove_from_dll, remove_output_link_tc_info(), REMOVED_OL_STATUS, REMOVED_OUTPUT_COMMAND, output_link_struct::status, agent_struct::timers_decision_cycle_phase, agent_struct::timers_kernel, agent_struct::timers_output_function_cpu_time, agent_struct::timers_phase, agent_struct::timers_total_kernel_time, UNCHANGED_OL_STATUS, and wme_remove_ref().

Referenced by clear_goal_stack(), do_one_top_level_phase(), and init_agent_memory().

{
output_link *ol, *next_ol;
io_wme *iw_list;
output_call_info output_call_data;
for (ol=thisAgent->existing_output_links; ol!=NIL; ol=next_ol) {
next_ol = ol->next;
switch (ol->status) {
/* --- output link is unchanged, so do nothing --- */
break;
/* --- calculate tc, and call the output function --- */
iw_list = get_io_wmes_for_output_link (thisAgent, ol);
output_call_data.mode = ADDED_OUTPUT_COMMAND;
output_call_data.outputs = iw_list;
#ifndef NO_TIMING_STUFF /* moved here from do_one_top_level_phase June 05. KJC */
thisAgent->timers_phase.stop();
thisAgent->timers_kernel.stop();
thisAgent->timers_total_kernel_time.update(thisAgent->timers_kernel);
thisAgent->timers_decision_cycle_phase[thisAgent->current_phase].update(thisAgent->timers_phase);
thisAgent->timers_kernel.start();
#endif
if (ol->cb) (ol->cb->function)(thisAgent, ol->cb->eventid, ol->cb->data, &output_call_data);
#ifndef NO_TIMING_STUFF
thisAgent->timers_kernel.stop();
thisAgent->timers_output_function_cpu_time.update(thisAgent->timers_kernel);
thisAgent->timers_kernel.start();
thisAgent->timers_phase.start();
#endif
deallocate_io_wme_list (thisAgent, iw_list);
break;
/* --- don't have to redo the TC, but do call the output function --- */
iw_list = get_io_wmes_for_output_link (thisAgent, ol);
output_call_data.mode = MODIFIED_OUTPUT_COMMAND;
output_call_data.outputs = iw_list;
#ifndef NO_TIMING_STUFF /* moved here from do_one_top_level_phase June 05. KJC */
thisAgent->timers_phase.stop();
thisAgent->timers_kernel.stop();
thisAgent->timers_total_kernel_time.update(thisAgent->timers_kernel);
thisAgent->timers_decision_cycle_phase[thisAgent->current_phase].update(thisAgent->timers_phase);
thisAgent->timers_kernel.start();
#endif
if (ol->cb) (ol->cb->function)(thisAgent, ol->cb->eventid, ol->cb->data, &output_call_data);
#ifndef NO_TIMING_STUFF
thisAgent->timers_kernel.stop();
thisAgent->timers_output_function_cpu_time.update(thisAgent->timers_kernel);
thisAgent->timers_kernel.start();
thisAgent->timers_phase.start();
#endif
deallocate_io_wme_list (thisAgent, iw_list);
break;
/* --- redo the TC, and call the output function */
remove_output_link_tc_info (thisAgent, ol);
iw_list = get_io_wmes_for_output_link (thisAgent, ol);
output_call_data.mode = MODIFIED_OUTPUT_COMMAND;
output_call_data.outputs = iw_list;
#ifndef NO_TIMING_STUFF /* moved here from do_one_top_level_phase June 05. KJC */
thisAgent->timers_phase.stop();
thisAgent->timers_kernel.stop();
thisAgent->timers_total_kernel_time.update(thisAgent->timers_kernel);
thisAgent->timers_decision_cycle_phase[thisAgent->current_phase].update(thisAgent->timers_phase);
thisAgent->timers_kernel.start();
#endif
if (ol->cb) (ol->cb->function)(thisAgent, ol->cb->eventid, ol->cb->data, &output_call_data);
#ifndef NO_TIMING_STUFF
thisAgent->timers_kernel.stop();
thisAgent->timers_output_function_cpu_time.update(thisAgent->timers_kernel);
thisAgent->timers_kernel.start();
thisAgent->timers_phase.start();
#endif
deallocate_io_wme_list (thisAgent, iw_list);
break;
/* --- call the output function, and free output_link structure --- */
remove_output_link_tc_info (thisAgent, ol); /* sets ids_in_tc to NIL */
iw_list = get_io_wmes_for_output_link (thisAgent, ol); /* gives just the link wme */
output_call_data.mode = REMOVED_OUTPUT_COMMAND;
output_call_data.outputs = iw_list;
#ifndef NO_TIMING_STUFF /* moved here from do_one_top_level_phase June 05. KJC */
thisAgent->timers_phase.stop();
thisAgent->timers_kernel.stop();
thisAgent->timers_total_kernel_time.update(thisAgent->timers_kernel);
thisAgent->timers_decision_cycle_phase[thisAgent->current_phase].update(thisAgent->timers_phase);
thisAgent->timers_kernel.start();
#endif
if (ol->cb) (ol->cb->function)(thisAgent, ol->cb->eventid, ol->cb->data, &output_call_data);
#ifndef NO_TIMING_STUFF
thisAgent->timers_kernel.stop();
thisAgent->timers_output_function_cpu_time.update(thisAgent->timers_kernel);
thisAgent->timers_kernel.start();
thisAgent->timers_phase.start();
#endif
deallocate_io_wme_list (thisAgent, iw_list);
wme_remove_ref (thisAgent, ol->link_wme);
remove_from_dll (thisAgent->existing_output_links, ol, next, prev);
free_with_pool (&thisAgent->output_link_pool, ol);
break;
}
Symbol* get_io_float_constant ( agent thisAgent,
double  value 
)

Definition at line 191 of file io.cpp.

References make_float_constant().

Referenced by get_io_symbol_from_tio_constituent_string().

{
return make_float_constant (thisAgent, value);
}
Symbol* get_io_identifier ( agent thisAgent,
char  first_letter,
uint64_t  number 
)

Definition at line 166 of file io.cpp.

References find_identifier(), make_new_identifier(), symbol_add_ref(), and TOP_GOAL_LEVEL.

{
Symbol* id = find_identifier(thisAgent, first_letter, number) ;
// DJP: The other "make_<type>" methods either make a new object or incremenent the refence
// on an existing object. So I'm going to make this method function the same way for identifiers.
if (id)
{
}
else
{
id = make_new_identifier (thisAgent, first_letter, TOP_GOAL_LEVEL);
}
return id ;
}
Symbol* get_io_int_constant ( agent thisAgent,
int64_t  value 
)

Definition at line 187 of file io.cpp.

References make_int_constant().

Referenced by get_io_symbol_from_tio_constituent_string().

{
return make_int_constant (thisAgent, value);
}
Symbol* get_io_sym_constant ( agent thisAgent,
char const *  name 
)

Definition at line 183 of file io.cpp.

References make_sym_constant().

Referenced by get_next_io_symbol_from_text_input_line().

{
return make_sym_constant (thisAgent, name);
}
io_wme* get_io_wmes_for_output_link ( agent thisAgent,
output_link ol 
)

Definition at line 626 of file io.cpp.

Referenced by do_output_cycle().

{
cons *c;
Symbol *id;
slot *s;
wme *w;
thisAgent->collected_io_wmes = NIL;
for (c=ol->ids_in_tc; c!=NIL; c=c->rest) {
id = static_cast<symbol_union *>(c->first);
for (w=id->id.input_wmes; w!=NIL; w=w->next)
for (s=id->id.slots; s!=NIL; s=s->next)
for (w=s->wmes; w!=NIL; w=w->next)
Symbol* get_new_io_identifier ( agent thisAgent,
char  first_letter 
)

Definition at line 161 of file io.cpp.

References make_new_identifier(), and TOP_GOAL_LEVEL.

Referenced by init_agent_memory().

{
return make_new_identifier (thisAgent, first_letter, TOP_GOAL_LEVEL);
}
Symbol* get_next_io_symbol_from_text_input_line ( agent thisAgent,
char **  text_read_position 
)

Definition at line 869 of file io.cpp.

References get_io_sym_constant(), get_io_symbol_from_tio_constituent_string(), MAX_TEXT_INPUT_LINE_LENGTH, NIL, tio_constituent_char, and tio_whitespace.

Referenced by accept_rhs_function_code().

{
char *ch;
char input_string[MAX_TEXT_INPUT_LINE_LENGTH+2];
int input_lexeme_length;
ch = *text_read_position;
/* --- scan past any whitespace --- */
while (tio_whitespace[static_cast<unsigned char>(*ch)]) ch++;
/* --- if end of line, return NIL --- */
if ((*ch=='\n')||(*ch==0)) { *text_read_position = ch; return NIL; }
/* --- if not a constituent character, return single-letter symbol --- */
if (! tio_constituent_char[static_cast<unsigned char>(*ch)]) {
input_string[0] = *ch++;
input_string[1] = 0;
*text_read_position = ch;
return get_io_sym_constant (thisAgent, input_string);
}
/* --- read string of constituents --- */
input_lexeme_length = 0;
while (tio_constituent_char[static_cast<unsigned char>(*ch)])
input_string[input_lexeme_length++] = *ch++;
/* --- return the appropriate kind of symbol --- */
input_string[input_lexeme_length] = 0;
Symbol* get_output_value ( io_wme outputs,
Symbol id,
Symbol attr 
)

Definition at line 793 of file io.cpp.

References io_wme_struct::attr, io_wme_struct::id, io_wme_struct::next, NIL, and io_wme_struct::value.

{
io_wme *iw;
for (iw=outputs; iw!=NIL; iw=iw->next)
if ( ((id==NIL)||(id==iw->id)) &&
void inform_output_module_of_wm_changes ( agent thisAgent,
::list wmes_being_added,
::list wmes_being_removed 
)
void init_soar_io ( agent thisAgent)

Definition at line 910 of file io.cpp.

References extra_tio_constituents, FALSE, init_memory_pool(), agent_struct::io_wme_pool, agent_struct::output_link_pool, tio_constituent_char, tio_whitespace, and TRUE.

Referenced by init_soar_agent().

{
unsigned int i;
init_memory_pool (thisAgent, &thisAgent->output_link_pool, sizeof(output_link), "output link");
init_memory_pool (thisAgent, &thisAgent->io_wme_pool, sizeof(io_wme), "io wme");
/* --- setup constituent_char array --- */
for (i=0; i<256; i++) tio_constituent_char[i] = (isalnum(i) != 0);
for (i=0; i<strlen(extra_tio_constituents); i++)
/* --- setup whitespace array --- */
uint64_t release_io_symbol ( agent thisAgent,
Symbol sym 
)

Definition at line 195 of file io.cpp.

References symbol_remove_ref().

Referenced by accept_rhs_function_code(), and do_input_cycle().

{
return symbol_remove_ref (thisAgent, sym);
}
void remove_input_function ( agent a,
const char *  name 
)

Definition at line 87 of file io.cpp.

References INPUT_PHASE_CALLBACK, and soar_remove_callback().

Bool remove_input_wme ( agent thisAgent,
wme w 
)

Definition at line 251 of file io.cpp.

References FALSE, wme_struct::gds, gds_invalid_so_remove_goal(), gds_struct::goal, wme_struct::id, symbol_union::id, identifier_struct::input_wmes, pi_struct::next, wme_struct::next, NIL, pi_struct::prev, print(), remove_from_dll, remove_wme_from_wm(), and TRUE.

{
wme *temp;
/* --- a little bit of error checking --- */
if (!w) {
print (thisAgent, "Error: an input routine called remove_input_wme on a NULL wme.\n");
return FALSE;
}
for (temp=w->id->id.input_wmes; temp!=NIL; temp=temp->next)
if (temp==w) break;
if (!temp) {
print (thisAgent, "Error: an input routine called remove_input_wme on a wme that\n");
print (thisAgent, "isn't one of the input wmes currently in working memory.\n");
return FALSE;
}
/* Note: for efficiency, it might be better to use a hash table for the
above test, rather than scanning the linked list. We could have one
global hash table for all the input wmes in the system. */
/* --- go ahead and remove the wme --- */
remove_from_dll (w->id->id.input_wmes, w, next, prev);
/* REW: begin 09.15.96 */
if (w->gds) {
if (w->gds->goal != NIL) {
/* NOTE: the call to remove_wme_from_wm will take care
of checking if GDS should be removed */
}
}
/* REW: end 09.15.96 */
remove_wme_from_wm (thisAgent, w);
return TRUE;
}
void remove_output_function ( agent thisAgent,
const char *  name 
)

Definition at line 114 of file io.cpp.

References output_link_struct::cb, agent_struct::existing_output_links, output_link_struct::link_wme, pi_struct::next, output_link_struct::next, NIL, wme_struct::output_link, agent_struct::output_link_pool, OUTPUT_PHASE_CALLBACK, pi_struct::prev, remove_from_dll, soar_exists_callback_id(), soar_remove_callback(), and wme_remove_ref().

{
/* Remove indexing structures ... */
if (!cb) return;
for (ol=thisAgent->existing_output_links; ol!=NIL; ol=ol->next)
{
if (ol->cb == cb)
{
/* Remove ol entry */
ol->link_wme->output_link = NULL;
wme_remove_ref(thisAgent, ol->link_wme);
remove_from_dll(thisAgent->existing_output_links, ol, next, prev);
free_with_pool(&(thisAgent->output_link_pool), ol);
break;
}
}
}