Agent library (part of spades v0.7) user guidance and reference manual
Patrick Riley Pfr @cs.cmu.edu
2003.5.27
Translation: Xu Yuan XYCHN15@yahoo.com.cn
1 Introduction
This is a document on the Agent library (part of spades). This document does not override all the features of Spades, which can be found in other documents.
The Agent library provides a C interface to make the Agent and Server interact. The Agent library supports information in the correct format. The Agent library uses some classes in the Spades library, and there are four major new categories (there are some subclasses):
AgentComminterface This class is the main point of the interface. All transmitted information passes this class.
TOCSMESSAGE This is a virtual base class. Subclasses provide various information sent to Server.
FromCSMessage This is a virtual base class. Subclasses provide a variety of information received from Server.
AgentlibraryParam This is a subclass of ParamReader (described in SPADES main documentation), class paramReader contains parameters for controlling the Agent library.
The Agent library also provides action and error log tools, which are described in the SPADES main documentation.
2.Agentcomminterface
This class is the main point of the interface. It supports sending information.
The functions are:
Constructor
The read and write file is set according to the parameters input_fd and otput_fd, but do not send any information.
Destructor
Close the channel with the server communication.
TryMessageRead
Try to read information from the server and return information. This function does not block, and NULL is returned without information.
ReceiveMessage
Like tryMessageRead, in addition to possible blocking, Num_select_timeout is waiting for information, waiting for the specified parameter WAIT_SEC and WAIT_USEC. Returns NULL if the timeout or received information is an error (and set off flag).
Shouldshutdown
Returns the closing flag to set, INITESHUTDOWN, the input channel error and timeout will set the closing flag.
INITIKESHUTDOWN
Set the closure flag to true.
GetlateStime
Returns the time recently received information.
Send
Send information (one type of TOCSMESSAGE)
GetOutstandingThinks
Get nothing to complete. Unless an error, it is 1 or 0. In other words, if the agent is thinking about the cycle, returns 1, otherwise returns 0.
3.tocsmessage
This is a virtual base class that can send information from the Agent to Server.
Use operator << Print information. This is mainly used on debugging and purposeful information.
GetOutstandingThinkMod
Returns this information that affects the number other than thinking (completed thinking -1, feeling 1, etc.).
Writeto
Write information according to Spades Server communication standard.
TOCSMESSAGE has a subclass, Agent can use it to send information to Server. These classes use DataArray, DataARRY described in the SPADES main documentation.
TOCSMESSAGE_ACT
Use DataArray as the parameter to process the characters you want to send.
TOCSMESSAGE_REQUESTTIMENOTIFY
Transforming an integer into time required for time notification.
TOCSMESSAGE_MIGRATIONDATA
Use DataArray as the parameter to process the Agent new data.
TOCSMESSAGE_DONETHINKING
Complete thinking information tells Server This Agent has completed the thinking cycle. TOCSMESSAGE_EXIT
Agent quit from the Server notified.
TOCSMESSAGE_INITDONE
Broad Initialization to the Server.
4.FromCsMessage
This is a virtual base class, Agent can receive information from Server.
This type of function is:
Use operator << Print information. This is mainly used on debugging and purposeful information.
GetOutstandingThinkMod
Returns this information that affects the number other than thinking (completed thinking -1, feeling 1, etc.).
ACCEPT
In order to avoid the user's calculation of time type or other painful things, this class is designed according to the guest mode. To handle different messages separately, you can use Subclass fromCsMessage :: Visitor or fromCsmessage :: Constvisitor. These subclasses of fromCSMessage have access functions. When you have a message to be processed, you can call the Accept function processing with fromCSMessage :: Visitor or fromCSMESSAGE :: Constvisitor. Your object will call the appropriate access function.
FromCSMessage has a subclass, Agent can use it to receive information sent by Server. These classes use DataArray, DataARRY described in the SPADES main documentation. The subclasses of fromcsmessage are:
Fromcsmessage_initdata
After start, the initialization data sent. If it is not a moving data, it will be empty.
FromCSMessage_exit
Require Agent to exit. Information will no longer be sent or received.
FromCSMessage_sense
This is a feeling of feeling. This is likely that it may not be a thinking cycle (you can use the getthinking function). You can get information and time related information and time.
FromCSMessage_Timenotify
Each request time is reported to send a time notification. This is likely that it may not be a thinking cycle (you can use the getthinking function).
Fromcsmessage_migrationRequest
Agent is required to send back a mobile data information because it is about to move.
FromCSMessage_ERROR
A error of Server. Error is stored as a string. Possible values and its meaning are described in the SPADES main documentation.
FromCSMessage_thinkTime
Notification of the time used for the last consideration cycle.
5. Parameter
Class AgentlibraryParam contains the following parameters. It also provides a tool for analyzing parameters in the command line and files, which is the same as the class paramreader described in the SPADES main document.
You can inherit agentlibraryParam to add your own parameters.
Name Type Description Default logfile_dirstringlog file Output Directory logsaction_log_fnstring Action Log filename (for debugging information) See the SPADES master document Detailed Description Actions.LogAction_log_levelinteger Output Action LOG's highest level. See the detailed description of the SPADES main document 0random_seedinteger randomly generates a value. Any negative value will result in the selection wait time (= 0) 5WAIT_USEC Integer (> = 0) 10NUM_SELECTS_TIMEOUTINTEGER (microsecond) = 0) > = 0) Before the Agent exits, the time 20INput_fd integer (> = 3) is received from the Server received information from the server. This must be in line with the type database of the agent. 3Output_fd integer (> = 3) Description files of information sent to Server. This must be in line with the type database of the agent. 46. Example
Example Agent gives a complete example of using the Agent library. This section provides some steps you may do before programming.
Allocate a parameter Object (Subclass of AgentlibraryParam)
Call GetOptions on this Object
Logger :: Instance () -> settagfunction (new agenttagfunction);
Logger :: Instance () -> setMaxActionLoglevel (AgentlibraryParam :: Instance () -> getActionLoglevel ());
Spades :: Seedram :: Instance () -> getrandomseed ());
Allocate Pacsi, Of Type Agentcomminterface
Fromcsmessage * m;
While ((m = pASCI-> received ")! = null)
Process message m
Deletem;