COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
Cosmos::Support::Agent Class Reference

#include <agentclass.h>

Collaboration diagram for Cosmos::Support::Agent:

Classes

struct  beatstruc_list
 
struct  messstruc
 Storage for messages. More...
 
struct  pollstruc
 
struct  request_entry
 

Public Types

enum  State : uint16_t {
  State::SHUTDOWN =0, State::INIT, State::IDLE, State::RUN,
  State::MONITOR, State::ASAFE, State::DEBUG, State::RESET
}
 
enum  AgentMessage : uint8_t {
  AgentMessage::ALL =1, AgentMessage::BEAT =2, AgentMessage::SOH =3, AgentMessage::GENERIC =4,
  AgentMessage::TIME =5, AgentMessage::LOCATION =6, AgentMessage::TRACK =7, AgentMessage::IMU =8,
  AgentMessage::EVENT =9, AgentMessage::REQUEST =10, AgentMessage::RESPONSE =11, AgentMessage::BINARY =128,
  AgentMessage::COMM =129
}
 Type of Agent Message. Types > 127 are binary. More...
 
enum  Where : size_t { Where::HEAD = 0, Where::TAIL = 1 }
 
typedef int32_t(* external_request_function) (string &request_string, string &output_string, Agent *agent)
 

Public Member Functions

 Agent (const string &node_name="", const string &agent_name="", double bprd=0., uint32_t bsize=AGENTMAXBUFFER, bool mflag=false, int32_t portnum=0, NetworkType ntype=NetworkType::UDP, uint16_t dlevel=1)
 
 ~Agent ()
 
int32_t start ()
 Start Agent Request and Heartbeat loops. More...
 
int32_t start_active_loop ()
 
int32_t finish_active_loop ()
 
int32_t add_request (string token, external_request_function function, string synopsis="", string description="")
 Add internal request to Agent request list with description and synopsis. More...
 
int32_t send_request (beatstruc cbeat, string request, string &output, float waitsec=5.)
 Send a request over AGENT. More...
 
int32_t send_request_jsonnode (beatstruc cbeat, jsonnode &jnode, float waitsec=5.)
 Send request for Node JSON. More...
 
int32_t get_agent (string node, string agent, double waitsec, beatstruc &cbeat)
 Get specific server. More...
 
int32_t check_agent (string node, string agent, double waitsec)
 Check agent. More...
 
beatstruc find_agent (string node, string agent, double waitsec=0.)
 Find agent. More...
 
vector< beatstrucfind_agents (double waitsec=0.)
 Find single server. More...
 
uint16_t running ()
 Check if we're supposed to be running. More...
 
int32_t wait (State state=State::RUN, double waitsec=10.)
 
int32_t last_error ()
 
int32_t set_sohstring (string list)
 Set Limited SOH string. More...
 
int32_t set_fullsohstring (string list)
 Set Full SOH string. More...
 
cosmosstrucget_cosmosstruc ()
 Return Agent cosmosstruc. More...
 
void get_ip (char *buffer, size_t buflen)
 
void get_ip_list (uint16_t port)
 
int32_t unpublish ()
 Close COSMOS output channel. More...
 
int32_t post (messstruc mess)
 Post a Cosmos::Agent::messstruc. More...
 
int32_t post (AgentMessage type, string message="")
 Post a JSON message. More...
 
int32_t post (AgentMessage type, vector< uint8_t > message)
 Post a binary message. More...
 
int32_t post_beat ()
 
int32_t post_soh ()
 
int32_t publish (NetworkType type, uint16_t port)
 Open COSMOS output channel. More...
 
int32_t subscribe (NetworkType type, const char *address, uint16_t port)
 Open COSMOS channel for polling with 100 usec timeout. More...
 
int32_t subscribe (NetworkType type, const char *address, uint16_t port, uint32_t usectimeo)
 Open COSMOS channel for polling. More...
 
int32_t unsubscribe ()
 Close COSMOS subscription channel. More...
 
int32_t poll (messstruc &mess, AgentMessage type, float waitsec=1.)
 Listen for message. More...
 
int32_t readring (messstruc &message, AgentMessage type=Agent::AgentMessage::ALL, float waitsec=1., Where where=Where::TAIL, string proc="", string node="")
 Check Ring for message. More...
 
int32_t parsering (AgentMessage type=Agent::AgentMessage::ALL, float waitsec=1., Where where=Where::HEAD, string proc="", string node="")
 Parse next message from ring. More...
 
int32_t resizering (size_t newsize)
 
int32_t clearring ()
 
int json_map_agentstruc (agentstruc **agent)
 
vector< socket_channelfind_addresses (NetworkType ntype)
 Discover interfaces. More...
 
int32_t shutdown ()
 Shutdown agent gracefully. More...
 
int32_t send (uint8_t address, string message)
 
int32_t receive (uint8_t address, string &message)
 
int32_t receiveAll (uint8_t address, string &message)
 
string getNode ()
 Listen for heartbeat. More...
 
string getAgent ()
 
int32_t getJson (string node, jsonnode &jnode)
 
int32_t set_agent_time_producer (double(*source)())
 
int32_t get_agent_time (double &agent_time, double &epsilon, double &delta, string agent, string node="any", double wait_sec=2.)
 
void log (string log_entry)
 
bool setSoh (string sohFields)
 
FILE * get_debug_fd (double mjd=0.)
 
int32_t close_debug_fd ()
 

Public Attributes

vector< jsonentry * > sohtable
 State of Health element vector. More...
 
vector< jsonentry * > fullsohtable
 
pollstruc metaRx
 
string metaHeader
 
cosmosstruccinfo
 
vector< beatstrucagent_list
 List of active agents. More...
 
vector< jsonnodenode_list
 List of active Nodes. More...
 
deque< messstrucmessage_queue
 Ring buffer for incoming messages. More...
 
size_t message_head = 100
 Last message placed in message ring buffer. More...
 
size_t message_tail = 100
 Last message rad in message ring buffer. More...
 
uint16_t debug_level = 0
 Flag for level of debugging, keep it public so that it can be controlled from the outside. More...
 
string nodeName
 
string agentName
 
vector< beatstrucslist
 

Private Member Functions

void heartbeat_loop ()
 Heartbeat Loop. More...
 
void request_loop () noexcept
 Request Loop. More...
 
int32_t process_request (string &bufferin, string &bufferout)
 
void message_loop ()
 
char * parse_request (char *input)
 

Static Private Member Functions

static int32_t req_forward (string &request, string &response, Agent *agent)
 Built-in Forward request. More...
 
static int32_t req_echo (string &request, string &response, Agent *agent)
 Built-in Echo request. More...
 
static int32_t req_help (string &request, string &response, Agent *agent)
 
static int32_t req_help_json (string &request, string &response, Agent *agent)
 Built-in Help request. More...
 
static int32_t req_shutdown (string &request, string &response, Agent *agent)
 Built-in Set state to Shutdown request. More...
 
static int32_t req_idle (string &request, string &response, Agent *agent)
 Built-in Set state to Idle request. More...
 
static int32_t req_init (string &request, string &response, Agent *agent)
 Built-in Set state to Init request. More...
 
static int32_t req_monitor (string &request, string &response, Agent *agent)
 Built-in Set state to Monitor request. More...
 
static int32_t req_reset (string &request, string &response, Agent *agent)
 Built-in Set state to Reset request. More...
 
static int32_t req_run (string &request, string &response, Agent *agent)
 Built-in Set state to Run request. More...
 
static int32_t req_status (string &request, string &response, Agent *agent)
 Built-in Status request. More...
 
static int32_t req_debug_level (string &request, string &response, Agent *agent)
 
static int32_t req_getvalue (string &request, string &response, Agent *agent)
 Built-in Get Internal Value request. More...
 
static int32_t req_get_value (string &request, string &response, Agent *agent)
 
static int32_t req_get_time (string &request, string &response, Agent *agent)
 
static int32_t req_get_position (string &request, string &response, Agent *agent)
 
static int32_t req_get_position_data (string &request, string &response, Agent *agent)
 
static int32_t req_setvalue (string &request, string &response, Agent *agent)
 Built-in Set Internal Value request. More...
 
static int32_t req_set_value (string &request, string &response, Agent *agent)
 
static int32_t req_listnames (string &request, string &response, Agent *agent)
 Built-in List Name Space Names request. More...
 
static int32_t req_nodejson (string &request, string &response, Agent *agent)
 Built-in Return Node JSON request. More...
 
static int32_t req_statejson (string &request, string &response, Agent *agent)
 Built-in Return State Vector JSON request. More...
 
static int32_t req_utcstartjson (string &request, string &response, Agent *agent)
 Built-in Return UTC Start Time JSON request. More...
 
static int32_t req_piecesjson (string &request, string &response, Agent *agent)
 Built-in Return Pieces JSON request. More...
 
static int32_t req_vertexsjson (string &request, string &response, Agent *agent)
 Built-in Return Vertex JSON request. More...
 
static int32_t req_facesjson (string &request, string &response, Agent *agent)
 Built-in Return Face JSON request. More...
 
static int32_t req_devgenjson (string &request, string &response, Agent *agent)
 Built-in Return devgen JSON request. More...
 
static int32_t req_devspecjson (string &request, string &response, Agent *agent)
 Built-in Return devspec JSON request. More...
 
static int32_t req_portsjson (string &request, string &response, Agent *agent)
 Built-in Return Ports JSON request. More...
 
static int32_t req_targetsjson (string &request, string &response, Agent *agent)
 Built-in Return Target JSON request. More...
 
static int32_t req_heartbeat (string &request, string &response, Agent *agent)
 Built-in Send Heartbeat request. More...
 
static int32_t req_postsoh (string &request, string &response, Agent *agent)
 
static int32_t req_utc (string &request, string &response, Agent *agent)
 
static int32_t req_soh (string &, string &response, Agent *agent)
 
static int32_t req_fullsoh (string &, string &response, Agent *agent)
 
static int32_t req_jsondump (string &, string &response, Agent *agent)
 

Private Attributes

NetworkType networkType = NetworkType::UDP
 
double activeTimeout = 0.0
 
uint32_t bufferSize = AGENTMAXBUFFER
 
bool multiflag = false
 
int32_t portNumber = 0
 
FILE * debug_fd = nullptr
 
string debug_pathName
 
string version = "2.0"
 
double timeoutSec = 2.0
 
bool logTime = true
 
double timeStart
 
string hbjstring
 
thread cthread
 Handle for request thread. More...
 
thread hthread
 Handle for heartbeat thread. More...
 
thread mthread
 Handle for message thread. More...
 
int32_t error_value
 Last error. More...
 
mutex process_mutex
 mutex to protect process_request More...
 
double(* agent_time_producer )() = currentmjd
 Function in which we generate our time, for the mjd request. More...
 
vector< request_entryreqs
 
DeviceCpu deviceCpu_
 

Member Enumeration Documentation

enum Cosmos::Support::Agent::State : uint16_t
strong
Enumerator
SHUTDOWN 

Shut down Agent.

INIT 

Agent Initializing.

IDLE 

Do minimal necessary to run.

RUN 

Run without monitoring.

MONITOR 

Run with monitoring.

ASAFE 

Agent in Safe State.

DEBUG 

Agent in Debug State.

RESET 

Reset Agent.

159  : uint16_t {
161  SHUTDOWN=0,
163  INIT,
165  IDLE,
167  RUN,
169  MONITOR,
171  ASAFE,
173  DEBUG,
175  RESET
176  };
enum Cosmos::Support::Agent::AgentMessage : uint8_t
strong

Type of Agent Message. Types > 127 are binary.

Enumerator
ALL 

All Message types.

BEAT 

Heartbeat Messages.

SOH 

State of Health Messages.

GENERIC 

Generic Mesages.

TIME 
LOCATION 
TRACK 
IMU 
EVENT 

Event Messsages.

REQUEST 

Request message.

RESPONSE 

Response message.

BINARY 

>= 128 are binary

COMM 
216  : uint8_t {
218  ALL=1,
220  BEAT=2,
222  SOH=3,
224  GENERIC=4,
225  TIME=5,
226  LOCATION=6,
227  TRACK=7,
228  IMU=8,
230  EVENT=9,
232  REQUEST=10,
234  RESPONSE=11,
236  BINARY=128,
237  COMM=129
238  };
Definition: inflate.h:23
Inertial Measurement Unit.
Definition: jsondef.h:496
enum Cosmos::Support::Agent::Where : size_t
strong
Enumerator
HEAD 
TAIL 
240  : size_t {
241  HEAD = 0,
242  TAIL = 1
243  };
Definition: inflate.h:21

Member Function Documentation

void Cosmos::Support::Agent::get_ip ( char *  buffer,
size_t  buflen 
)
void Cosmos::Support::Agent::get_ip_list ( uint16_t  port)
int Cosmos::Support::Agent::json_map_agentstruc ( agentstruc **  agent)
int32_t Cosmos::Support::Agent::send ( uint8_t  address,
string  message 
)
int32_t Cosmos::Support::Agent::receive ( uint8_t  address,
string &  message 
)
int32_t Cosmos::Support::Agent::receiveAll ( uint8_t  address,
string &  message 
)
void Cosmos::Support::Agent::log ( string  log_entry)
bool Cosmos::Support::Agent::setSoh ( string  sohFields)
char* Cosmos::Support::Agent::parse_request ( char *  input)
private

Member Data Documentation

vector<jsonentry*> Cosmos::Support::Agent::sohtable

State of Health element vector.

vector<jsonentry*> Cosmos::Support::Agent::fullsohtable
pollstruc Cosmos::Support::Agent::metaRx
string Cosmos::Support::Agent::metaHeader
cosmosstruc* Cosmos::Support::Agent::cinfo
vector<beatstruc> Cosmos::Support::Agent::agent_list

List of active agents.

vector<jsonnode> Cosmos::Support::Agent::node_list

List of active Nodes.

deque<messstruc> Cosmos::Support::Agent::message_queue

Ring buffer for incoming messages.

size_t Cosmos::Support::Agent::message_head = 100

Last message placed in message ring buffer.

size_t Cosmos::Support::Agent::message_tail = 100

Last message rad in message ring buffer.

uint16_t Cosmos::Support::Agent::debug_level = 0

Flag for level of debugging, keep it public so that it can be controlled from the outside.

string Cosmos::Support::Agent::nodeName
string Cosmos::Support::Agent::agentName
vector<beatstruc> Cosmos::Support::Agent::slist
NetworkType Cosmos::Support::Agent::networkType = NetworkType::UDP
private
double Cosmos::Support::Agent::activeTimeout = 0.0
private
uint32_t Cosmos::Support::Agent::bufferSize = AGENTMAXBUFFER
private
bool Cosmos::Support::Agent::multiflag = false
private
int32_t Cosmos::Support::Agent::portNumber = 0
private
FILE* Cosmos::Support::Agent::debug_fd = nullptr
private
string Cosmos::Support::Agent::debug_pathName
private
string Cosmos::Support::Agent::version = "2.0"
private
double Cosmos::Support::Agent::timeoutSec = 2.0
private
bool Cosmos::Support::Agent::logTime = true
private
double Cosmos::Support::Agent::timeStart
private
string Cosmos::Support::Agent::hbjstring
private
thread Cosmos::Support::Agent::cthread
private

Handle for request thread.

thread Cosmos::Support::Agent::hthread
private

Handle for heartbeat thread.

thread Cosmos::Support::Agent::mthread
private

Handle for message thread.

int32_t Cosmos::Support::Agent::error_value
private

Last error.

mutex Cosmos::Support::Agent::process_mutex
private

mutex to protect process_request

double(* Cosmos::Support::Agent::agent_time_producer) () = currentmjd
private

Function in which we generate our time, for the mjd request.

vector<request_entry> Cosmos::Support::Agent::reqs
private
DeviceCpu Cosmos::Support::Agent::deviceCpu_
private

The documentation for this class was generated from the following files: