COSMOS core
1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
|
Modules | |
Agent Server and Client functions | |
Agent Server and Client Library typedefs | |
Agent Server and Client.
These functions support the transformation of a generic program into a COSMOS aware program. The first level of transformation creates a COSMOS Client that is able to speak the COSMOS language and communicate with any active COSMOS Agents, while the second level of transformation creates a full COSMOS Agent.
Clients are COSMOS aware programs that are made aware of the JSON Name Space, and are capable of receiving messages broadcast by any Agents on the same NetworkType. These messages, composed of JSON from the JSON Name Space, contain an initial header containing key information about the sending Agent, plus any additional JSON Name Space values that the particular Agent cares to make available. This allows the Clients to collect information about the local system, and make requests of Agents. COSMOS Clients are equipped with a background thread that collects COSMOS messages and stores them in a ring. Reading of messages is accomplised through Cosmos::Agent::readring, which gives you the next message in the ring until you reach the most recent message. Ring size defaults to 100 messages, but can by changed with Cosmos::Agent::resizering. The ring can be flushed at any time with Cosmos::Agent::clearring. Requests to agents are made with Cosmos::Agent::send_request. As part of its message collection thread, the Client also keeps a list of discovered Agents. This list can be used to provide the Agent information required by Cosmos::Agent::send_request through use of Cosmos::Agent::find_agent. Finally, Clients open a Publication Channel for the sending of messages to other COSMOS aware software. Messages are broadcast, using whatever mechanism is appropriate for the NetworkType chosen, using Cosmos::Agent::post. They can be assigned any of 256 types, following the rules of Cosmos::Agent::AgentMessage. The actual content over the network will be a single type byte, a 2 byte unsigned integer in little_endian order containing the length in bytes of the header, a JSON header using values from the JSON Name Space to represent meta information about the Agent, and optional data, either as bytes (if type > 127), or additional JSON values. The header contains the following fields from the beatstruc, returned from either Cosmos::Agent::readring or Cosmos::Agent::find_agent:
Agents are persistent COSMOS aware programs that provide the system framework for any COSMOS implementation. They are similar to UNIX Daemons or Windows Services in that they run continuously until commanded to stop, and serve a constant function, either automatically or on demand. In addition to the features listed for Clients, Agents are provided with two additional features, implemented as two additional threads of execution.
Both Clients and Agents are formed using Cosmos::Agent. Once you have performed any initializations necessary, you should enter a continuous loop, protected by Cosmos::Agent::running, and preferably surrendering control periodically with Cosmos::COSMOS_SLEEP. Upon exiting from this loop, you should call Cosmos::Agent::shutdown.