Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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...
 
int getEventnumber () const
 Get number of last event. 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
 
int event_number
 

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 27 of file JClient.hh.

Member Enumeration Documentation

Client modi.

Enumerator
UNKNOWN 
SLEEP 
ACTIVE 
IGNORE 
ILLEGAL 

Definition at line 38 of file JClient.hh.

Constructor & Destructor Documentation

KM3NETDAQ::JClient::JClient ( )
inline

Default constructor.

Definition at line 44 of file JClient.hh.

44  :
45  name (),
46  hostname (),
47  start_command(),
48  mode(UNKNOWN),
49  born(0),
50  died(0),
51  is_alive(false),
52  state_name("?"),
53  event_name("?"),
54  event_number(-1)
55  {}
std::string event_name
Definition: JClient.hh:495
JLANG::JString start_command
Definition: JClient.hh:488
std::string state_name
Definition: JClient.hh:494
then echo n User name
Definition: JCookie.sh:45
std::string hostname
Definition: JClient.hh:487
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 65 of file JClient.hh.

67  :
68  name (__name),
69  hostname (__hostname),
70  start_command(__start_command),
71  mode(UNKNOWN),
72  born(0),
73  died(0),
74  is_alive(false),
75  state_name("?"),
76  event_name("?"),
77  event_number(-1)
78  {
79  configure();
80  }
std::string event_name
Definition: JClient.hh:495
JLANG::JString start_command
Definition: JClient.hh:488
std::string state_name
Definition: JClient.hh:494
then echo n User name
Definition: JCookie.sh:45
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
std::string hostname
Definition: JClient.hh:487

Member Function Documentation

void KM3NETDAQ::JClient::start ( )
inline

Start process.

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

Definition at line 87 of file JClient.hh.

88  {
89  using namespace std;
90  using namespace JPP;
91 
92  if (start_command != "") {
93 
94  JShell& shell = JShell::getInstance();
95 
96  shell << start_command << endl;
97  shell.flush();
98  }
99  }
static JShell & getInstance()
Get reference to unique instance of this class object.
Definition: JShell.hh:76
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 110 of file JClient.hh.

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

Get name of run control client.

Returns
name

Definition at line 173 of file JClient.hh.

174  {
175  return name;
176  }
then echo n User name
Definition: JCookie.sh:45
const std::string& KM3NETDAQ::JClient::getHostname ( ) const
inline

Get host name of run control client.

Returns
host name

Definition at line 184 of file JClient.hh.

185  {
186  return hostname;
187  }
std::string hostname
Definition: JClient.hh:487
const std::string& KM3NETDAQ::JClient::getFullName ( ) const
inline

Get full name of run control client.

Returns
full name

Definition at line 195 of file JClient.hh.

196  {
197  return full_name;
198  }
std::string full_name
Definition: JClient.hh:489
const std::string& KM3NETDAQ::JClient::getStartCommand ( ) const
inline

Get start command of run control client.

Returns
name

Definition at line 206 of file JClient.hh.

207  {
208  return start_command;
209  }
JLANG::JString start_command
Definition: JClient.hh:488
bool KM3NETDAQ::JClient::isSleep ( ) const
inline

Check sleep mode.

Returns
true if sleep; else false

Definition at line 217 of file JClient.hh.

218  {
219  return mode == SLEEP;
220  }
bool KM3NETDAQ::JClient::isActive ( ) const
inline

Check active mode.

Returns
true if active; else false

Definition at line 228 of file JClient.hh.

229  {
230  return mode == ACTIVE;
231  }
bool KM3NETDAQ::JClient::isIgnore ( ) const
inline

Check ignore mode.

Returns
true if ignore; else false

Definition at line 239 of file JClient.hh.

240  {
241  return mode == IGNORE;
242  }
bool KM3NETDAQ::JClient::isIllegal ( ) const
inline

Check illegal mode.

Returns
true if illegal; else false

Definition at line 250 of file JClient.hh.

251  {
252  return mode == ILLEGAL;
253  }
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 264 of file JClient.hh.

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

Get name of current state.

Returns
state name

Definition at line 316 of file JClient.hh.

317  {
318  return state_name;
319  }
std::string state_name
Definition: JClient.hh:494
const std::string& KM3NETDAQ::JClient::getEventname ( ) const
inline

Get name of last event.

Returns
event name

Definition at line 327 of file JClient.hh.

328  {
329  return event_name;
330  }
std::string event_name
Definition: JClient.hh:495
int KM3NETDAQ::JClient::getEventnumber ( ) const
inline

Get number of last event.

Returns
event number

Definition at line 338 of file JClient.hh.

339  {
340  return event_number;
341  }
bool KM3NETDAQ::JClient::getAlive ( ) const
inline

Get alive status.

Returns
true if alive; else false

Definition at line 349 of file JClient.hh.

350  {
351  return is_alive;
352  }
void KM3NETDAQ::JClient::setAlive ( const bool  alive)
inline

Set alive status.

Parameters
alivealive

Definition at line 360 of file JClient.hh.

361  {
362  is_alive = alive;
363  }
JMode KM3NETDAQ::JClient::getMode ( ) const
inline

Get mode.

Returns
mode

Definition at line 371 of file JClient.hh.

372  {
373  return mode;
374  }
void KM3NETDAQ::JClient::setMode ( const JMode  mode)
inline

Set mode.

Parameters
modemode

Definition at line 382 of file JClient.hh.

383  {
384  this->mode = mode;
385  }
int KM3NETDAQ::JClient::getBorn ( ) const
inline

Get born count.

Returns
number of times born

Definition at line 393 of file JClient.hh.

394  {
395  return born;
396  }
int KM3NETDAQ::JClient::getDied ( ) const
inline

Get died count.

Returns
number of times died

Definition at line 404 of file JClient.hh.

405  {
406  return died;
407  }
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 464 of file JClient.hh.

465  {
466  using std::string;
467 
469 
471  start_command = start_command.replace(" ", " ");
472 
473  start_command.replace("$HOST$", hostname);
474  start_command.replace("$NAME$", name);
475  start_command.replace("$SERVER$", SERVER);
476  start_command.replace("$LOGGER$", LOGGER);
477 
478  string::size_type pos = name.find_last_of(CLIENTNAME_DELIMETER);
479 
480  if (pos != string::npos) {
481  start_command.replace("$ARGS$", name.substr(pos + 1));
482  }
483  }
then usage $script[host[local file]] fi case set_variable LOGGER
Definition: JStopDAQ.sh:28
std::string full_name
Definition: JClient.hh:489
JLANG::JString start_command
Definition: JClient.hh:488
JString & trim()
Trim string.
Definition: JString.hh:229
static const std::string CLIENTNAME_DELIMETER
Definition: JDAQTags.hh:37
then echo n User name
Definition: JCookie.sh:45
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
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
then usage $script fi SERVER

Friends And Related Function Documentation

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

Read client from input.

Parameters
inistream
clientclient
Returns
istream

Definition at line 417 of file JClient.hh.

418  {
419  in >> client.name;
420  in >> client.hostname;
421 
422  if (in) {
423 
424  getline(in >> std::ws, client.start_command);
425 
426  in.clear(); // clear error state of input stream if no start command is available.
427 
428  client.configure();
429  }
430 
431  return in;
432  }
then echo Test string reversed by client(hit< return > to continue)." JProcess -c "JEcho-r" -C fi if (( 1 ))
JSocketInputChannel_t in
reader for incoming messages
Definition: JLigier.cc:438
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
virtual void clear()
Clear status of reader.
std::ostream& operator<< ( std::ostream &  out,
const JClient client 
)
friend

Write client to output.

Parameters
outostream
clientclient
Returns
ostream

Definition at line 442 of file JClient.hh.

443  {
444  out << client.name;
445  out << ' ';
446  out << client.hostname;
447  out << ' ';
448  out << client.start_command;
449 
450  return out;
451  }
JSocketNonblockingWriter out
writer for outgoing messages
Definition: JLigier.cc:439
then echo Test string reversed by client(hit< return > to continue)." JProcess -c "JEcho-r" -C fi if (( 1 ))

Member Data Documentation

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

host name of message server

Author
mdejonghost name of message server

Definition at line 31 of file JClient.hh.

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

host name of message logger

Definition at line 32 of file JClient.hh.

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

Definition at line 486 of file JClient.hh.

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

Definition at line 487 of file JClient.hh.

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

Definition at line 488 of file JClient.hh.

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

Definition at line 489 of file JClient.hh.

JMode KM3NETDAQ::JClient::mode
protected

Definition at line 490 of file JClient.hh.

int KM3NETDAQ::JClient::born
protected

Definition at line 491 of file JClient.hh.

int KM3NETDAQ::JClient::died
protected

Definition at line 492 of file JClient.hh.

bool KM3NETDAQ::JClient::is_alive
protected

Definition at line 493 of file JClient.hh.

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

Definition at line 494 of file JClient.hh.

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

Definition at line 495 of file JClient.hh.

int KM3NETDAQ::JClient::event_number
protected

Definition at line 496 of file JClient.hh.


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