COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_004.cpp File Reference
#include "support/configCosmos.h"
#include "support/elapsedtime.h"
#include "support/timeutils.h"
#include "agent/agentclass.h"
#include <iostream>
#include <string>
Include dependency graph for agent_004.cpp:

Functions

int32_t request_hello (string &, string &response, Agent *)
 The function to handle the "hello" request. More...
 
int main (int, char **)
 agent_004 is an example of a request handler. More...
 

Variables

static int request_counter = 0
 Count of the number of requests that have been run. More...
 
static Agentagent
 The agent constructor. More...
 

Function Documentation

int32_t request_hello ( string &  ,
string &  response,
Agent  
)

The function to handle the "hello" request.

Parameters
Theresponse to send back to the requester.
Returns
int
86 {
87  response = "hello " + std::to_string(request_counter);
88 
89  cout << "agent_004 got a request! Its response is: " << response << endl;
90 
91  // add counter
93 
94  return 0;
95 }
string to_string(char *value)
Definition: stringlib.cpp:220
static int request_counter
Count of the number of requests that have been run.
Definition: agent_004.cpp:47
int main ( int  ,
char **   
)

agent_004 is an example of a request handler.

Returns
int
57 {
58  cout << "Starting agent_004" << endl;
59 
60  // Initialize agent parameters; its name and node
61  string agentname = "004"; // Forward facing name of the agent
62  string nodename = "cubesat1"; // The node that the agent will run on
63 
64  // Construct agent with above parameters
65  agent = new Agent(nodename, agentname);
66 
67  // Define the request within the agent
68  agent->add_request("request_hello", request_hello);
69 
70  // Start executing the agent
71  while(agent->running())
72  {
73  // Sleep for 1 sec
74  COSMOS_SLEEP(1.);
75  }
76 
77  return 0;
78 }
int32_t request_hello(string &request, string &response, Agent *cdata)
The function to handle the "hello" request.
Definition: agent_004.cpp:85
static Agent * agent
The agent constructor.
Definition: agent_004.cpp:50
uint16_t running()
Check if we&#39;re supposed to be running.
Definition: agentclass.cpp:391
string agentname
Definition: agent_add_soh.cpp:53
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.
Definition: agentclass.cpp:312
Definition: agentclass.h:139
string nodename
Definition: agent_add_soh.cpp:54

Variable Documentation

int request_counter = 0
static

Count of the number of requests that have been run.

Agent* agent
static

The agent constructor.