1 #ifndef __JRUNCONTROL__JCLIENT__
2 #define __JRUNCONTROL__JCLIENT__
67 const std::string& __hostname,
68 const std::string& __start_command =
"") :
93 if (start_command !=
"") {
97 shell << start_command << endl;
111 void stop(
const int signal = -9)
116 if (start_command !=
"") {
118 const string header =
"__header___";
119 const string trailer =
"__trailer__";
123 os <<
"ssh " << hostname <<
' '
125 <<
"echo" <<
' ' << header <<
";"
126 <<
"ps hax -o '%p %a'" <<
";"
127 <<
"echo" <<
' ' << trailer
132 shell << os.str() << endl;
138 while (
getline(shell, buffer) && buffer.find(header) == string::npos) {}
142 while (
getline(shell, buffer) && buffer.find(trailer) == string::npos) {
149 if (is >> pid &&
getline(is >> ws, buffer)) {
150 if (start_command.find(buffer) != string::npos) {
151 os <<
"ssh " << hostname <<
' '
153 <<
"kill " << signal <<
" " << pid <<
" </dev/null >&/dev/null"
161 if (os.str() !=
"") {
162 shell << os.str() << endl;
209 return start_command;
220 return mode == SLEEP;
231 return mode == ACTIVE;
242 return mode == IGNORE;
253 return mode == ILLEGAL;
272 this->is_alive =
true;
279 this->is_alive =
false;
292 istringstream is(buffer);
300 this->event_name =
event.getName();
301 this->event_info =
event.getInfo();
302 this->state_name = state;
421 in >> client.hostname;
425 getline(
in >> std::ws, client.start_command);
447 out << client.hostname;
449 out << client.start_command;
471 start_command = start_command.trim();
472 start_command = start_command.replace(
" ",
" ");
474 start_command.replace(
"$HOST$", hostname);
475 start_command.replace(
"$NAME$", name);
476 start_command.replace(
"$SERVER$", SERVER);
477 start_command.replace(
"$LOGGER$", LOGGER);
481 if (pos != string::npos) {
482 start_command.replace(
"$ARGS$", name.substr(pos + 1));
Shell interaction via I/O streams.
virtual void clear()
Clear status of reader.
Wrapper class around STL string class.
Auxiliary class to specify white space character(s) in currect locale.
ControlHost client manager.
JSocketNonblockingWriter out
writer for outgoing messages
JSocketInputChannel_t in
reader for incoming messages
The JShell clas can be used to interact with the shell via I/O streams.
static JShell & getInstance()
Get reference to unique instance of this class object.
JShell & flush(std::ostream &out=null)
Extracts characters from this shell and flush them to the given output stream until the prompt is rea...
const std::string & getHostname() const
Get host name of run control client.
int getBorn() const
Get born count.
friend std::ostream & operator<<(std::ostream &out, const JClient &client)
Write client to output.
friend std::istream & operator>>(std::istream &in, JClient &client)
Read client from input.
const std::string & getEventname() const
Get name of last event.
bool isSleep() const
Check sleep mode.
void setMode(const JMode mode)
Set mode.
bool isActive() const
Check active mode.
const std::string & getEventInfo() const
Get event information.
JLANG::JString start_command
const std::string & getStatename() const
Get name of current state.
void start()
Start process.
const std::string & getFullName() const
Get full name of run control client.
const std::string & getName() const
Get name of run control client.
const std::string & getStartCommand() const
Get start command of run control client.
bool isIgnore() const
Check ignore mode.
JMode getMode() const
Get mode.
JClient(const std::string &__name, const std::string &__hostname, const std::string &__start_command="")
Constructor.
static std::string SERVER
host name of message server
bool getAlive() const
Get alive status.
bool update(const JNET::JTag &tag, const std::string &buffer)
Update client.
static std::string LOGGER
host name of message logger
JClient()
Default constructor.
void stop(const int signal=-9)
Stop process.
int getDied() const
Get died count.
void configure()
Configure client parameters.
bool isIllegal() const
Check illegal mode.
void setAlive(const bool alive)
Set alive status.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
static const JTag DISPTAG_Born("Born")
static const JTag DISPTAG_Died("Died")
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
static const JNET::JTag RC_REPLY
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
static const std::string RUN_CONTROL_CLIENT
static const std::string TOKEN_DELIMETER
static const std::string CLIENTNAME_DELIMETER
Auxiliary class for handling event name and optional static information.