Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Functions
JDAQClientStarter.cc File Reference

Auxiliary program to start (remote) run control client. More...

#include <string>
#include <iostream>
#include <unistd.h>
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JNet/JControlHost.hh"
#include "JDAQ/JDAQTags.hh"

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Detailed Description

Auxiliary program to start (remote) run control client.

This program makes a connection to a specific port number on the given host with a preset timeout. The option -H <hostname>[:port] correponds to the hostname and the port of the client, respectively. The option -m <message> corresponds to the argument list provided to method enter of the client.

Author
mdejong

Definition in file JDAQClientStarter.cc.

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 21 of file JDAQClientStarter.cc.

22 {
23  using namespace std;
24  using namespace JPP;
25 
26  JHostname hostname;
27  string message;
28  int timeout_s;
29  int debug;
30 
31  try {
32 
33  JParser<> zap("Auxiliary program to start (remote) run control client.");
34 
35  zap['H'] = make_field(hostname);
36  zap['m'] = make_field(message);
37  zap['t'] = make_field(timeout_s) = 10; // [s]
38  zap['d'] = make_field(debug) = 3;
39 
40  zap(argc, argv);
41  }
42  catch(const exception &error) {
43  FATAL(error.what() << endl);
44  }
45 
46 
47  using namespace KM3NETDAQ;
48 
49  JControlHost::Throw(true);
50 
51  try {
52 
53  JControlHost starter(hostname);
54 
55  string tag;
56  long long int length = 0;
57 
58  bool is_alive = false;
59 
60  for (int i = 0; i != timeout_s; ++i) {
61 
62  is_alive = (starter.CheckHead(tag, length) > 0);
63 
64  if (!is_alive)
65  sleep(1);
66  else
67  break;
68  }
69 
70  if (is_alive) {
71 
72  {
73  char buffer[length];
74 
75  starter.GetFullData(buffer, length);
76 
77  const string version(buffer, length);
78 
79  DEBUG("Current version " << CHOO_VERSION << endl);
80  DEBUG("Received version " << version << endl);
81 
82  if (version != CHOO_VERSION) {
83  WARNING("Version mis-match: " << version << " " << CHOO_VERSION << endl);
84  }
85  }
86 
87  DEBUG("Send message " << message << endl);
88 
89  starter.PutFullString(RC_STRT, message);
90 
91  {
92  starter.WaitHead(tag, length);
93 
94  char buffer[length];
95 
96  starter.GetFullData(buffer, length);
97 
98  DEBUG("Got reply " << string(buffer,length) << endl);
99  }
100 
101  } else {
102  ERROR("Timeout at connecting to " << hostname << " after " << timeout_s << " s." << endl);
103  }
104  }
105  catch(const JControlHostException& error) {
106  ERROR(error << endl);
107  }
108 }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define WARNING(A)
Definition: JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Exception for ControlHost.
Definition: JException.hh:486
ControlHost class.
Utility class to parse command line options.
Definition: JParser.hh:1698
static const std::string CHOO_VERSION
Definition: JControlHost.hh:34
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
static const JNET::JTag RC_STRT
Definition: JDAQTags.hh:65
Definition: JSTDTypes.hh:14
Auxiliary data structure for hostname and port number.
Definition: JHostname.hh:35