COSMOS core
1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
|
Class to manage information about a queue of Events. More...
#include <command_queue.h>
Public Member Functions | |
~CommandQueue () | |
Ensure all threads are joined before destruction. More... | |
size_t | join_event_threads () |
Join all threads spawn and empty our vector. More... | |
size_t | get_event_size () |
Retrieve the size of the queue. More... | |
Event & | get_event (int i) |
Retrieve an Event by its position in the queue. More... | |
size_t | get_command_size () |
Retrieve the size of the queue. More... | |
Event & | get_command (int i) |
Retrieve an Event by its position in the queue. More... | |
int32_t | load_commands (string incoming_dir) |
Load queue of Events from a file. More... | |
int32_t | save_commands (string temp_dir, string name=".queue") |
Save the queue of Events to a file. More... | |
int32_t | restore_commands (string temp_dir, string name=".queue") |
Restore the queue of Events from a file. More... | |
int32_t | run_command (Event &cmd, string nodename, double logdate_exec) |
Run the given Event. More... | |
int32_t | run_commands (Agent *agent, string nodename, double logdate_exec) |
Traverse the entire queue of Events, clearing those that have finished. More... | |
int32_t | add_command (Event &c) |
Remove all matching Event from the queue. More... | |
int32_t | del_command (Event &c) |
Remove all matching Event from the queue. More... | |
int32_t | del_command (int pos) |
Remove Event from the queue based on position. More... | |
void | sort () |
Sort the Events in the queue by Event exectution time. More... | |
Private Attributes | |
std::list< Event > | commands |
std::deque< Event > | events |
vector< std::thread > | event_threads |
bool | queue_changed = false |
bool | queue_blocked = false |
Friends | |
std::ostream & | operator<< (std::ostream &out, CommandQueue &cmdq) |
Extraction operator. More... | |
Class to manage information about a queue of Events.
Cosmos::Support::CommandQueue::~CommandQueue | ( | ) |
Ensure all threads are joined before destruction.
size_t Cosmos::Support::CommandQueue::join_event_threads | ( | ) |
Join all threads spawn and empty our vector.
|
inline |
Retrieve the size of the queue.
|
inline |
|
inline |
Retrieve the size of the queue.
|
inline |
int32_t Cosmos::Support::CommandQueue::load_commands | ( | string | incoming_dir | ) |
Load queue of Events from a file.
Loads new commands from *.command files located in the incoming directory.
Reads new Events from *.command files in the incoming directory, adds them to the queue of Events, and deletes the *.command files. Events in the queue are then sorted by their execution time.
incoming_dir | Directory where the .queue file will be read from |
Commands are loaded into the global CommandQueue object (cmd_queue), .command files are removed, and the command list is sorted by utc.
incoming_dir | Directory where the .command files will be read from |
int32_t Cosmos::Support::CommandQueue::save_commands | ( | string | temp_dir, |
string | name = ".queue" |
||
) |
Save the queue of Events to a file.
Save the queue of Events to the file temp_dir/.queue
\param temp_dir Directory where the .queue file will be written
Commands are taken from the global command queue Command queue is sorted by utc after loading
temp_dir | Directory where the .queue file will be written |
name | File where the .queue will be written |
int32_t Cosmos::Support::CommandQueue::restore_commands | ( | string | temp_dir, |
string | name = ".queue" |
||
) |
Restore the queue of Events from a file.
Save the queue of Events to the file temp_dir/.queue
\param temp_dir Directory where the .queue file will be written
Commands are taken from the global command queue Command queue is sorted by utc after loading
temp_dir | Directory where the .queue file will be read from |
name | File where the .queue will be read from |
int32_t Cosmos::Support::CommandQueue::run_command | ( | Event & | cmd, |
string | node_name, | ||
double | logdate_exec | ||
) |
Run the given Event.
Execute an event using ford(). For each event run, the time of execution (utcexec) is set, the flag EVENT_FLAG_ACTUAL is set to true, and this updated command information is logged to the OUTPUT directory.
\param cmd Reference to event to run \param nodename Name of node \param logdate_exec Time of execution (for logging purposes)
Executes a command in a separate shell (system) using threads. For each command run, the time of execution (utcexec) is set, the flag EVENT_FLAG_ACTUAL is set to true, and this updated command information is logged to the OUTPUT directory.
cmd | Reference to event to run |
nodename | Name of node |
logdate_exec | Time of execution (for logging purposes) |
int32_t Cosmos::Support::CommandQueue::run_commands | ( | Agent * | agent, |
string | node_name, | ||
double | logdate_exec | ||
) |
Traverse the entire queue of Events, clearing those that have finished.
Traverse the entire queue of Events, and run those which qualify.
An Event qualifies to be cleared if its thread could be joined, or if it has been running for more than 1 minute.
\param agent Pointer to Agent object (for call to condition_true(..)) \param nodename Name of the node \param logdate_exec Time of execution (for logging purposes)
Traverse the entire queue of Events, and run those which qualify.
An Event only qualifies to run if the current time is greater than or equal to the execution time of the Event. Further, if the Event is conditional, then the Event condition must be true.
\param agent Pointer to Agent object (for call to condition_true(..)) \param nodename Name of the node \param logdate_exec Time of execution (for logging purposes)
An Event only qualifies to run if the current time is greater than or equal to the execution time of the Event. Further, if the Event is conditional, then the Event condition must be true.
\param agent Pointer to Agent object (for call to condition_true(..)) \param nodename Name of the node \param logdate_exec Time of execution (for logging purposes)
int32_t Cosmos::Support::CommandQueue::add_command | ( | Event & | c | ) |
int32_t Cosmos::Support::CommandQueue::del_command | ( | Event & | c | ) |
int32_t Cosmos::Support::CommandQueue::del_command | ( | int | pos | ) |
Remove Event from the queue based on position.
pos | Position of event to remove |
This function removes events based on their queue position (0-indexed).
|
inline |
Sort the Events in the queue by Event exectution time.
This function is called after new Events are loaded.
|
friend |
Extraction operator.
out | Reference to ostream |
cmdq | Reference to CommandQueue (JIMNOTE: should be const, ya?) |
Writes the given CommandQueue to the given output stream (in JSON format) and returns a reference to the modified ostream.
|
private |
An std::list of members of the Event class to be run
|
private |
An std::queue of members of the Event class that have run
|
private |
A vector of all threads spawned to run events
|
private |
A boolean indicator that the queue has changed
|
private |