Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
KM3NETDAQ::JClient Class Reference

Client data structure. More...

#include <JClient.hh>

Public Types

enum  JMode {
  UNKNOWN = -1 , SLEEP = 0 , ACTIVE , IGNORE = -2 ,
  ILLEGAL = -3
}
 Client modi. More...
 

Public Member Functions

 JClient ()
 Default constructor. More...
 
 JClient (const std::string &__name, const std::string &__hostname, const std::string &__start_command="")
 Constructor. More...
 
void start ()
 Start process. More...
 
void stop (const int signal=-9)
 Stop process. More...
 
const std::string & getName () const
 Get name of run control client. More...
 
const std::string & getHostname () const
 Get host name of run control client. More...
 
const std::string & getFullName () const
 Get full name of run control client. More...
 
const std::string & getStartCommand () const
 Get start command of run control client. More...
 
bool isSleep () const
 Check sleep mode. More...
 
bool isActive () const
 Check active mode. More...
 
bool isIgnore () const
 Check ignore mode. More...
 
bool isIllegal () const
 Check illegal mode. More...
 
bool update (const JNET::JTag &tag, const std::string &buffer)
 Update client. More...
 
const std::string & getStatename () const
 Get name of current state. More...
 
const std::string & getEventname () const
 Get name of last event. More...
 
const std::string & getEventInfo () const
 Get event information. More...
 
bool getAlive () const
 Get alive status. More...
 
void setAlive (const bool alive)
 Set alive status. More...
 
JMode getMode () const
 Get mode. More...
 
void setMode (const JMode mode)
 Set mode. More...
 
int getBorn () const
 Get born count. More...
 
int getDied () const
 Get died count. More...
 

Static Public Attributes

static std::string SERVER
 host name of message server More...
 
static std::string LOGGER
 host name of message logger More...
 

Protected Member Functions

void configure ()
 Configure client parameters. More...
 

Protected Attributes

std::string name
 
std::string hostname
 
JLANG::JString start_command
 
std::string full_name
 
JMode mode
 
int born
 
int died
 
bool is_alive
 
std::string state_name
 
std::string event_name
 
std::string event_info
 

Friends

std::istream & operator>> (std::istream &in, JClient &client)
 Read client from input. More...
 
std::ostream & operator<< (std::ostream &out, const JClient &client)
 Write client to output. More...
 

Detailed Description

Client data structure.

Definition at line 28 of file JClient.hh.

Member Enumeration Documentation

◆ JMode

Client modi.

Enumerator
UNKNOWN 
SLEEP 
ACTIVE 
IGNORE 
ILLEGAL 

Definition at line 39 of file JClient.hh.

Constructor & Destructor Documentation

◆ JClient() [1/2]

KM3NETDAQ::JClient::JClient ( )
inline

Default constructor.

Definition at line 45 of file JClient.hh.

45  :
46  name (),
47  hostname (),
48  start_command(),
49  mode(UNKNOWN),
50  born(0),
51  died(0),
52  is_alive(false),
53  state_name("?"),
54  event_name("?"),
55  event_info()
56  {}
std::string state_name
Definition: JClient.hh:495
std::string hostname
Definition: JClient.hh:488
JLANG::JString start_command
Definition: JClient.hh:489
std::string name
Definition: JClient.hh:487
std::string event_name
Definition: JClient.hh:496
std::string event_info
Definition: JClient.hh:497

◆ JClient() [2/2]

KM3NETDAQ::JClient::JClient ( const std::string &  __name,
const std::string &  __hostname,
const std::string &  __start_command = "" 
)
inline

Constructor.

Parameters
__namename of client
__hostnamehost name
__start_commandstart command

Definition at line 66 of file JClient.hh.

68  :
69  name (__name),
70  hostname (__hostname),
71  start_command(__start_command),
72  mode(UNKNOWN),
73  born(0),
74  died(0),
75  is_alive(false),
76  state_name("?"),
77  event_name("?"),
78  event_info()
79  {
80  configure();
81  }
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.

Member Function Documentation

◆ start()

void KM3NETDAQ::JClient::start ( )
inline

Start process.

The start command is issued on the (remote) host.

Definition at line 88 of file JClient.hh.

89  {
90  using namespace std;
91  using namespace JPP;
92 
93  if (start_command != "") {
94 
95  JShell& shell = JShell::getInstance();
96 
97  shell << start_command << endl;
98  shell.flush(cout);
99  }
100  }
The JShell clas can be used to interact with the shell via I/O streams.
Definition: JShell.hh:36
static JShell & getInstance()
Get reference to unique instance of this class object.
Definition: JShell.hh:76
JShell & flush(std::ostream &out=null)
Extracts characters from this shell and flush them to the given output stream until the prompt is rea...
Definition: JShell.hh:184
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14

◆ stop()

void KM3NETDAQ::JClient::stop ( const int  signal = -9)
inline

Stop process.

A kill command is issued on the (remote) host. To determine the PID for the kill command, the start command is compared to the output of a ps command on the (remote) host.

Parameters
signalsignal

Definition at line 111 of file JClient.hh.

112  {
113  using namespace std;
114  using namespace JPP;
115 
116  if (start_command != "") {
117 
118  const string header = "__header___";
119  const string trailer = "__trailer__";
120 
121  ostringstream os;
122 
123  os << "ssh " << hostname << ' '
124  << "\""
125  << "echo" << ' ' << header << ";"
126  << "ps hax -o '%p %a'" << ";"
127  << "echo" << ' ' << trailer
128  << "\"";
129 
130  JShell& shell = JShell::getInstance();
131 
132  shell << os.str() << endl;
133 
134  os.str("");
135 
136  string buffer;
137 
138  while (getline(shell, buffer) && buffer.find(header) == string::npos) {}
139 
140  istringstream is;
141 
142  while (getline(shell, buffer) && buffer.find(trailer) == string::npos) {
143 
144  is.clear();
145  is.str(buffer);
146 
147  int pid;
148 
149  if (is >> pid && getline(is >> ws, buffer)) {
150  if (start_command.find(buffer) != string::npos) {
151  os << "ssh " << hostname << ' '
152  << "\""
153  << "kill " << signal << " " << pid << " </dev/null >&/dev/null"
154  << "\"";
155  }
156  }
157  }
158 
159  shell.flush();
160 
161  if (os.str() != "") {
162  shell << os.str() << endl;
163  shell.flush();
164  }
165  }
166  }
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478

◆ getName()

const std::string& KM3NETDAQ::JClient::getName ( ) const
inline

Get name of run control client.

Returns
name

Definition at line 174 of file JClient.hh.

175  {
176  return name;
177  }

◆ getHostname()

const std::string& KM3NETDAQ::JClient::getHostname ( ) const
inline

Get host name of run control client.

Returns
host name

Definition at line 185 of file JClient.hh.

186  {
187  return hostname;
188  }

◆ getFullName()

const std::string& KM3NETDAQ::JClient::getFullName ( ) const
inline

Get full name of run control client.

Returns
full name

Definition at line 196 of file JClient.hh.

197  {
198  return full_name;
199  }
std::string full_name
Definition: JClient.hh:490

◆ getStartCommand()

const std::string& KM3NETDAQ::JClient::getStartCommand ( ) const
inline

Get start command of run control client.

Returns
name

Definition at line 207 of file JClient.hh.

208  {
209  return start_command;
210  }

◆ isSleep()

bool KM3NETDAQ::JClient::isSleep ( ) const
inline

Check sleep mode.

Returns
true if sleep; else false

Definition at line 218 of file JClient.hh.

219  {
220  return mode == SLEEP;
221  }

◆ isActive()

bool KM3NETDAQ::JClient::isActive ( ) const
inline

Check active mode.

Returns
true if active; else false

Definition at line 229 of file JClient.hh.

230  {
231  return mode == ACTIVE;
232  }

◆ isIgnore()

bool KM3NETDAQ::JClient::isIgnore ( ) const
inline

Check ignore mode.

Returns
true if ignore; else false

Definition at line 240 of file JClient.hh.

241  {
242  return mode == IGNORE;
243  }

◆ isIllegal()

bool KM3NETDAQ::JClient::isIllegal ( ) const
inline

Check illegal mode.

Returns
true if illegal; else false

Definition at line 251 of file JClient.hh.

252  {
253  return mode == ILLEGAL;
254  }

◆ update()

bool KM3NETDAQ::JClient::update ( const JNET::JTag tag,
const std::string &  buffer 
)
inline

Update client.

The client parameters are updated according to the ControlHost tag and message.

Parameters
tagtag
buffermessage
Returns
true if OK; else false

Definition at line 265 of file JClient.hh.

266  {
267  using namespace std;
269 
270  if (tag == JNET::DISPTAG_Born) {
271 
272  this->is_alive = true;
273  this->born += 1;
274 
275  return true;
276 
277  } else if (tag == JNET::DISPTAG_Died) {
278 
279  this->is_alive = false;
280  this->died += 1;
281 
282  return true;
283 
284  } else if (tag == RC_REPLY) {
285 
286  string key;
287  string ip;
288  string name;
289  JEvent_t event;
290  string state;
291 
292  istringstream is(buffer);
293 
294  const locale loc(is.getloc(), new JWhiteSpacesFacet(is.getloc(), TOKEN_DELIMETER));
295 
296  is.imbue(loc);
297 
298  if (is >> key >> ip >> name >> event >> state && key == RUN_CONTROL_CLIENT) {
299 
300  this->event_name = event.getName();
301  this->event_info = event.getInfo();
302  this->state_name = state;
303 
304  return true;
305  }
306  }
307 
308  return false;
309  }
Auxiliary class to specify white space character(s) in currect locale.
char * loc(char *orig)
static const JTag DISPTAG_Born("Born")
static const JTag DISPTAG_Died("Died")
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:67
static const std::string RUN_CONTROL_CLIENT
Definition: JDAQTags.hh:44
static const std::string TOKEN_DELIMETER
Definition: JDAQTags.hh:58

◆ getStatename()

const std::string& KM3NETDAQ::JClient::getStatename ( ) const
inline

Get name of current state.

Returns
state name

Definition at line 317 of file JClient.hh.

318  {
319  return state_name;
320  }

◆ getEventname()

const std::string& KM3NETDAQ::JClient::getEventname ( ) const
inline

Get name of last event.

Returns
event name

Definition at line 328 of file JClient.hh.

329  {
330  return event_name;
331  }

◆ getEventInfo()

const std::string& KM3NETDAQ::JClient::getEventInfo ( ) const
inline

Get event information.

Returns
event information

Definition at line 339 of file JClient.hh.

340  {
341  return event_info;
342  }

◆ getAlive()

bool KM3NETDAQ::JClient::getAlive ( ) const
inline

Get alive status.

Returns
true if alive; else false

Definition at line 350 of file JClient.hh.

351  {
352  return is_alive;
353  }

◆ setAlive()

void KM3NETDAQ::JClient::setAlive ( const bool  alive)
inline

Set alive status.

Parameters
alivealive

Definition at line 361 of file JClient.hh.

362  {
363  is_alive = alive;
364  }

◆ getMode()

JMode KM3NETDAQ::JClient::getMode ( ) const
inline

Get mode.

Returns
mode

Definition at line 372 of file JClient.hh.

373  {
374  return mode;
375  }

◆ setMode()

void KM3NETDAQ::JClient::setMode ( const JMode  mode)
inline

Set mode.

Parameters
modemode

Definition at line 383 of file JClient.hh.

384  {
385  this->mode = mode;
386  }

◆ getBorn()

int KM3NETDAQ::JClient::getBorn ( ) const
inline

Get born count.

Returns
number of times born

Definition at line 394 of file JClient.hh.

395  {
396  return born;
397  }

◆ getDied()

int KM3NETDAQ::JClient::getDied ( ) const
inline

Get died count.

Returns
number of times died

Definition at line 405 of file JClient.hh.

406  {
407  return died;
408  }

◆ configure()

void KM3NETDAQ::JClient::configure ( )
inlineprotected

Configure client parameters.

In this, the following tokens in the start command are substituted: $HOST$ by <host name>; $NAME$ by <process name>; $SERVER$ by JClient::SERVER; $LOGGER$ by JClient::LOGGER; $ARGS$ by part following last '/' in <process name>;

Definition at line 465 of file JClient.hh.

466  {
467  using std::string;
468 
469  full_name = KM3NETDAQ::getFullName(hostname, name);
470 
472  start_command = start_command.replace(" ", " ");
473 
474  start_command.replace("$HOST$", hostname);
475  start_command.replace("$NAME$", name);
476  start_command.replace("$SERVER$", SERVER);
477  start_command.replace("$LOGGER$", LOGGER);
478 
479  string::size_type pos = name.find_last_of(CLIENTNAME_DELIMETER);
480 
481  if (pos != string::npos) {
482  start_command.replace("$ARGS$", name.substr(pos + 1));
483  }
484  }
JString & replace(const char target, const char replacement, const std::size_t max=std::numeric_limits< std::size_t >::max())
Replace characters.
Definition: JString.hh:170
JString & trim()
Trim string.
Definition: JString.hh:229
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
static const std::string CLIENTNAME_DELIMETER
Definition: JDAQTags.hh:59

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  in,
JClient client 
)
friend

Read client from input.

Parameters
inistream
clientclient
Returns
istream

Definition at line 418 of file JClient.hh.

419  {
420  in >> client.name;
421  in >> client.hostname;
422 
423  if (in) {
424 
425  getline(in >> std::ws, client.start_command);
426 
427  in.clear(); // clear error state of input stream if no start command is available.
428 
429  client.configure();
430  }
431 
432  return in;
433  }
virtual void clear()
Clear status of reader.
JSocketInputChannel_t in
reader for incoming messages
Definition: JLigier.cc:461

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JClient client 
)
friend

Write client to output.

Parameters
outostream
clientclient
Returns
ostream

Definition at line 443 of file JClient.hh.

444  {
445  out << client.name;
446  out << ' ';
447  out << client.hostname;
448  out << ' ';
449  out << client.start_command;
450 
451  return out;
452  }
JSocketNonblockingWriter out
writer for outgoing messages
Definition: JLigier.cc:462

Member Data Documentation

◆ SERVER

std::string KM3NETDAQ::JClient::SERVER
static

host name of message server

Author
mdejong

Definition at line 32 of file JClient.hh.

◆ LOGGER

std::string KM3NETDAQ::JClient::LOGGER
static

host name of message logger

Definition at line 33 of file JClient.hh.

◆ name

std::string KM3NETDAQ::JClient::name
protected

Definition at line 487 of file JClient.hh.

◆ hostname

std::string KM3NETDAQ::JClient::hostname
protected

Definition at line 488 of file JClient.hh.

◆ start_command

JLANG::JString KM3NETDAQ::JClient::start_command
protected

Definition at line 489 of file JClient.hh.

◆ full_name

std::string KM3NETDAQ::JClient::full_name
protected

Definition at line 490 of file JClient.hh.

◆ mode

JMode KM3NETDAQ::JClient::mode
protected

Definition at line 491 of file JClient.hh.

◆ born

int KM3NETDAQ::JClient::born
protected

Definition at line 492 of file JClient.hh.

◆ died

int KM3NETDAQ::JClient::died
protected

Definition at line 493 of file JClient.hh.

◆ is_alive

bool KM3NETDAQ::JClient::is_alive
protected

Definition at line 494 of file JClient.hh.

◆ state_name

std::string KM3NETDAQ::JClient::state_name
protected

Definition at line 495 of file JClient.hh.

◆ event_name

std::string KM3NETDAQ::JClient::event_name
protected

Definition at line 496 of file JClient.hh.

◆ event_info

std::string KM3NETDAQ::JClient::event_info
protected

Definition at line 497 of file JClient.hh.


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