#include "winlib.h" /*********************************************************** * Action Functions * ************************************************************ * Description: In this module, all action predicates have their corresponding function. The format of all the functions is the same: the first argument is the arity of the calling function, which is checked for correctness, the second argument is the pointer to the agent originating the action, and the third argument is the argument array of the calling action. * * * Created by: kave eshghi * * At: Tue Aug 18 14:56:35 1992 * ***********************************************************/ extern void write_window_pipe(term_ptr term); /* ============================================================ | inform() | |----------------------------------------------------------| | Desc : performs the inform action | | | |==========================================================| */ void inform(module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to inform"); exit(0); } else { int recepient=args[0]->functor; /* in the general case, we need to find the recepient by checking that it is local, if not ask the dispatcher */ send_message(INFORM,recepient,agent->agent_functor,args[1]); } } /* ============================================================ | request() | |----------------------------------------------------------| | Desc : performs the request action | | | |==========================================================| */ void request(module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to request"); } else { int recepient=args[0]->functor; /* in the general case, we need to find the recepient by checking that it is local, if not ask the despatcher */ send_message(REQUEST,recepient,agent->agent_functor,args[1]); } } /* ============================================================ | b_request() | |----------------------------------------------------------| | Desc : performs the request action | | | |==========================================================| */ void b_request(module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to b_request"); } else { int recepient=args[0]->functor; /* in the general case, we need to find the recepient by checking that it is local, if not ask the despatcher */ send_message(B_REQUEST,recepient,agent->agent_functor,args[1]); } } /* ============================================================ | b_inform() | |----------------------------------------------------------| | Desc : performs the request action | | | |==========================================================| */ void b_inform(module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to b_inform"); } else { int recepient=args[0]->functor; /* in the general case, we need to find the recepient by checking that it is local, if not ask the despatcher */ send_message(B_INFORM,recepient,agent->agent_functor,args[1]); } } /* ============================================================ | unrequest() | |----------------------------------------------------------| | Desc : performs the unrequest action | | | |==========================================================| */ void unrequest(module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to request"); } else { int recepient=args[0]->functor; /* in the general case, we need to find the recepient by checking that it is local, if not ask the despatcher */ send_message(UNREQUEST,recepient,agent->agent_functor,args[1]); } } /* ============================================================ | x_window() | |----------------------------------------------------------| | Desc : informs the user through the X-Window Interface | |==========================================================| */ void x_window(module_ptr agent,term_ptr term) { term_ptr *args=maketermarray(2); term_ptr transmit_term; args[0]=maketerm(NONVAR,agent->agent_functor,0,NULL,NULL); args[1]=copy_term(term); transmit_term=maketerm(TUPLE,0,2,NULL,args); write_window_pipe(transmit_term); free_term(transmit_term); } /* ============================================================ | m_message() | |----------------------------------------------------------| | Desc : sends a message to the specified module | |==========================================================| */ void m_message(module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to m_message\n"); } else { int i; int recepient=args[0]->functor; module_ptr r_agent=sym_table[recepient]->agent_ref; struct term *func=args[1]; for(i=0;ifunction_count&& r_agent->f_table[i].functor!=func->functor;i++); if (i==r_agent->function_count) { printf("error: non existing module function\n"); } else { (r_agent->f_table[i].funct)(func->arity, agent, func->argument_array, r_agent->f_table[i].data); } } } /* ============================================================ | c_module() | |----------------------------------------------------------| | Desc : sends a message to the generic handler of the specified module | |==========================================================| */ void c_module( module_ptr agent, term_ptr term) { int arity=term->arity; term_ptr *args=term->argument_array; if (arity!=2) { printf("error: wrong number of arguments to c_module\n"); } else { int i; int recepient=args[0]->functor; module_ptr r_agent=sym_table[recepient]->agent_ref; if (r_agent!=NULL) { struct term *func=args[1]; if (r_agent->generic==NULL) { printf("error: no generic function for module\n"); } else { (r_agent->generic)(agent, func); } } } } /* ============================================================ | end_window_process() | |----------------------------------------------------------| | Params : 1) an agent pointer | | 2) a term | | Desc : terminates the window and interpreter processes provided the action is originated by the window manager | | |==========================================================| */ void end_window_process(module_ptr agent, term_ptr term) { void EndWinProcess(); if (agent->agent_functor==X_MANAGER) EndWinProcess(agent); } /* ============================================================ | spy() | |----------------------------------------------------------| | Params : 1) | | 2) | | 3) | | Desc : sets up the spy field of a given proposition | | | | Returns: | |==========================================================| */ void spy(module_ptr agent, term_ptr term) { void spy_state(int agent_id, int window_id, int state); if (agent==NULL || term==NULL) return; else { /* the input term has the following format: */ /* spy(Agent, Proposition, Window_ID) */ int agent_id=term->argument_array[0]->functor; module_ptr target_agent= sym_table[agent_id]->agent_ref; term_ptr prop_term=term->argument_array[1]; int type=sym_table[prop_term->functor]->type; int action_type=sym_table[prop_term->functor]->action_type; if (target_agent==NULL) return; else { struct proposition *p=get_prop(target_agent, term->argument_array[1], type, action_type); int window_id=term->argument_array[2]->functor; p->spy_id=window_id; spy_state(agent_id,window_id,p->state); } } } /* read in the automatically generated action description file */ #include "actions.aux" int ActionCount=sizeof(action_preds)/sizeof(action_preds[0]);