#include <unistd.h>#include <libtrigger.h>#include <libutils.h>Go to the source code of this file.
Defines | |
| #define | EXTERN extern |
| #define | FALSE 0 |
| #define | TRUE 1 |
| #define | OAA_LIBRARY_VERSION oaa_library_version_str; |
| #define | STREQ(str1, str2) (strcmp((str1), (str2)) == 0) |
| #define | sleep_millis(n) usleep((n)*1000L) |
Functions | |
| EXTERN int | 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. | |
| EXTERN void | oaa_Ready (int ShouldPrint) |
| Changes the agent's 'open' status to 'ready', indicating that the agent is now ready to receive message. | |
| EXTERN int | icl_Builtin (ICLTerm *goal) |
| EXTERN int | 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. | |
| EXTERN int | 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(). | |
| EXTERN int | 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(). | |
| EXTERN int | icl_ConvertSolvables (int toStandard, ICLTerm *ShorthandSolvables, ICLTerm **StandardSolvables) |
| Convert between shorthand and standard forms of solvables list. | |
| EXTERN int | oaa_Init (int argc, char *argv[]) |
| Must be called to init oaa parameters, such as argv and agrc. | |
| EXTERN void | oaa_MainLoop (int ShouldPrint) |
| The main event loop for the application. | |
| EXTERN void | oaa_ProcessAllEvents () |
| To be called when the application that uses OAA has its own event loop. | |
| EXTERN void | oaa_ProcessEvent (ICLTerm *Event, ICLTerm *Params) |
| Interprets an incoming event. | |
| EXTERN void | oaa_SetTimeout (double NSecs) |
| Sets the timeout value used by oaa_GetEvent(). | |
| EXTERN void | oaa_GetEvent (ICLTerm **Event, ICLTerm **Params, int LowestPriority) |
| Return the next event to execute. | |
| EXTERN int | oaa_ValidateEvent (ICLTerm *E, ICLTerm **OkEvent) |
| Check that an incoming lowlevel event should be processed. | |
| EXTERN int | oaa_Interpret (ICLTerm *goal, ICLTerm *params, ICLTerm **solutions) |
| Executes an incoming event Implements a simple meta-interpreter for executing complex goals. | |
| EXTERN int | oaa_DelaySolution (ICLTerm *id) |
| Requests that the current AppDoEvent not return solutions to the current goal until a later time. | |
| EXTERN int | oaa_ReturnDelayedSolutions (ICLTerm *id, ICLTerm *solution_list) |
| Returns the list of solutions for a delayed request. | |
| EXTERN 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. | |
| EXTERN int | oaa_PostEvent (ICLTerm *contents, ICLTerm *params) |
| Sends a low-level event to another agent. | |
| EXTERN int | oaa_Version (ICLTerm *agent_id, ICLTerm **language, ICLTerm **version) |
| Lookup the language and library version number for an agent. | |
| EXTERN int | oaa_CanSolve (ICLTerm *goal, ICLTerm **kslist) |
| Asks the Facilitator for a list of agents which could solve a Goal. | |
| EXTERN int | oaa_Ping (ICLTerm *agent_addr, double time_limit, double *total_response_time) |
| Tests whether a given agent is currently responding to requests. | |
| EXTERN 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. | |
| EXTERN int | oaa_DeclareData (ICLTerm *solv, ICLTerm *params, ICLTerm **declared_solvs) |
| Declare data solvables for an agent. | |
| EXTERN int | oaa_Undeclare (ICLTerm *solvable, ICLTerm *initial_params, ICLTerm **undeclared_solvables) |
| Remove solvables from a client or facilitator, and inform the parent if appropriate. | |
| EXTERN 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. | |
| EXTERN int | oaa_AddData (ICLTerm *clause, ICLTerm *in_params, ICLTerm **out_params) |
| Add a new clause for a DATA solvable (locally and/or remotely). | |
| EXTERN int | oaa_RemoveData (ICLTerm *clause, ICLTerm *in_params, ICLTerm **out_params) |
| EXTERN int | oaa_ReplaceData (ICLTerm *clause1, ICLTerm *clause2, ICLTerm *in_params, ICLTerm **out_params) |
| Change a predicate value to a new one. | |
| EXTERN int | oaa_Id (ICLTerm **my_id) |
| Return the Id of the current agent. | |
| EXTERN int | oaa_Name (ICLTerm **my_name) |
| Return the name of the current agent. | |
| EXTERN int | oaa_Address (char *connectionId, ICLTerm *Type, ICLTerm **myAddress) |
| Returns (one of more) Addresses for this agent. | |
| EXTERN int | oaa_PrimaryAddress (ICLTerm **primaryAddress) |
| Returns the primary address for this agent in new memory. | |
| EXTERN int | oaa_PrimaryId (ICLTerm **primaryId) |
| Returns the primary id for this agent. | |
| EXTERN 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. | |
| EXTERN 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). | |
| EXTERN int | oaa_AddToCache (ICLTerm *goal, ICLTerm *solutions) |
| Add each solution to goal one at a time so we can retrieve solutions later using findall. | |
| EXTERN int | oaa_ClearCache () |
| Clear the cache. | |
| EXTERN int | oaa_RegisterCallback (char *callback_id, int(*callback_proc)(ICLTerm *, ICLTerm *, ICLTerm *)) |
| Declare what procedures should be used for callbacks. | |
| EXTERN int | oaa_GetCallback (char *callback_id, int(**callback_proc)(ICLTerm *, ICLTerm *, ICLTerm *)) |
| EXTERN int | oaa_TraceMsg (char *format_string,...) |
| If trace mode is on, display message and arguments. | |
| EXTERN char * | oaa_name_string (void) |
| EXTERN int | memberchk (ICLTerm *Param, ICLTerm *ParamList) |
| Searches for a parameter in a list. | |
| EXTERN int | 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. | |
| EXTERN int | oaa_Disconnect (char *ConnectionId, ICLTerm *Params) |
| Disconnect from the given comm link, or from all links if the given CommunicationID is NULL. | |
| EXTERN int | oaa_SetupCommunication (char *InitialAgentName) |
Convenience function for connecting to a facilitator and, if oaa_listen | |
| EXTERN int | oaa_LibraryVersion (ICLTerm **versionCopy) |
| EXTERN int | oaa_SupportsSequenceNumbers (char *connectionId) |
Variables | |
| EXTERN char const * | oaa_library_version_str |
Definition in file liboaa.h.
| #define OAA_LIBRARY_VERSION oaa_library_version_str; |
| EXTERN int 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:
| EXTERN int icl_Builtin | ( | ICLTerm * | goal | ) |
| EXTERN int 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).
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:
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:
Add a new clause for a DATA solvable (locally and/or remotely).
Params:
Remarks:
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.
| 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) |
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.
| EXTERN int 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.
| EXTERN 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.
| 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. |
Remarks
| EXTERN int oaa_DelaySolution | ( | ICLTerm * | id | ) |
| EXTERN int oaa_Disconnect | ( | char * | ConnectionId, | |
| ICLTerm * | Params | |||
| ) |
Disconnect from the given comm link, or from all links if the given CommunicationID is NULL.
| ConnectionId | the link to disconnect; if NULL, disconnect from all links | |
| Params | for future enhancements; currently ignored. |
Return the next event to execute.
Remarks:
| int oaa_Id | ( | ICLTerm ** | my_id | ) |
| EXTERN int oaa_Init | ( | int | argc, | |
| char * | argv[] | |||
| ) |
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.
| EXTERN void oaa_MainLoop | ( | int | ShouldPrint | ) |
| EXTERN int oaa_Name | ( | ICLTerm ** | my_name | ) |
| EXTERN 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.
| 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) |
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!
| EXTERN int oaa_PrimaryAddress | ( | ICLTerm ** | primaryAddress | ) |
| EXTERN int oaa_PrimaryId | ( | ICLTerm ** | primaryId | ) |
| EXTERN void oaa_ProcessAllEvents | ( | ) |
| EXTERN void oaa_Ready | ( | int | ShouldPrint | ) |
| EXTERN 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.
| 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. |
Remarks:
| EXTERN int 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().
| ConnectionId | the symbolic connection Id (client or server connection) | |
| AgentName | the name of the agent | |
| Solvables | solvable list |
| EXTERN int oaa_ReplaceData | ( | ICLTerm * | clause1, | |
| ICLTerm * | clause2, | |||
| ICLTerm * | in_params, | |||
| ICLTerm ** | out_params | |||
| ) |
Change a predicate value to a new one.
| clause1 | must be a clause of a writable data solvable. | |
| clause2 | must be a clause of a writable data solvable. |
Remarks:
| EXTERN void oaa_SetTimeout | ( | double | NSecs | ) |
| EXTERN int oaa_SetupCommunication | ( | char * | InitialAgentName | ) |
| EXTERN 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.
| EXTERN int oaa_SupportsSequenceNumbers | ( | char * | connectionId | ) |
| EXTERN int oaa_TraceMsg | ( | char * | format_string, | |
| ... | ||||
| ) |
| EXTERN 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.
| 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. |
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.
| EXTERN char const* oaa_library_version_str |