Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JClientList.hh
Go to the documentation of this file.
1#ifndef __JRUNCONTROL__JCLIENTLIST__
2#define __JRUNCONTROL__JCLIENTLIST__
3
4#include <vector>
5#include <algorithm>
6
7#include "chsm.h"
8
10
11
12/**
13 * \author mdejong
14 */
15
16namespace KM3NETDAQ {
17
18
19 /**
20 * List of clients.
21 */
23 public std::vector<JClient>
24 {
25 protected:
26 /**
27 * Auxiliary class for comparing clients.
28 */
30 public:
31 /**
32 * Less than operator.
33 * The full names of the clients are used for the comparison.
34 *
35 * \param first first client
36 * \param second second client
37 * \return true is first less than second; else false
38 */
39 inline bool operator()(const JClient& first, const JClient& second) const
40 {
41 return first.getFullName() < second.getFullName();
42 }
43
44
45 /**
46 * Less than operator.
47 * The full names of the client is used for the comparison.
48 *
49 * \param client client
50 * \param full_name full name
51 * \return true is client's full name less than full name; else false
52 */
53 inline bool operator()(const JClient& client, const std::string& full_name) const
54 {
55 return client.getFullName() < full_name;
56 }
57 };
58
60
61
62 public:
63 /**
64 * Default constructor.
65 */
67 std::vector<JClient>(),
68 comparator()
69 {}
70
71
72 /**
73 * Insert client.
74 *
75 * \param client client
76 * \return iterator to client and true if inserted; else false
77 */
79 {
80 iterator i = std::lower_bound(this->begin(), this->end(), client, comparator);
81
82 if (i == this->end() || comparator(client, *i)) {
83
84 i = std::vector<JClient>::insert(i, client);
85
86 return std::make_pair(i, true);
87
88 } else {
89
90 return std::make_pair(i, false);
91 }
92 }
93
94
95 /**
96 * Find client.
97 *
98 * \param client client
99 * \return iterator to client
100 */
101 iterator find(const JClient& client)
102 {
103 iterator i = std::lower_bound(this->begin(), this->end(), client, comparator);
104
105 if (i != this->end() && !comparator(*i, client))
106 return i;
107 else
108 return this->end();
109 }
110
111
112 /**
113 * Find client by its full name.
114 *
115 * \param buffer full name of client (possibly followed by more text)
116 * \return position of client (or end)
117 */
118 iterator find(const std::string& buffer)
119 {
120 const std::string full_name = getFullName(buffer);
121
122 iterator i = std::lower_bound(this->begin(), this->end(), full_name, comparator);
123
124 if (i != this->end() && !comparator(*i, full_name))
125 return i;
126 else
127 return this->end();
128 }
129
130
131 /**
132 * Start processes.
133 */
134 void start()
135 {
136 for (iterator i = this->begin(); i != this->end(); ++i) {
137 if (i->getMode() == JClient::ACTIVE) {
138 i->start();
139 }
140 }
141 }
142
143
144 /**
145 * Stop processes.
146 *
147 * \param signal signal
148 */
149 void stop(const int signal = -9)
150 {
151 for (iterator i = this->begin(); i != this->end(); ++i) {
152 if (i->getBorn() > i->getDied()) {
153 i->stop(signal);
154 }
155 }
156 }
157
158
159 /**
160 * Get number of clients with given mode.
161 *
162 * \param mode mode
163 * \return number of clients
164 */
165 unsigned int count(const JClient::JMode mode) const
166 {
167 unsigned int n = 0;
168
169 for (const_iterator i = this->begin(); i != this->end(); ++i) {
170 if (i->getMode() == mode) {
171 ++n;
172 }
173 }
174
175 return n;
176 }
177
178
179 /**
180 * Get number of active clients with born count exceeding died count.
181 *
182 * \return number of clients
183 */
184 unsigned int count() const
185 {
186 unsigned int n = 0;
187
188 for (const_iterator i = this->begin(); i != this->end(); ++i) {
189 if (i->getMode() == JClient::ACTIVE && i->getBorn() > i->getDied()) {
190 ++n;
191 }
192 }
193
194 return n;
195 }
196
197
198 /**
199 * Get number of active clients in given state.
200 *
201 * \param state state
202 * \return number of clients
203 */
204 unsigned int count(const CHSM::state& state) const
205 {
206 unsigned int n = 0;
207
208 for (const_iterator i = this->begin(); i != this->end(); ++i) {
209 if (i->getMode() == JClient::ACTIVE && i->getStatename() == getStateName(state.name())) {
210 ++n;
211 }
212 }
213
214 return n;
215 }
216 };
217}
218
219#endif
List of ControlHost client managers.
Definition JLigier.cc:479
ControlHost client manager.
Definition JLigier.cc:245
Auxiliary class for comparing clients.
bool operator()(const JClient &first, const JClient &second) const
Less than operator.
bool operator()(const JClient &client, const std::string &full_name) const
Less than operator.
void stop(const int signal=-9)
Stop processes.
unsigned int count(const JClient::JMode mode) const
Get number of clients with given mode.
iterator find(const std::string &buffer)
Find client by its full name.
void start()
Start processes.
std::pair< iterator, bool > insert(const JClient &client)
Insert client.
unsigned int count(const CHSM::state &state) const
Get number of active clients in given state.
unsigned int count() const
Get number of active clients with born count exceeding died count.
const JComparator comparator
JClientList()
Default constructor.
iterator find(const JClient &client)
Find client.
JMode
Client modi.
Definition JClient.hh:39
const int n
Definition JPolint.hh:791
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
std::string getStateName(const std::string &name)
Get name of state.