COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
command_queue.h
Go to the documentation of this file.
1 /*!******************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 #ifndef COSMOS_CommandQueue_H
31 #define COSMOS_CommandQueue_H
32 
37 
42 #include "support/configCosmos.h"
43 #include "support/jsonlib.h"
44 #include "agent/agentclass.h"
45 #include "agent/event.h"
46 
47 namespace Cosmos
48 {
49  namespace Support
50  {
51  namespace Command
52  {
53  int32_t Shell(string command_line="", string outpath="", string inpath="", string errpath="");
54  }
55 
58  {
59  private:
61  std::list<Event> commands;
63  std::deque<Event> events;
65  vector<std::thread> event_threads;
67  bool queue_changed = false;
68 
69  bool queue_blocked = false;
70 
71  public:
73  ~CommandQueue();
74 
76  size_t join_event_threads();
77 
79 
82  size_t get_event_size() { return events.size(); }
83 
85 
90  {
91  std::deque<Event>::iterator ii = events.begin();
92  std::advance(ii,i);
93  return *ii;
94  }
95 
97 
100  size_t get_command_size() { return commands.size(); }
101 
103 
108  {
109  std::list<Event>::iterator ii = commands.begin();
110  std::advance(ii,i);
111  return *ii;
112  }
113 
115 
124  int32_t load_commands(string incoming_dir);
125 
127 
132  int32_t save_commands(string temp_dir, string name=".queue");
133 
135 
140  int32_t restore_commands(string temp_dir, string name=".queue");
141 
143 
152  int32_t run_command(Event &cmd, string nodename, double logdate_exec);
153 
155 
164 // int32_t flush_commands();
165 
167 
177  int32_t run_commands(Agent *agent, string nodename, double logdate_exec);
178 
180 
186  int32_t add_command(Event& c);
187 
189 
195  int32_t del_command(Event& c);
196 
198 
204  int32_t del_command(int pos);
205 
207 
210  void sort() { commands.sort([](Event & c1, Event & c2) { return c1.getTime() < c2.getTime(); }); }
212 
220  friend std::ostream& operator<<(std::ostream& out, CommandQueue& cmdq);
221 
222 
223  }; // end of Command Queue Class
224  } // end of namespace Support
225 } // end of namepsace Cosmos
226 
227 #endif // COSMOS_CommandQueue_H
static string incoming_dir
Definition: agent_exec-2-0.cpp:143
Definition: agentclass.cpp:54
Event & get_event(int i)
Retrieve an Event by its position in the queue.
Definition: command_queue.h:89
static double logdate_exec
Definition: agent_exec-2-0.cpp:77
Class to manage Event information.
Definition: event.h:57
void sort()
Sort the Events in the queue by Event exectution time.
Definition: command_queue.h:210
Event & get_command(int i)
Retrieve an Event by its position in the queue.
Definition: command_queue.h:107
int i
Definition: rw_test.cpp:37
static string temp_dir
Definition: agent_exec-2-0.cpp:146
vector< std::thread > event_threads
Definition: command_queue.h:65
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: agent_001.cpp:45
Definition: agentclass.h:139
JSON Support definitions.
Headers and definitions common to all COSMOS.
string getTime()
Retrieves Event::mjd.
Definition: event.h:131
string name
Definition: cubesat2obj.cpp:6
Agent Server and Client header file.
std::deque< Event > events
Definition: command_queue.h:63
Class to manage information about a queue of Events.
Definition: command_queue.h:57
size_t get_command_size()
Retrieve the size of the queue.
Definition: command_queue.h:100
int32_t Shell(string command_line, string outpath, string inpath, string errpath)
Definition: command_queue.cpp:43
string nodename
Definition: agent_add_soh.cpp:54
std::ostream & operator<<(std::ostream &out, CommandQueue &cmdq)
Extraction operator.
Definition: command_queue.cpp:547
Commanding Class.
size_t get_event_size()
Retrieve the size of the queue.
Definition: command_queue.h:82
std::list< Event > commands
Definition: command_queue.h:61