liboaa.c File Reference

Contains the C implementation of the library for the Open Agent Architecture. More...

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/time.h>
#include <stdarg.h>
#include "libicl_private.h"
#include "libicl.h"
#include "libdb.h"
#include "libcom_tcp.h"
#include "liboaa.h"
#include "dictionary.h"
#include "testers.h"

Go to the source code of this file.

Defines

#define EXPORT_BORLAND
#define EXPORT_MSCPP
#define MAXHOSTNAMELEN   256

Functions

int oaa_SeqNumLessThan (int a, int b)
EXTERN int oaa_Init (int argc, char *argv[])
 Must be called to init oaa parameters, such as argv and agrc.
int oaa_compare_terms (void *t1, void *t2)
 Use unification to compare 2 terms, returning 0 for success and 1 for failure.
int oaa_assert_current_contexts (ICLTerm *id, ICLTerm *contexts)
 Record current contexts associated with a particular id.
int oaa_retrieve_current_contexts (ICLTerm *id, ICLTerm **contexts)
 Retrieve the context associated with id without removing the entry from the table.
int oaa_retrieve_nth_current_contexts (ICLTerm **id, ICLTerm **contexts, int n)
 Retrieve the nth id and contexts from the current_context table.
int oaa_retractall_current_contexts (ICLTerm *id)
 Retract all current contexts associated with a particular id.
int oaa_assert_delay (ICLTerm *id, ICLTerm *user_id)
 Assert the fact that the user has requested a delayed solution to a particular goal.
int oaa_retract_delay (ICLTerm *id, ICLTerm **user_id)
 Retract the fact that the user has requested a delayed solution to a particular goal and return the user id.
int oaa_assert_delay_table (ICLTerm *goal_id, ICLTerm *user_id, ICLTerm *full_goal, ICLTerm *solve_params, ICLTerm *all_params)
 Store the solution to a delayed goal.
int oaa_retract_delay_table (ICLTerm **goal_id, ICLTerm *user_id, ICLTerm **full_goal, ICLTerm **solve_params, ICLTerm **all_params)
 Remove and return the first solution found that has been stored with the key, user_id.
int oaa_assert_callback (ICLTerm *id, int(*user_callback)(ICLTerm *, ICLTerm *, ICLTerm *))
 Store a callback procedure associated with a particular id.
int oaa_retrieve_callback (ICLTerm *id, int(**user_callback)(ICLTerm *, ICLTerm *, ICLTerm *))
 Retrieves the callback procedure without retracting it.
int oaa_retract_callback (ICLTerm *id, int(*user_callback)(ICLTerm *, ICLTerm *, ICLTerm *))
 Retract the first callback associated with this id.
int oaa_retractall_callback (ICLTerm *id, ICLTerm **proc)
 Retract all callbacks associated with this id.
int oaa_assert_cache (ICLTerm *goal, ICLTerm *solutions)
 Store cached solutionsin the oaa_cache table.
int oaa_retrieve_cache (ICLTerm *goal, ICLTerm **solutions)
 Retrieves the cached solutions without retracting them.
int oaa_retractall_cache (ICLTerm *goal)
 Retract all cached solutions with goals that unify with the parameter.
int oaa_retrieve_all_cache (ICLTerm *goal, ICLTerm **solutions)
 Retrieves all the cached solutions without retracting them.
int oaa_retract_cache (ICLTerm *goal, ICLTerm **solutions)
 Retract the first cached solutions associated with this goal.
int oaa_assert_waiting_for (ICLTerm *id, ICLTerm *event_list)
 Store a list of events with an associated id.
int oaa_retrieve_waiting_for (ICLTerm *id, ICLTerm **event_list)
 Retrieves the event list for a particular id without retracting it.
int oaa_retrieve_all_waiting_for (ICLTerm *id, ICLTerm **event_list)
 Retrieves all event lists for a particular id term.
int oaa_retract_waiting_for (ICLTerm *id, ICLTerm **event_list)
 Retract the first event list associated with this id.
int oaa_assert_waiting_event (ICLTerm *event)
 Store an event.
int oaa_retrieve_all_waiting_events (ICLTerm **event_list)
 Retrieves all waiting events.
int oaa_retract_waiting_event (ICLTerm *event)
 Retract the first event list associated with this id.
ICLTermoaa_built_in_solvables ()
 Initializes and returns value for oaa_built_in_solvables_term.
EXTERN void icl_param_standard_form (ICLTerm *param, ICLListType **SList)
 Returns a copy of parameter in standard parameter form.
EXTERN int icl_param_default (ICLTerm *param, ICLTerm **result)
 Returns true if param unifies with a default parameter.
EXTERN void icl_perm_standard_form (ICLTerm *perm, ICLTerm **Standard)
 Returns a copy of perm in standard permission form.
EXTERN int icl_perm_default (ICLTerm *perm, ICLTerm **result)
 Returns true if perm unifies with a default permission.
EXTERN int icl_address_to_id (ICLTerm *inFullAddress, ICLTerm **result)
EXTERN int icl_standardize_address (ICLTerm *Addr, ICLTerm **StandardAddr)
 Standardizes an address or address list, Can only be used after oaa_Register() because of the reliance on com_GetInfo().
EXTERN int icl_standardize_solvables (ICLTerm *ShorthandSolvables, ICLTerm **StandardSolvables)
 Renders solvables in canonical form.
EXTERN int icl_readable_solvables (ICLTerm *StandardSolvables, ICLTerm **ShorthandSolvables)
 This is provided for use in "pretty-printing" solvables, in trace messages, etc.
EXTERN int icl_readable_solvable (ICLTerm *StandardSolvable, ICLTerm **ShorthandSolvable)
 Convert a single solvable into shorthand notation.
EXTERN int oaa_goal_in_solvables (ICLTerm *Goal, ICLTerm *Solvables, ICLTerm **MatchedSolvable)
 Determine whether Goal appears in Solvables, with appropriate Params and Perms for it to be called.
EXTERN int oaa_call_callback (char *callback_id, ICLTerm *goal, ICLTerm *params, ICLTerm *solutions)
EXTERN int oaa_sort_and_get_event (ICLTerm *EventList, int LowestPriority, ICLTerm **Event, ICLTerm **Params)
 Sort raw events by priority, choose the highest priority event or FirstIn if equal priority, extract event data and sender, and store the rest of events.
EXTERN int oaa_extract_event (ICLTerm *raw_event, ICLTerm **content, ICLTerm **params)
 Extract the content and parameters from an event term.
EXTERN int oaa_class (char *class)
 Return the class (leaf, node, or root) of the current agent.
EXTERN char * oaa_name_string (void)
EXTERN int oaa_Id (ICLTerm **my_id)
 Return the Id of the current agent.
EXTERN ICLTermperm_default_list ()
 Returns the list of default permissions.
EXTERN ICLTermparam_default_list ()
 Returns the list of default parameters.
EXTERN int oaa_priority_compare (ICLTerm *Elt1, ICLTerm *Elt2)
 Returns true if Elt1 and Elt2 should swap according to priority.
EXTERN int oaa_extract_event_param (ICLTerm *event, char *param, ICLTerm **result)
 Extract the content and a parameter value from an event term.
EXTERN int oaa_choose_event (int LowestPriority, ICLTerm *EventList, ICLTerm **Event)
 Extracts the first event from a list which has a HIGHER priority than the required lowest.
EXTERN int oaa_read_all_events (double TimeOut, ICLListType **Events, int *FlushPriority)
 Flush the communication event queue, reading ALL available events and returning a list of them, or empty list if none available.
EXTERN int oaa_select_event (double timeout, ICLTerm **event)
 If a positive timeout is defined, wait N seconds for an event to arrive.
EXTERN int oaa_flush_events (ICLTerm **original_events, int flush_priority)
 Flushes any events with a lower priority than the FlushPriority.
EXTERN int oaa_data_in_solvables (ICLTerm *Clause, ICLTerm *Solvables, ICLTerm *Perm, ICLTerm **MatchedSolvable)
 Determine whether (the Head of) Clause appears in Solvables, with appropriate Params and Perms for it to be read or written.
EXTERN int oaa_distribute_perms (ICLTerm *solvables, ICLTerm *common_perms, ICLTerm **new_solvables)
EXTERN int oaa_distribute_params (ICLTerm *solvables, ICLTerm *common_params, ICLTerm **new_solvables)
 Add common_params (CommonPerms) to the Params (Permissions) list of each solvable in solvables.
EXTERN int oaa_declare_aux (char *mode, ICLTerm *solvables, ICLTerm *params, ICLTerm **declared_solvables)
EXTERN int icl_standardize_addressee (ICLTerm *Addr, ICLTerm **StandardAddr)
 Standardizes an addressee.
EXTERN int oaa_address_to_comm_id (ICLTerm *inAddress, char **commId)
EXTERN char * new_goal_id ()
EXTERN char * new_trigger_id ()
EXTERN int select_elements (ICLTerm *list, int(*test_function)(ICLTerm *), ICLTerm **result)
 Selects all List elements for which Selector(element) succeeds.
EXTERN int oaa_handle_user_event (ICLTerm *event, ICLTerm *params, ICLTerm **solutions)
EXTERN int oaa_exec_event (ICLTerm *goal, ICLTerm *params, ICLTerm **solutions)
 Defines execution of events built into all agents.
EXTERN int oaa_cont_solve (ICLTerm *goal_id, ICLTerm *goal, ICLTerm *global_params, ICLTerm **solutions, ICLTerm **out_params)
 Post request for solutions, and if appropriate, poll until results are returned.
EXTERN ICLTermremove_element (ICLTerm *elt, ICLTerm *list, ICLTerm **rest)
 Creates a copy of the incoming list, where the first element that unifies with elt is missing.
EXTERN int oaa_cont_poll_until_all_events (ICLTerm *event_list, ICLTerm *event, ICLTerm *params, int priority, ICLTerm **solutions)
EXTERN int oaa_handle_ev_update_data (ICLTerm *goal, ICLTerm *params)
EXTERN int oaa_ComTraceMsg (char *format_string,...)
 If com trace mode is on, display message and arguments.
EXTERN int oaa_flush_notification (ICLTerm *raw_event)
 Given a raw event, grabs its real event and looks up whether a notification should be sent out regarding the event's cancellation due to a flush.
EXTERN int oaa_event_param (ICLTerm *event, ICLTerm *param)
 Extract a parameter from an event term.
EXTERN int oaa_get_flush_notify (ICLTerm *event, ICLTerm **notify_event)
 Records a list of events which require a return notification if the event is flushed.
EXTERN int oaa_translate_incoming_event (ICLTerm *raw_event_in, ICLTerm **raw_event_out)
EXTERN int oaa_unwrap_event (ICLTerm *in_event, char **connection_id, ICLTerm **out_event)
 Remove an event term from its communications wrapper (if any), and returns it in our standard internal form: 'timeout' OR event(Content, Params).
EXTERN int oaa_from_param (ICLTerm *event)
EXTERN int oaa_content_fac_id (ICLTerm *content, ICLTerm **id)
EXTERN int oaa_is_parent_fac_id (char *connection_id, ICLTerm **id)
EXTERN int oaa_is_oaa_id (char *connection_id, ICLTerm **id)
EXTERN int oaa_remove_data_owned_by (ICLTerm *id)
EXTERN int oaa_handle_ev_update_trigger (ICLTerm *goal, ICLTerm *params)
EXTERN int oaa_handle_ev_solve (ICLTerm *goal, ICLTerm *params, ICLTerm **solutions)
EXTERN int oaa_handle_ev_solved (ICLTerm *goal, ICLTerm *params)
EXTERN int oaa_add_data_local (ICLTerm *clause1, ICLTerm *params)
 Assert a clause for an agent's solvable.
EXTERN int oaa_remove_data_local (ICLTerm *clause1, ICLTerm *params)
 Retract a clause (or all clauses) from an agent's solvable.
EXTERN int oaa_replace_data_local (ICLTerm *clause1_in, ICLTerm *params)
 Replace one or more clauses from an agent's solvable.
EXTERN int oaa_Inform (ICLTerm *type_info, char *format_string, ICLTerm *args)
 Sends a typed message to interested agents.
EXTERN int oaa_solve_local (ICLTerm *full_goal, ICLTerm *params, ICLTerm **solutions)
EXTERN int oaa_turn_on_debug ()
EXTERN int oaa_turn_off_debug ()
EXTERN int predicate_skeleton (ICLTerm *goal, ICLTerm **skeleton)
EXTERN int oaa_is_waiting_for (ICLTerm *event)
 Check to see if the current event is something we are waiting for on a higher recursive level.
EXTERN int oaa_translate_outgoing_event (ICLTerm *event, ICLTerm *dest_id, char *commId, ICLTerm **new_event)
 Provides backwards compatibility by calling a hook (user:oaa_event_translation/7) that translates outgoing events to agents of other versions.
EXTERN int oaa_poll_until_event (ICLTerm *event, ICLTerm **solution)
 Block until requested event arrives in oaa_GetEvent().
EXTERN int oaa_declare_local (char *mode, ICLTerm *solvable0, ICLTerm *params, ICLTerm **returned_solvables)
EXTERN int solvables_to_be_added (ICLTerm *solvables, ICLTerm *current, ICLTerm **ok_solvables)
 Checks a list of solvables, to make sure they can legally be declared.
EXTERN int solvables_to_be_removed (ICLTerm *solvables, ICLTerm *current, ICLTerm **ok_solvables)
 Checks a list of solvables, to make sure they can legally be UNdeclared.
EXTERN int oaa_remove_solvables_data (ICLTerm *solvables)
 For each data solvable, remove all clauses belonging to it.
EXTERN int icl_subtract (ICLTerm *list1, ICLTerm *list2, ICLTerm **result)
 Implement the prolog predicate subtract/3.
EXTERN int replace_element (ICLTerm *elt, ICLTerm *old_list, ICLTerm *new_elt, ICLTerm **new_list)
 Replaces the element elt, if present in old_list, with the element new_elt.
EXTERN int oaa_update (char *mode, ICLTerm *clause, ICLTerm *initial_params, ICLTerm **out_params)
 Common code for oaa_AddData(), oaaRemoveData(), and oaa_ReplaceData().
EXTERN int oaa_retractall (ICLTerm *clause, ICLTerm *owner, ICLTerm *callback)
EXTERN int retract_all (ICLTerm *clause)
 Remove all clauses matching Clause1 Always succeeds.
EXTERN int oaa_data_owner (ICLTerm *params, ICLTerm **owner)
 Determine data ownership from the available params.
EXTERN int oaa_asserta (ICLTerm *clause, ICLTerm *owner, ICLTerm *callback)
EXTERN int oaa_assertz (ICLTerm *clause, ICLTerm *owner, ICLTerm *callback)
EXTERN int oaa_retract (ICLTerm *clause, ICLTerm *owner, ICLTerm *callback)
EXTERN int oaa_replace_all (ICLTerm *clause1, ICLTerm *clause2, ICLTerm *owner, ICLTerm *callback)
EXTERN int oaa_poll_until_event_priority (ICLTerm *event, int priority, ICLTerm **solutions)
EXTERN int oaa_poll_until_all_events (ICLTerm *event_list, int priority, ICLTerm **solutions)
 Block until all requested events arrive.
EXTERN int oaa_grab_waiting_event (ICLTerm *event_list, ICLTerm **event)
 If one of the delayed events is in the EventList that we are waiting for, return this event and remove from delayed list.
EXTERN int replace_all (ICLTerm *clause1, ICLTerm *clause2)
 Replaces all clauses matching clause1 with clause2.
char * getlocalhostname (void)
 * Retrieve local host name.
EXPORT_MSCPP int EXPORT_BORLAND oaa_Register (char *ConnectionId, char *AgentName, ICLTerm *Solvables)
 Once a comm link is established, either as a client to a Facilitator or as a server for other agents, oaa_Register will setup and registration information for this agent.
EXPORT_MSCPP void EXPORT_BORLAND oaa_Ready (int ShouldPrint)
 Changes the agent's 'open' status to 'ready', indicating that the agent is now ready to receive message.
EXPORT_MSCPP int EXPORT_BORLAND icl_BuiltIn (ICLTerm *goal)
 Test whether an expression is an ICL built-in goal.
int icl_compound_goal (ICLTerm *goal)
 Test whether an expression is an ICL compound goal.
EXPORT_MSCPP int EXPORT_BORLAND icl_BasicGoal (ICLTerm *goal)
 Test whether an expression is an ICL basic (non-compound) goal; that is, just a functor with 0 or more arguments.
EXPORT_MSCPP int EXPORT_BORLAND icl_GoalComponents (ICLTerm *fullgoal, ICLTerm **address, ICLTerm **goal, ICLTerm **param)
 Assemble, disassemble, or match against the top-level components of an ICL goal.
int icl_standardize_perms (ICLTerm *Perms, int KeepDefaults, ICLTerm **Standardized)
 Standardizes a permissions list, removing defaults if requested.
int icl_standardize_params (ICLTerm *Params, int KeepDefaults, ICLTerm **Standardized)
 Standardizes a permissions list, removing defaults if requested.
int icl_param_arg (char *param, ICLTerm *value, ICLTerm *paramlist, ICLTerm **result)
 Searches for a parameter in a parameter list.
EXPORT_MSCPP int EXPORT_BORLAND icl_GetParamValue (ICLTerm *Param, ICLTerm *ParamList, ICLTerm **Result)
 To get or test the value of a parameter that has a default, it is best to call icl_GetParamValue().
EXPORT_MSCPP int EXPORT_BORLAND icl_GetPermValue (ICLTerm *Perm, ICLTerm *PermList, ICLTerm **Result)
 To get or test the value of a parameter that has a default, it is best to call icl_GetPermValue().
int icl_name (ICLTerm *term)
 Returns TRUE if Term is a valid address name Any atom except for "parent", "self" or "facilitator" may be a name.
int icl_true_id (ICLTerm *term, ICLTerm **Id)
 Returns canonical term for a lowest-level id.
EXPORT_MSCPP int EXPORT_BORLAND icl_ConvertSolvables (int toStandard, ICLTerm *ShorthandSolvables, ICLTerm **StandardSolvables)
 Convert between shorthand and standard forms of solvables list.
int icl_standardize_solvable (ICLTerm *Shorthand, ICLTerm **Standard)
int icl_minimally_instantiate_solvable (ICLTerm *Shorthand, ICLTerm **Minimal)
 Convert from shorthand (or standard form) to minimally instantiated solvables list.
int icl_minimally_instantiate_solvables (ICLTerm *ShorthandSolvables, ICLTerm **MinimalSolvables)
 Loop to call minimally_instantiate_solvable.
int oaa_goal_matches_solvables (ICLTerm *Goal, ICLTerm *Solvables, ICLTerm **RealGoal, ICLTerm **RealMatched)
 Determine whether a call to Goal is handled by the agent with these Solvables.
int oaa_data_matches_solvables (ICLTerm *Clause, ICLTerm *Solvables, ICLTerm *Perm, ICLTerm **RealClause, ICLTerm **RealMatched)
 Determine whether Clause can be read or written by the agent with these Solvables, and return the "real" form of the clause that takes synonyms into account.
EXPORT_MSCPP void EXPORT_BORLAND oaa_MainLoop (int ShouldPrint)
 The main event loop for the application.
EXPORT_MSCPP void EXPORT_BORLAND oaa_ProcessAllEvents ()
 To be called when the application that uses OAA has its own event loop.
EXPORT_MSCPP void EXPORT_BORLAND oaa_ProcessEvent (ICLTerm *Event, ICLTerm *Params)
 Interprets an incoming event.
EXPORT_MSCPP void EXPORT_BORLAND oaa_SetTimeout (double NSecs)
 Sets the timeout value used by oaa_GetEvent().
EXPORT_MSCPP void EXPORT_BORLAND oaa_GetEvent (ICLTerm **Event, ICLTerm **Params, int LowestPriority)
 Return the next event to execute.
int oaa_ValidateEvent (ICLTerm *E, ICLTerm **OkEvent)
 Check that an incoming lowlevel event should be processed.
int oaa_Interpret (ICLTerm *goal, ICLTerm *params, ICLTerm **solutions)
 Executes an incoming event Implements a simple meta-interpreter for executing complex goals.
int oaa_find_all_contexts (ICLTerm *params, ICLTerm **contexts)
ICLTermvalid_oaa_solvables ()
int passes_tests (ICLTerm *params)
int oaa_DelaySolution (ICLTerm *id)
 Requests that the current AppDoEvent not return solutions to the current goal until a later time.
int oaa_ReturnDelayedSolutions (ICLTerm *id, ICLTerm *solution_list)
 Returns the list of solutions for a delayed request.
int oaa_AddDelayedContextParams (ICLTerm *id, ICLTerm *params, ICLTerm **new_params)
 When a goal is delayed using oaa_DelaySolution(), incoming context parameters from the original request can not be automatically concatenated to outgoing oaa_Solve() requests.
int oaa_PostEvent (ICLTerm *contents, ICLTerm *params)
 Sends a low-level event to another agent.
int oaa_convert_id_to_comm_id (ICLTerm *id, ICLTerm **cid)
int oaa_LibraryVersion (ICLTerm **version)
int oaa_Version (ICLTerm *agent_id, ICLTerm **language, ICLTerm **version)
 Lookup the language and library version number for an agent.
int oaa_CanSolve (ICLTerm *goal, ICLTerm **kslist)
 Asks the Facilitator for a list of agents which could solve a Goal.
int oaa_Ping (ICLTerm *agent_addr, double time_limit, double *total_response_time)
 Tests whether a given agent is currently responding to requests.
int oaa_Declare (ICLTerm *solvable, ICLTerm *initial_common_perms, ICLTerm *initial_common_params, ICLTerm *initial_params, ICLTerm **declared_solvables)
 Declare solvables for a client or facilitator, and inform the parent if appropriate.
int oaa_DeclareData (ICLTerm *solv, ICLTerm *params, ICLTerm **declared_solvs)
 Declare data solvables for an agent.
int oaa_Undeclare (ICLTerm *solvable, ICLTerm *initial_params, ICLTerm **undeclared_solvables)
 Remove solvables from a client or facilitator, and inform the parent if appropriate.
int oaa_Redeclare (ICLTerm *initial_solvable, ICLTerm *initial_new_solvable, ICLTerm *initial_params)
 Replace a solvable on a client or facilitator, and inform the parent if appropriate.
int oaa_public_solvable (ICLTerm *solvable)
int oaa_data_solvable (ICLTerm *solvable)
int oaa_AddData (ICLTerm *clause, ICLTerm *in_params, ICLTerm **out_params)
 Add a new clause for a DATA solvable (locally and/or remotely).
int oaa_RemoveData (ICLTerm *clause, ICLTerm *in_params, ICLTerm **out_params)
int oaa_ReplaceData (ICLTerm *clause1, ICLTerm *clause2, ICLTerm *in_params, ICLTerm **out_params)
 Change a predicate value to a new one.
int icl_replace_param_value (ICLTerm *param, ICLTerm *param_list)
 If param unifies with an element of param list, replace the element with the unified result.
int asserta (ICLTerm *clause)
int assertz (ICLTerm *clause)
int retract (ICLTerm *clause)
int asserta_ref (ICLTerm *clause, ICLTerm **ref)
int assertz_ref (ICLTerm *clause, ICLTerm **ref)
int ref_for_clause (ICLTerm *clause, ICLTerm **ref)
int erase_ref (ICLTerm *clause, ICLTerm *ref)
int oaa_Address (char *connectionId, ICLTerm *Type, ICLTerm **myAddress)
 Returns (one of more) Addresses for this agent.
int oaa_PrimaryAddress (ICLTerm **primaryAddress)
 Returns the primary address for this agent in new memory.
int oaa_PrimaryId (ICLTerm **primaryId)
 Returns the primary id for this agent.
int oaa_Name (ICLTerm **my_name)
 Return the name of the current agent.
int oaa_Solve (ICLTerm *goal, ICLTerm *initial_params, ICLTerm **out_params, ICLTerm **solutions)
 Sends work or information requests to distributed agents, brokered by the Facilitator agent.
int oaa_InCache (ICLTerm *goal, ICLTerm **solutions)
 Retrieve solutions from the cache if the goal we are asking for is properly contained in the cache (check subsumption).
int oaa_AddToCache (ICLTerm *goal, ICLTerm *solutions)
 Add each solution to goal one at a time so we can retrieve solutions later using findall.
int oaa_ClearCache ()
 Clear the cache.
int oaa_RegisterCallback (char *callback_id, int(*callback_proc)(ICLTerm *, ICLTerm *, ICLTerm *))
 Declare what procedures should be used for callbacks.
int oaa_GetCallback (char *callback_id, int(**callback_proc)(ICLTerm *, ICLTerm *, ICLTerm *))
int oaa_TraceMsg (char *format_string,...)
 If trace mode is on, display message and arguments.
EXPORT_MSCPP int EXPORT_BORLAND memberchk (ICLTerm *Param, ICLTerm *ParamList)
 Searches for a parameter in a list.
EXPORT_MSCPP int EXPORT_BORLAND oaa_Connect (char *ConnectionId, ICLTerm *Address, char *InitialAgentName, ICLTerm *Params)
 Connect and handshake with the agent listening on Address, or, if Address is a variable, allow com_Connect() to find the address.
EXPORT_MSCPP int EXPORT_BORLAND oaa_Disconnect (char *ConnectionId, ICLTerm *Params)
 Disconnect from the given comm link, or from all links if the given CommunicationID is NULL.
EXPORT_MSCPP int EXPORT_BORLAND oaa_SetupCommunication (char *InitialAgentName)
 Convenience function for connecting to a facilitator and, if oaa_listen can be resolved, for opening server listening sockets for to handle direct_connect requests.
int oaa_version_atleast (int major, int minor, int level, ICLTerm *toCheck)
 Check if the given version list is at least [major,minor,level].
EXPORT_MSCPP int EXPORT_BORLAND oaa_SupportsSequenceNumbers (char *connectionId)

Variables

char const * oaa_library_version_str = "[2,3,2]"
ICLDatabasecommdb
ICLTermoaa_saved_events = NULL
int oaa_argc = 0
char ** oaa_argv = NULL


Detailed Description

Contains the C implementation of the library for the Open Agent Architecture.

Definition in file liboaa.c.


Define Documentation

#define EXPORT_BORLAND

Definition at line 31 of file liboaa.c.

#define EXPORT_MSCPP

Definition at line 36 of file liboaa.c.

#define MAXHOSTNAMELEN   256

Definition at line 77 of file liboaa.c.


Function Documentation

int asserta ( ICLTerm clause  ) 

Definition at line 5800 of file liboaa.c.

int asserta_ref ( ICLTerm clause,
ICLTerm **  ref 
)

Definition at line 5847 of file liboaa.c.

int assertz ( ICLTerm clause  ) 

Definition at line 5814 of file liboaa.c.

int assertz_ref ( ICLTerm clause,
ICLTerm **  ref 
)

Definition at line 5855 of file liboaa.c.

int erase_ref ( ICLTerm clause,
ICLTerm ref 
)

Definition at line 5873 of file liboaa.c.

char* getlocalhostname ( void   ) 

* Retrieve local host name.

returns: NULL if can't calculate host

Definition at line 780 of file liboaa.c.

int icl_address_to_id ( ICLTerm inFullAddress,
ICLTerm **  result 
)

Definition at line 6376 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND icl_BasicGoal ( ICLTerm goal  ) 

Test whether an expression is an ICL basic (non-compound) goal; that is, just a functor with 0 or more arguments.

Remarks:

Definition at line 1038 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND icl_BuiltIn ( ICLTerm goal  ) 

Test whether an expression is an ICL built-in goal.

Remarks:

Definition at line 978 of file liboaa.c.

int icl_compound_goal ( ICLTerm goal  ) 

Test whether an expression is an ICL compound goal.

Definition at line 1007 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND icl_ConvertSolvables ( int  toStandard,
ICLTerm ShorthandSolvables,
ICLTerm **  StandardSolvables 
)

Convert between shorthand and standard forms of solvables list.

Remarks:

Note: in the C version, an additional arg (toStandard) is added to distinguish between the two calling conventions:

    icl_ConvertSolvables(TRUE, +ShorthandSolvables, -StandardSolvables).

    icl_ConvertSolvables(FALSE, +StandardSolvables, -ShorthandSolvables).
 

Definition at line 1818 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND icl_GetParamValue ( ICLTerm Param,
ICLTerm ParamList,
ICLTerm **  Result 
)

To get or test the value of a parameter that has a default, it is best to call icl_GetParamValue().

For a parameter that has no default, you can use icl_GetParamValue() OR memberchk().

Remarks:

Definition at line 1381 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND icl_GetPermValue ( ICLTerm Perm,
ICLTerm PermList,
ICLTerm **  Result 
)

To get or test the value of a parameter that has a default, it is best to call icl_GetPermValue().

For a parameter that has no default, you can use icl_GetPermValue() OR memberchk().

Remarks:

Definition at line 1421 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND icl_GoalComponents ( ICLTerm fullgoal,
ICLTerm **  address,
ICLTerm **  goal,
ICLTerm **  param 
)

Assemble, disassemble, or match against the top-level components of an ICL goal.

Remarks:

Note: This function allocates memory for the three return values.

Definition at line 1062 of file liboaa.c.

int icl_minimally_instantiate_solvable ( ICLTerm Shorthand,
ICLTerm **  Minimal 
)

Convert from shorthand (or standard form) to minimally instantiated solvables list.

Remarks:

Definition at line 2019 of file liboaa.c.

int icl_minimally_instantiate_solvables ( ICLTerm ShorthandSolvables,
ICLTerm **  MinimalSolvables 
)

Loop to call minimally_instantiate_solvable.

Definition at line 2068 of file liboaa.c.

int icl_name ( ICLTerm term  ) 

Returns TRUE if Term is a valid address name Any atom except for "parent", "self" or "facilitator" may be a name.

Definition at line 1514 of file liboaa.c.

int icl_param_arg ( char *  param,
ICLTerm value,
ICLTerm paramlist,
ICLTerm **  result 
)

Searches for a parameter in a parameter list.

Just like icl_ParamValue() except it returns the argument of the result instead of the whole unified term. Returns a newly allocated copy.

Definition at line 1353 of file liboaa.c.

int icl_param_default ( ICLTerm param,
ICLTerm **  result 
)

Returns true if param unifies with a default parameter.

result may be NULL (test only) or can return the result of the unification.

Definition at line 1340 of file liboaa.c.

void icl_param_standard_form ( ICLTerm param,
ICLListType **  SList 
)

Returns a copy of parameter in standard parameter form.

Definition at line 1286 of file liboaa.c.

int icl_perm_default ( ICLTerm perm,
ICLTerm **  result 
)

Returns true if perm unifies with a default permission.

result may be NULL (test only) or can return the result of the unification.

Definition at line 1203 of file liboaa.c.

void icl_perm_standard_form ( ICLTerm perm,
ICLTerm **  Standard 
)

Returns a copy of perm in standard permission form.

Definition at line 1171 of file liboaa.c.

int icl_readable_solvable ( ICLTerm StandardSolvable,
ICLTerm **  ShorthandSolvable 
)

Convert a single solvable into shorthand notation.

Definition at line 1939 of file liboaa.c.

int icl_readable_solvables ( ICLTerm StandardSolvables,
ICLTerm **  ShorthandSolvables 
)

This is provided for use in "pretty-printing" solvables, in trace messages, etc.

Definition at line 1972 of file liboaa.c.

int icl_replace_param_value ( ICLTerm param,
ICLTerm param_list 
)

If param unifies with an element of param list, replace the element with the unified result.

Does *not* replace default values.

Definition at line 5614 of file liboaa.c.

int icl_standardize_address ( ICLTerm Addr,
ICLTerm **  StandardAddr 
)

Standardizes an address or address list, Can only be used after oaa_Register() because of the reliance on com_GetInfo().

Definition at line 1713 of file liboaa.c.

int icl_standardize_addressee ( ICLTerm Addr,
ICLTerm **  StandardAddr 
)

Standardizes an addressee.

Can only be used after oaa_Register() because of the reliance on com_GetInfo().

Definition at line 1575 of file liboaa.c.

int icl_standardize_params ( ICLTerm Params,
int  KeepDefaults,
ICLTerm **  Standardized 
)

Standardizes a permissions list, removing defaults if requested.

Normally there's no need to keep the default value of a param, but there are exceptional situations. If KeepDefaults is true, default values are kept. Standardized is all newly allocated stuff.

Definition at line 1219 of file liboaa.c.

int icl_standardize_perms ( ICLTerm Perms,
int  KeepDefaults,
ICLTerm **  Standardized 
)

Standardizes a permissions list, removing defaults if requested.

Normally there's no need to keep the default value of a param, but there are exceptional situations. If KeepDefaults is true, default values are kept.

Definition at line 1130 of file liboaa.c.

int icl_standardize_solvable ( ICLTerm Shorthand,
ICLTerm **  Standard 
)

Definition at line 1830 of file liboaa.c.

int icl_standardize_solvables ( ICLTerm ShorthandSolvables,
ICLTerm **  StandardSolvables 
)

Renders solvables in canonical form.

Definition at line 1897 of file liboaa.c.

int icl_subtract ( ICLTerm list1,
ICLTerm list2,
ICLTerm **  result 
)

Implement the prolog predicate subtract/3.

Result contains the elements of list1 that are not in list2.

Definition at line 5317 of file liboaa.c.

int icl_true_id ( ICLTerm term,
ICLTerm **  Id 
)

Returns canonical term for a lowest-level id.

f fails, doesn't change result Id.

Definition at line 1531 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND memberchk ( ICLTerm Param,
ICLTerm ParamList 
)

Searches for a parameter in a list.

Parameters:
Param A term to search for
ParamList A list to search in
Returns:
TRUE if Param is contained in ParamList

Definition at line 7966 of file liboaa.c.

char * new_goal_id (  ) 

Definition at line 7387 of file liboaa.c.

char * new_trigger_id (  ) 

Definition at line 7416 of file liboaa.c.

int oaa_add_data_local ( ICLTerm clause1,
ICLTerm params 
)

Assert a clause for an agent's solvable.

This performs the local processing needed for calls to oaa_AddData(), and ev_update(add, ...) requests. Application code should not call oaa_add_data_local() directly, but rather oaa_AddData() with address(self).

See also:
oaa_AddData.

Definition at line 5896 of file liboaa.c.

int oaa_AddData ( ICLTerm clause,
ICLTerm in_params,
ICLTerm **  out_params 
)

Add a new clause for a DATA solvable (locally and/or remotely).

Params:

Remarks:

Definition at line 5517 of file liboaa.c.

int oaa_AddDelayedContextParams ( ICLTerm id,
ICLTerm params,
ICLTerm **  new_params 
)

When a goal is delayed using oaa_DelaySolution(), incoming context parameters from the original request can not be automatically concatenated to outgoing oaa_Solve() requests.

Since an agent can manage multiple delayed goals at the same time, liboaa doesn't know the correct context for the outgoing oaa_Solve() without explicit direction from the programmer. Hence, an agent programmer who wants to call oaa_Solve() during a delayed goal is expected to use this function to add the saved contexts for the delayed goal to his/her outgoing oaa_Solve() parameters.

Parameters:
id an Id which will be used to later match solutions to request
params parameters for solve goal
new_params params augmented by saved contexts; points to newly allocated memory--remember to call icl_Free(*new_params)

Definition at line 4318 of file liboaa.c.

int oaa_Address ( char *  connectionId,
ICLTerm Type,
ICLTerm **  myAddress 
)

Returns (one of more) Addresses for this agent.

If ConnectionId is ground, returns a single Address, relative to that connection. If connection Id is not null, the function returns a single answer for this specific connection. If the connection bound to the incoming Id is not valid, (not actually connected), returns "no_address" and prints out a warning. If connection Id is null, returns all the addresses of the currently valid connections.

Definition at line 6274 of file liboaa.c.

int oaa_address_to_comm_id ( ICLTerm inAddress,
char **  commId 
)

Definition at line 4352 of file liboaa.c.

int oaa_AddToCache ( ICLTerm goal,
ICLTerm solutions 
)

Add each solution to goal one at a time so we can retrieve solutions later using findall.

Definition at line 7091 of file liboaa.c.

int oaa_assert_cache ( ICLTerm goal,
ICLTerm solutions 
)

Store cached solutionsin the oaa_cache table.

Definition at line 437 of file liboaa.c.

int oaa_assert_callback ( ICLTerm id,
int(*)(ICLTerm *, ICLTerm *, ICLTerm *)  user_callback 
)

Store a callback procedure associated with a particular id.

Definition at line 368 of file liboaa.c.

int oaa_assert_current_contexts ( ICLTerm id,
ICLTerm contexts 
)

Record current contexts associated with a particular id.

This function is specific to the C version and replaces the the predicate asserta(oaa_current_contexts(ID, Contexts)).

Definition at line 223 of file liboaa.c.

int oaa_assert_delay ( ICLTerm id,
ICLTerm user_id 
)

Assert the fact that the user has requested a delayed solution to a particular goal.

Definition at line 293 of file liboaa.c.

int oaa_assert_delay_table ( ICLTerm goal_id,
ICLTerm user_id,
ICLTerm full_goal,
ICLTerm solve_params,
ICLTerm all_params 
)

Store the solution to a delayed goal.

Definition at line 317 of file liboaa.c.

int oaa_assert_waiting_event ( ICLTerm event  ) 

Store an event.

Definition at line 585 of file liboaa.c.

int oaa_assert_waiting_for ( ICLTerm id,
ICLTerm event_list 
)

Store a list of events with an associated id.

Definition at line 522 of file liboaa.c.

int oaa_asserta ( ICLTerm clause,
ICLTerm owner,
ICLTerm callback 
)

Definition at line 6471 of file liboaa.c.

int oaa_assertz ( ICLTerm clause,
ICLTerm owner,
ICLTerm callback 
)

Definition at line 6497 of file liboaa.c.

ICLTerm* oaa_built_in_solvables (  ) 

Initializes and returns value for oaa_built_in_solvables_term.

Definition at line 629 of file liboaa.c.

int oaa_call_callback ( char *  callback_id,
ICLTerm goal,
ICLTerm params,
ICLTerm solutions 
)

Definition at line 7359 of file liboaa.c.

int oaa_CanSolve ( ICLTerm goal,
ICLTerm **  kslist 
)

Asks the Facilitator for a list of agents which could solve a Goal.

Definition at line 4657 of file liboaa.c.

int oaa_choose_event ( int  LowestPriority,
ICLTerm EventList,
ICLTerm **  Event 
)

Extracts the first event from a list which has a HIGHER priority than the required lowest.

Fails if none found. If event found, destructively removed from list.

Definition at line 2815 of file liboaa.c.

int oaa_class ( char *  class  ) 

Return the class (leaf, node, or root) of the current agent.

Definition at line 6440 of file liboaa.c.

int oaa_ClearCache (  ) 

Clear the cache.

Definition at line 7108 of file liboaa.c.

int oaa_compare_terms ( void *  t1,
void *  t2 
)

Use unification to compare 2 terms, returning 0 for success and 1 for failure.

Used for qsort-like comparison.

Definition at line 201 of file liboaa.c.

int oaa_ComTraceMsg ( char *  format_string,
  ... 
)

If com trace mode is on, display message and arguments.

Definition at line 7451 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND oaa_Connect ( char *  ConnectionId,
ICLTerm Address,
char *  InitialAgentName,
ICLTerm Params 
)

Connect and handshake with the agent listening on Address, or, if Address is a variable, allow com_Connect() to find the address.

See also:
com_Connect()

Definition at line 8009 of file liboaa.c.

int oaa_cont_poll_until_all_events ( ICLTerm event_list,
ICLTerm event,
ICLTerm params,
int  priority,
ICLTerm **  solutions 
)

Definition at line 7241 of file liboaa.c.

int oaa_cont_solve ( ICLTerm goal_id,
ICLTerm goal,
ICLTerm global_params,
ICLTerm **  solutions,
ICLTerm **  out_params 
)

Post request for solutions, and if appropriate, poll until results are returned.

Definition at line 6995 of file liboaa.c.

int oaa_content_fac_id ( ICLTerm content,
ICLTerm **  id 
)

Definition at line 3450 of file liboaa.c.

int oaa_convert_id_to_comm_id ( ICLTerm id,
ICLTerm **  cid 
)

Definition at line 4453 of file liboaa.c.

int oaa_data_in_solvables ( ICLTerm Clause,
ICLTerm Solvables,
ICLTerm Perm,
ICLTerm **  MatchedSolvable 
)

Determine whether (the Head of) Clause appears in Solvables, with appropriate Params and Perms for it to be read or written.

Should not be called directly; only by oaa_data_matches_solvables.

Parameters:
Clause must be non-compound (basic) to match: no address, no params, no subClauses.
Solvables must be in standard form.

Definition at line 2398 of file liboaa.c.

int oaa_data_matches_solvables ( ICLTerm Clause,
ICLTerm Solvables,
ICLTerm Perm,
ICLTerm **  RealClause,
ICLTerm **  RealMatched 
)

Determine whether Clause can be read or written by the agent with these Solvables, and return the "real" form of the clause that takes synonyms into account.

Parameters:
Clause must be non-compound (basic) to match: no address, no params, no subClauses.
Solvables must be in standard form.
Perm is 'read' or 'write'.
RealClause is what should actually be used (asserted, retracted, replaced).
RealMatched is the solvable record corresponding to RealClause.
Remarks:

Definition at line 2322 of file liboaa.c.

int oaa_data_owner ( ICLTerm params,
ICLTerm **  owner 
)

Determine data ownership from the available params.

Definition at line 6216 of file liboaa.c.

int oaa_data_solvable ( ICLTerm solvable  ) 

Definition at line 5133 of file liboaa.c.

int oaa_Declare ( ICLTerm solvable,
ICLTerm initial_common_perms,
ICLTerm initial_common_params,
ICLTerm initial_params,
ICLTerm **  declared_solvables 
)

Declare solvables for a client or facilitator, and inform the parent if appropriate.

Parameters:
solvable a single solvable or a list of solvables, in shorthand or standard form
initial_common_perms permissions to be distributed to each solvable in solvable. This is purely for programming convenience. See comments for icl_ConvertSolvables() for possible values, and solvables documentation for their meanings.
initial_common_params params to be distributed to each solvable in Solvables. This is purely for programming convenience. See comments for icl_ConvertSolvables() for possible values, and solvables documentation for their meanings.
declared_solvables returns a list, in standard form, of all solvables successfully declared.
Params:

Remarks

Definition at line 4765 of file liboaa.c.

int oaa_declare_aux ( char *  mode,
ICLTerm solvables,
ICLTerm params,
ICLTerm **  declared_solvables 
)

Definition at line 4979 of file liboaa.c.

int oaa_declare_local ( char *  mode,
ICLTerm solvable0,
ICLTerm params,
ICLTerm **  returned_solvables 
)

Definition at line 5170 of file liboaa.c.

int oaa_DeclareData ( ICLTerm solv,
ICLTerm params,
ICLTerm **  declared_solvs 
)

Declare data solvables for an agent.

Definition at line 4823 of file liboaa.c.

int oaa_DelaySolution ( ICLTerm id  ) 

Requests that the current AppDoEvent not return solutions to the current goal until a later time.

Parameters:
id an Id which will be used to later match solutions to request

Definition at line 4203 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND oaa_Disconnect ( char *  ConnectionId,
ICLTerm Params 
)

Disconnect from the given comm link, or from all links if the given CommunicationID is NULL.

Parameters:
ConnectionId the link to disconnect; if NULL, disconnect from all links
Params for future enhancements; currently ignored.
Returns:
TRUE if successful, FALSE otherwise.

Definition at line 8243 of file liboaa.c.

int oaa_distribute_params ( ICLTerm solvables,
ICLTerm common_params,
ICLTerm **  new_solvables 
)

Add common_params (CommonPerms) to the Params (Permissions) list of each solvable in solvables.

Parameters:
solvables a solvables list, in standard form.

Definition at line 5343 of file liboaa.c.

int oaa_distribute_perms ( ICLTerm solvables,
ICLTerm common_perms,
ICLTerm **  new_solvables 
)

Definition at line 5372 of file liboaa.c.

int oaa_event_param ( ICLTerm event,
ICLTerm param 
)

Extract a parameter from an event term.

This FAILS if the parameter isn't present (unlike oaa_extract_event_param(). Does not look for default values, really behaves like memberchk() or icl_ParamValue().

Definition at line 3578 of file liboaa.c.

int oaa_exec_event ( ICLTerm goal,
ICLTerm params,
ICLTerm **  solutions 
)

Defines execution of events built into all agents.

Goals that can't be handled by oaa_exec_event are passed to the user-declared app_do_event callback, if present.

Definition at line 3684 of file liboaa.c.

int oaa_extract_event ( ICLTerm raw_event,
ICLTerm **  content,
ICLTerm **  params 
)

Extract the content and parameters from an event term.

Always succeeds. The content part of the term is often (loosely) called the Event. Note: Allocates memory for **content and **params.

Definition at line 3552 of file liboaa.c.

int oaa_extract_event_param ( ICLTerm event,
char *  param,
ICLTerm **  result 
)

Extract the content and a parameter value from an event term.

Always succeeds, unless you ask for a param that has no default value. The content part of the term is often (loosely) called the Event. Note: return icl struct : param(X).

Definition at line 3595 of file liboaa.c.

int oaa_find_all_contexts ( ICLTerm params,
ICLTerm **  contexts 
)

Definition at line 3940 of file liboaa.c.

int oaa_flush_events ( ICLTerm **  original_events,
int  flush_priority 
)

Flushes any events with a lower priority than the FlushPriority.

Definition at line 3027 of file liboaa.c.

int oaa_flush_notification ( ICLTerm raw_event  ) 

Given a raw event, grabs its real event and looks up whether a notification should be sent out regarding the event's cancellation due to a flush.

Definition at line 3075 of file liboaa.c.

int oaa_from_param ( ICLTerm event  ) 

Definition at line 3434 of file liboaa.c.

int oaa_get_flush_notify ( ICLTerm event,
ICLTerm **  notify_event 
)

Records a list of events which require a return notification if the event is flushed.

Currently, only the ev_solve() event returns a message; all other events are flushed without notification.

Definition at line 3096 of file liboaa.c.

int oaa_GetCallback ( char *  callback_id,
int(**)(ICLTerm *, ICLTerm *, ICLTerm *)  callback_proc 
)

Definition at line 7352 of file liboaa.c.

EXPORT_MSCPP void EXPORT_BORLAND oaa_GetEvent ( ICLTerm **  Event,
ICLTerm **  Params,
int  LowestPriority 
)

Return the next event to execute.

Remarks:

Definition at line 2686 of file liboaa.c.

int oaa_goal_in_solvables ( ICLTerm Goal,
ICLTerm Solvables,
ICLTerm **  MatchedSolvable 
)

Determine whether Goal appears in Solvables, with appropriate Params and Perms for it to be called.

Parameters:
Goal must be non-compound (basic) to match: no address, no params, no subgoals
Solvables must be in standard form
Remarks:

Definition at line 2204 of file liboaa.c.

int oaa_goal_matches_solvables ( ICLTerm Goal,
ICLTerm Solvables,
ICLTerm **  RealGoal,
ICLTerm **  RealMatched 
)

Determine whether a call to Goal is handled by the agent with these Solvables.

Parameters:
Goal must be non-compound (basic) to match: no address, no params, no subgoals.
Solvables must be in standard form.
RealGoal is what should actually be called, after taking synonyms into account. (In short form)
RealMatched is the solvable record corresponding to RealGoal (In canonical form)
Remarks:

Definition at line 2137 of file liboaa.c.

int oaa_grab_waiting_event ( ICLTerm event_list,
ICLTerm **  event 
)

If one of the delayed events is in the EventList that we are waiting for, return this event and remove from delayed list.

Definition at line 7623 of file liboaa.c.

int oaa_handle_ev_solve ( ICLTerm goal,
ICLTerm params,
ICLTerm **  solutions 
)

Definition at line 3991 of file liboaa.c.

int oaa_handle_ev_solved ( ICLTerm goal,
ICLTerm params 
)

Definition at line 3967 of file liboaa.c.

int oaa_handle_ev_update_data ( ICLTerm goal,
ICLTerm params 
)

Definition at line 3799 of file liboaa.c.

int oaa_handle_ev_update_trigger ( ICLTerm goal,
ICLTerm params 
)

Definition at line 3869 of file liboaa.c.

int oaa_handle_user_event ( ICLTerm event,
ICLTerm params,
ICLTerm **  solutions 
)

Definition at line 4112 of file liboaa.c.

EXTERN int oaa_Id ( ICLTerm **  Id  ) 

Return the Id of the current agent.

int oaa_InCache ( ICLTerm goal,
ICLTerm **  solutions 
)

Retrieve solutions from the cache if the goal we are asking for is properly contained in the cache (check subsumption).

Definition at line 7081 of file liboaa.c.

int oaa_Inform ( ICLTerm type_info,
char *  format_string,
ICLTerm args 
)

Sends a typed message to interested agents.

NOT FULLY IMPLEMENTED

Definition at line 7499 of file liboaa.c.

EXTERN int oaa_Init ( int  argc,
char *  argv[] 
)

Must be called to init oaa parameters, such as argv and agrc.

In the multithreaded version, starts the oaa thread.

Definition at line 164 of file liboaa.c.

int oaa_Interpret ( ICLTerm goal,
ICLTerm params,
ICLTerm **  solutions 
)

Executes an incoming event Implements a simple meta-interpreter for executing complex goals.

Agent goals are interpreted by oaa_exec_event(). The contents of Params will vary depending on context. When oaa_Interpret is called on an incoming event, Params will (usually) include from(Sender). Calls generated internally may contain from(self). Additional params may accumulate through recursive calls to oaa_Interpret.

Definition at line 3620 of file liboaa.c.

int oaa_is_oaa_id ( char *  connection_id,
ICLTerm **  id 
)

Definition at line 3490 of file liboaa.c.

int oaa_is_parent_fac_id ( char *  connection_id,
ICLTerm **  id 
)

Definition at line 3473 of file liboaa.c.

int oaa_is_waiting_for ( ICLTerm event  ) 

Check to see if the current event is something we are waiting for on a higher recursive level.

Definition at line 7601 of file liboaa.c.

int oaa_LibraryVersion ( ICLTerm **  version  ) 

Definition at line 4580 of file liboaa.c.

EXPORT_MSCPP void EXPORT_BORLAND oaa_MainLoop ( int  ShouldPrint  ) 

The main event loop for the application.

Reads an event, executes (interprets) it, checks on_receive triggers for the event, checks any application-dependent triggers.

Definition at line 2493 of file liboaa.c.

int oaa_Name ( ICLTerm **  my_name  ) 

Return the name of the current agent.

Definition at line 6390 of file liboaa.c.

EXTERN char* oaa_name_string ( void   ) 

int oaa_Ping ( ICLTerm agent_addr,
double  time_limit,
double *  total_response_time 
)

Tests whether a given agent is currently responding to requests.

Fails if a ping is not returned in TimeLimit amount of time.

Parameters:
AgentAddr the address of agent to test
TimeLimit the time limit (in seconds) for how long to wait for a response
TotalResponseTime the time for the round trip (in seconds)

Definition at line 4679 of file liboaa.c.

int oaa_poll_until_all_events ( ICLTerm event_list,
int  priority,
ICLTerm **  solutions 
)

Block until all requested events arrive.

Solutions should have been already initialized.

Definition at line 7174 of file liboaa.c.

int oaa_poll_until_event ( ICLTerm event,
ICLTerm **  solution 
)

Block until requested event arrives in oaa_GetEvent().

oaa_poll_until_event() will allocate the memory for the solution, the task to free it is left to the caller. If the caller does not care about the solution, just use NULL as the third parameter and no memory allocation will be performed.

Definition at line 7124 of file liboaa.c.

int oaa_poll_until_event_priority ( ICLTerm event,
int  priority,
ICLTerm **  solutions 
)

Definition at line 7140 of file liboaa.c.

int oaa_PostEvent ( ICLTerm contents,
ICLTerm params 
)

Sends a low-level event to another agent.

Should NOT be used before there's a connection established for the destination (such as when a client sends ev_connect to its facilitator). In such unusual cases, use com_SendData() directly. For application developers, this just means don't call oaa_PostEvent() until after you've called oaa_Register().

Parameters may include:

IMPORTANT: there may be a different address INSIDE the event; these should not be confused!

Definition at line 4381 of file liboaa.c.

int oaa_PrimaryAddress ( ICLTerm **  primaryAddress  ) 

Returns the primary address for this agent in new memory.

Definition at line 6339 of file liboaa.c.

int oaa_PrimaryId ( ICLTerm **  primaryId  ) 

Returns the primary id for this agent.

Definition at line 6360 of file liboaa.c.

int oaa_priority_compare ( ICLTerm Elt1,
ICLTerm Elt2 
)

Returns true if Elt1 and Elt2 should swap according to priority.

Definition at line 2788 of file liboaa.c.

EXPORT_MSCPP void EXPORT_BORLAND oaa_ProcessAllEvents (  ) 

To be called when the application that uses OAA has its own event loop.

Reads an event, executes (interprets) it, checks on_receive triggers for the event, checks any application-dependent triggers.

Definition at line 2518 of file liboaa.c.

EXPORT_MSCPP void EXPORT_BORLAND oaa_ProcessEvent ( ICLTerm Event,
ICLTerm Params 
)

Interprets an incoming event.

For a timeout, checks task triggers and calls user's idle procedure Otherwise, oaa_Interprets the event, checks on_receive comm triggers, and then checks task triggers.

Definition at line 2615 of file liboaa.c.

int oaa_public_solvable ( ICLTerm solvable  ) 

Definition at line 5112 of file liboaa.c.

int oaa_read_all_events ( double  TimeOut,
ICLListType **  Events,
int *  FlushPriority 
)

Flush the communication event queue, reading ALL available events and returning a list of them, or empty list if none available.

Remarks

Definition at line 2885 of file liboaa.c.

EXPORT_MSCPP void EXPORT_BORLAND oaa_Ready ( int  ShouldPrint  ) 

Changes the agent's 'open' status to 'ready', indicating that the agent is now ready to receive message.

If requested, prints 'Ready' to standard out.

Definition at line 941 of file liboaa.c.

int oaa_Redeclare ( ICLTerm initial_solvable,
ICLTerm initial_new_solvable,
ICLTerm initial_params 
)

Replace a solvable on a client or facilitator, and inform the parent if appropriate.

Parameters:
initial_solvable a single solvable, in shorthand or standard form. If in standard form, however, ONLY the goal is considered in selecting the solvable to be replaced (permissions and parameters are ignored).
initial_new_solvable a single solvable, in shorthand or standard form.
Params:

Remarks:

Definition at line 4892 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND oaa_Register ( char *  ConnectionId,
char *  AgentName,
ICLTerm Solvables 
)

Once a comm link is established, either as a client to a Facilitator or as a server for other agents, oaa_Register will setup and registration information for this agent.

The following information is stored about the current connection, accessible through com_GetInfo(ConnectionId, Info):

if connecting as client, this is also available:

In addition, the following predicates are written to parent Facilitator, or locally if the ConnectionId is a server connection:

Solvables are also written using oaa_Declare().

Parameters:
ConnectionId the symbolic connection Id (client or server connection)
AgentName the name of the agent
Solvables solvable list

Definition at line 824 of file liboaa.c.

int oaa_RegisterCallback ( char *  callback_id,
int(*)(ICLTerm *, ICLTerm *, ICLTerm *)  callback_proc 
)

Declare what procedures should be used for callbacks.

These are application-defined procedures called by library code.

Definition at line 7325 of file liboaa.c.

int oaa_remove_data_local ( ICLTerm clause1,
ICLTerm params 
)

Retract a clause (or all clauses) from an agent's solvable.

This performs the local processing needed for calls to oaaRemoveData(), and ev_update(remove, ...) requests.

See also:
oaaRemoveData()

Definition at line 6004 of file liboaa.c.

int oaa_remove_data_owned_by ( ICLTerm id  ) 

Definition at line 7700 of file liboaa.c.

int oaa_remove_solvables_data ( ICLTerm solvables  ) 

For each data solvable, remove all clauses belonging to it.

Solvables must be in standard form, and should include only data solvables; permissions are ignored.

Definition at line 7655 of file liboaa.c.

int oaa_RemoveData ( ICLTerm clause,
ICLTerm in_params,
ICLTerm **  out_params 
)

Definition at line 5555 of file liboaa.c.

int oaa_replace_all ( ICLTerm clause1,
ICLTerm clause2,
ICLTerm owner,
ICLTerm callback 
)

Definition at line 6553 of file liboaa.c.

int oaa_replace_data_local ( ICLTerm clause1_in,
ICLTerm params 
)

Replace one or more clauses from an agent's solvable.

This performs the local processing needed for calls to oaa_ReplaceData, and ev_update(replace, ...) requests. Clause1 is the thing to be replaced. The thing to replace it with must be present in Params, as with(Clause2).

See also:
oaa_ReplaceData

Definition at line 6077 of file liboaa.c.

int oaa_ReplaceData ( ICLTerm clause1,
ICLTerm clause2,
ICLTerm in_params,
ICLTerm **  out_params 
)

Change a predicate value to a new one.

Parameters:
clause1 must be a clause of a writable data solvable.
clause2 must be a clause of a writable data solvable.
Params:

Remarks:

Definition at line 5602 of file liboaa.c.

int oaa_retract ( ICLTerm clause,
ICLTerm owner,
ICLTerm callback 
)

Definition at line 6524 of file liboaa.c.

int oaa_retract_cache ( ICLTerm goal,
ICLTerm **  solutions 
)

Retract the first cached solutions associated with this goal.

Definition at line 509 of file liboaa.c.

int oaa_retract_callback ( ICLTerm id,
int(*)(ICLTerm *, ICLTerm *, ICLTerm *)  user_callback 
)

Retract the first callback associated with this id.

Definition at line 402 of file liboaa.c.

int oaa_retract_delay ( ICLTerm id,
ICLTerm **  user_id 
)

Retract the fact that the user has requested a delayed solution to a particular goal and return the user id.

Definition at line 305 of file liboaa.c.

int oaa_retract_delay_table ( ICLTerm **  goal_id,
ICLTerm user_id,
ICLTerm **  full_goal,
ICLTerm **  solve_params,
ICLTerm **  all_params 
)

Remove and return the first solution found that has been stored with the key, user_id.

Definition at line 346 of file liboaa.c.

int oaa_retract_waiting_event ( ICLTerm event  ) 

Retract the first event list associated with this id.

Definition at line 614 of file liboaa.c.

int oaa_retract_waiting_for ( ICLTerm id,
ICLTerm **  event_list 
)

Retract the first event list associated with this id.

Definition at line 572 of file liboaa.c.

int oaa_retractall ( ICLTerm clause,
ICLTerm owner,
ICLTerm callback 
)

Definition at line 6547 of file liboaa.c.

int oaa_retractall_cache ( ICLTerm goal  ) 

Retract all cached solutions with goals that unify with the parameter.

Definition at line 462 of file liboaa.c.

int oaa_retractall_callback ( ICLTerm id,
ICLTerm **  proc 
)

Retract all callbacks associated with this id.

Definition at line 415 of file liboaa.c.

int oaa_retractall_current_contexts ( ICLTerm id  ) 

Retract all current contexts associated with a particular id.

This function is specific to the C version and replaces the the predicate retractall(oaa_current_contexts(ID)).

Definition at line 272 of file liboaa.c.

int oaa_retrieve_all_cache ( ICLTerm goal,
ICLTerm **  solutions 
)

Retrieves all the cached solutions without retracting them.

Definition at line 483 of file liboaa.c.

int oaa_retrieve_all_waiting_events ( ICLTerm **  event_list  ) 

Retrieves all waiting events.

Definition at line 597 of file liboaa.c.

int oaa_retrieve_all_waiting_for ( ICLTerm id,
ICLTerm **  event_list 
)

Retrieves all event lists for a particular id term.

Definition at line 545 of file liboaa.c.

int oaa_retrieve_cache ( ICLTerm goal,
ICLTerm **  solutions 
)

Retrieves the cached solutions without retracting them.

Definition at line 448 of file liboaa.c.

int oaa_retrieve_callback ( ICLTerm id,
int(**)(ICLTerm *, ICLTerm *, ICLTerm *)  user_callback 
)

Retrieves the callback procedure without retracting it.

Definition at line 389 of file liboaa.c.

int oaa_retrieve_current_contexts ( ICLTerm id,
ICLTerm **  contexts 
)

Retrieve the context associated with id without removing the entry from the table.

This function is specific to the C version and replaces the predicate oaa_current_contexts(id, Contexts).

Definition at line 239 of file liboaa.c.

int oaa_retrieve_nth_current_contexts ( ICLTerm **  id,
ICLTerm **  contexts,
int  n 
)

Retrieve the nth id and contexts from the current_context table.

This function is specific to the C version and replaces the the predicate oaa_current_contexts(Id, Contexts) i.e. when the goal is called with both parameters as uninstantiated variables.

Definition at line 254 of file liboaa.c.

int oaa_retrieve_waiting_for ( ICLTerm id,
ICLTerm **  event_list 
)

Retrieves the event list for a particular id without retracting it.

Definition at line 532 of file liboaa.c.

int oaa_ReturnDelayedSolutions ( ICLTerm id,
ICLTerm solution_list 
)

Returns the list of solutions for a delayed request.

Parameters:
id an Id referring to a previously saved oaa_DelaySolution

Definition at line 4219 of file liboaa.c.

int oaa_select_event ( double  timeout,
ICLTerm **  event 
)

If a positive timeout is defined, wait N seconds for an event to arrive.

Otherwise block-wait until an event arrives.

IMPORTANT: Connected/1 gets special handling, because we want the connection ID and oaa ID to be assigned immediately. Otherwise, oaa_translate_incoming_event() and oaa_unwrap_event() won't always work properly for subsequent events from the new connection (or would have to be more complicated).

Definition at line 3258 of file liboaa.c.

int oaa_SeqNumLessThan ( int  a,
int  b 
)

Definition at line 8518 of file liboaa.c.

EXPORT_MSCPP void EXPORT_BORLAND oaa_SetTimeout ( double  NSecs  ) 

Sets the timeout value used by oaa_GetEvent().

Definition at line 2658 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND oaa_SetupCommunication ( char *  InitialAgentName  ) 

Convenience function for connecting to a facilitator and, if oaa_listen can be resolved, for opening server listening sockets for to handle direct_connect requests.

Definition at line 8484 of file liboaa.c.

int oaa_Solve ( ICLTerm goal,
ICLTerm initial_params,
ICLTerm **  out_params,
ICLTerm **  solutions 
)

Sends work or information requests to distributed agents, brokered by the Facilitator agent.

The default behavior (paramlist = []) is to act like the Prolog primitive call(Goal), blocking until Goal is finished, and unifying and backtracking over solutions for Goal.

This behavior may be modified by a parameter list, which may contain:

Note that certain combinations of parameters are inconsistent, and are handled as follows:

All of the above parameters may be used in the "global" parameter list (the second argument to oaa_Solve), when Goal is non-compound. Most can be used in the global list with compound goals also. Some of these parameters can also be used in the NESTED parameter lists of compound goals. Uses of these parameters with compound goals are documented elsewhere. When that documentation exists, this will go there: With many compound goals, however, the get_satisfier/1 parameter isn't really meaningful. Thus, with compound goals, it is often best to use this parameter in a nested parameter list.

Definition at line 6706 of file liboaa.c.

int oaa_solve_local ( ICLTerm full_goal,
ICLTerm params,
ICLTerm **  solutions 
)

Definition at line 6902 of file liboaa.c.

int oaa_sort_and_get_event ( ICLTerm EventList,
int  LowestPriority,
ICLTerm **  Event,
ICLTerm **  Params 
)

Sort raw events by priority, choose the highest priority event or FirstIn if equal priority, extract event data and sender, and store the rest of events.

The chosen event must be of HIGHER priority than LowestPriority, and oaa_sort_and_get_event() can fail if no appropriate event is found.

Definition at line 2768 of file liboaa.c.

EXPORT_MSCPP int EXPORT_BORLAND oaa_SupportsSequenceNumbers ( char *  connectionId  ) 

Definition at line 8584 of file liboaa.c.

int oaa_TraceMsg ( char *  format_string,
  ... 
)

If trace mode is on, display message and arguments.

Definition at line 7436 of file liboaa.c.

int oaa_translate_incoming_event ( ICLTerm raw_event_in,
ICLTerm **  raw_event_out 
)

Definition at line 3513 of file liboaa.c.

int oaa_translate_outgoing_event ( ICLTerm event,
ICLTerm dest_id,
char *  commId,
ICLTerm **  new_event 
)

Provides backwards compatibility by calling a hook (user:oaa_event_translation/7) that translates outgoing events to agents of other versions.

Also allows for event differences based on language. user:oaa_event_translation/7 can be hard-coded, loaded at runtime, or whatever. If it's not present, we return the same event.

See also:
oaa_translate_incoming_event()

Definition at line 4487 of file liboaa.c.

int oaa_turn_off_debug (  ) 

Definition at line 7482 of file liboaa.c.

int oaa_turn_on_debug (  ) 

Definition at line 7468 of file liboaa.c.

int oaa_Undeclare ( ICLTerm solvable,
ICLTerm initial_params,
ICLTerm **  undeclared_solvables 
)

Remove solvables from a client or facilitator, and inform the parent if appropriate.

If called by a leaf or node agent, assumes agent it is already registered with a parent facilitator.

Parameters:
solvable a single solvable or a list of solvables, in shorthand or standard form. If a solvable is in standard form, however, ONLY the goal is considered in selecting the solvables to be removed (permissions and parameters are ignored).
initial_params address(X): Where the solvable exists. X may be either 'self' or 'parent' (or the appropriate local ids). Default: 'self'.
undeclared_solvables returns a list, in standard form, of all solvables successfully removed.

Definition at line 4856 of file liboaa.c.

int oaa_unwrap_event ( ICLTerm in_event,
char **  connection_id,
ICLTerm **  out_event 
)

Remove an event term from its communications wrapper (if any), and returns it in our standard internal form: 'timeout' OR event(Content, Params).

Note: First message from facilitator looks like:

    term(event(ev_connected(LIST),[])) term/1 event/2
Usually we get:
    term(int, event(functor(LIST),[])) term/2 event/2
For timeout:
    timeout
Parameters:
in_event,: An event from another agent, which has already been translated for version compatibility, if necessary.
connection_id the CONNECTION of the immediate agent from which this message came (note that an agent's CONNECTION can be different than its ID).
out_event an event term in our standard internal format, as required by all other library procedures.

Definition at line 3328 of file liboaa.c.

int oaa_update ( char *  mode,
ICLTerm clause,
ICLTerm initial_params,
ICLTerm **  out_params 
)

Common code for oaa_AddData(), oaaRemoveData(), and oaa_ReplaceData().

Parameters:
mode add, remove, or replace.
clause may include whatever is appropriate for oaa_AddData(), oaaRemoveData(), or oaa_ReplaceData().
initial_params may include whatever is appropriate for oaa_AddData(), oaaRemoveData(), or oaa_ReplaceData().

Definition at line 5643 of file liboaa.c.

int oaa_ValidateEvent ( ICLTerm E,
ICLTerm **  OkEvent 
)

Check that an incoming lowlevel event should be processed.

This is the place to put security checks on events. The default behavior defined by the library can be made more stringent by individual agents using the callback oaa_AppValidateEvent(). oaa_ValidateEvent() has the right to modify the incoming event, or refuse it altogether by failing. This will return a newly allocated ICLTerm.

Definition at line 3005 of file liboaa.c.

int oaa_Version ( ICLTerm agent_id,
ICLTerm **  language,
ICLTerm **  version 
)

Lookup the language and library version number for an agent.

The default version (if unspecified) is 1.0.

Definition at line 4593 of file liboaa.c.

int oaa_version_atleast ( int  major,
int  minor,
int  level,
ICLTerm toCheck 
)

Check if the given version list is at least [major,minor,level].

To indicate that portions of the version list are irrelevant, use -1.

Parameters:
major the minimum major value in the version, never -1
minor the minimum minor value, or -1 to ignore minor and level values
level the minimum level value, or -1 to ignore
toCheck the version ICLTerm to check, must be a list
Returns:
TRUE if the given term contains a list with a version at least the one given and FALSE otherwise. FALSE is also returned if toCheck is not a list

Definition at line 8538 of file liboaa.c.

ICLTerm * param_default_list (  ) 

Returns the list of default parameters.

May be used with icl_ParamValue() to test or lookup an element

Definition at line 1268 of file liboaa.c.

int passes_tests ( ICLTerm params  ) 

Definition at line 4157 of file liboaa.c.

ICLTerm * perm_default_list (  ) 

Returns the list of default permissions.

May be used with icl_ParamValue() to test or lookup an element

Definition at line 1183 of file liboaa.c.

int predicate_skeleton ( ICLTerm goal,
ICLTerm **  skeleton 
)

Definition at line 7795 of file liboaa.c.

int ref_for_clause ( ICLTerm clause,
ICLTerm **  ref 
)

Definition at line 5863 of file liboaa.c.

ICLTerm * remove_element ( ICLTerm elt,
ICLTerm list,
ICLTerm **  rest 
)

Creates a copy of the incoming list, where the first element that unifies with elt is missing.

Fails if X is not an element in the list.

Returns:
a pointer to the removed element

Definition at line 7831 of file liboaa.c.

int replace_all ( ICLTerm clause1,
ICLTerm clause2 
)

Replaces all clauses matching clause1 with clause2.

Always succeeds.

Definition at line 6200 of file liboaa.c.

int replace_element ( ICLTerm elt,
ICLTerm old_list,
ICLTerm new_elt,
ICLTerm **  new_list 
)

Replaces the element elt, if present in old_list, with the element new_elt.

If there are multiple occurrences of elt, only replaces the first. Results returned in new_list.

Definition at line 7861 of file liboaa.c.

int retract ( ICLTerm clause  ) 

Definition at line 5828 of file liboaa.c.

int retract_all ( ICLTerm clause  ) 

Remove all clauses matching Clause1 Always succeeds.

Needed because retractall((func(X) :- Y)) doesn't work.

Definition at line 6184 of file liboaa.c.

int select_elements ( ICLTerm list,
int(*)(ICLTerm *)  test_function,
ICLTerm **  result 
)

Selects all List elements for which Selector(element) succeeds.

If there are multiple occurrences of Elt, only replaces the first teste_function is a pointer to a function of prototype : int func(ICLTerm* t) processed on each ICLTerm contained in the incoming list

Definition at line 4931 of file liboaa.c.

int solvables_to_be_added ( ICLTerm solvables,
ICLTerm current,
ICLTerm **  ok_solvables 
)

Checks a list of solvables, to make sure they can legally be declared.

Definition at line 5411 of file liboaa.c.

int solvables_to_be_removed ( ICLTerm solvables,
ICLTerm current,
ICLTerm **  ok_solvables 
)

Checks a list of solvables, to make sure they can legally be UNdeclared.

Definition at line 5448 of file liboaa.c.

ICLTerm* valid_oaa_solvables (  ) 

Definition at line 4097 of file liboaa.c.


Variable Documentation

ICLDatabase* commdb

Definition at line 90 of file libcom_tcp.c.

int oaa_argc = 0

Definition at line 115 of file liboaa.c.

char** oaa_argv = NULL

Definition at line 116 of file liboaa.c.

char const* oaa_library_version_str = "[2,3,2]"

Deprecated:
use oaa_LibraryVersion()

Definition at line 87 of file liboaa.c.

ICLTerm* oaa_saved_events = NULL

Definition at line 99 of file liboaa.c.


Generated on Wed May 23 17:20:15 2007 using doxygen 1.5.2