Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPutMessage.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 
4 #include "Jeep/JParser.hh"
5 #include "Jeep/JMessage.hh"
6 #include "JNet/JControlHost.hh"
7 
8 
9 /**
10  * \file
11  *
12  * Auxiliary program to send message to ControlHost server.
13  *
14  * The option <tt>-H <hostname>[:port]</tt> correponds to the hostname and the port of the server, respectively.
15  * The option <tt>-t</tt> corresponds to the ControlHost tag.
16  * The option <tt>-m <message></tt> corresponds to the message (should be quoted "" if it consists of multiple tokens).
17  * \author mdejong
18  */
19 int main(int argc, const char *argv[])
20 {
21  using namespace std;
22 
23  string hostname;
24  JNET::JTag tag;
25  string message;
26  bool use_cin;
27  int debug;
28 
29  try {
30 
31  JParser<> zap("Auxiliary program to send message to ControlHost server.");
32 
33  zap['H'] = make_field(hostname) = "localhost";
34  zap['t'] = make_field(tag);
35  zap['m'] = make_field(message) = "";
36  zap['c'] = make_field(use_cin);
37  zap['d'] = make_field(debug) = 3;
38 
39  zap(argc, argv);
40  }
41  catch(const exception &error) {
42  FATAL(error.what() << endl);
43  }
44 
45 
46  using namespace JPP;
47 
48  JControlHost::Throw(true);
49 
50  try {
51 
52  JControlHost out(hostname);
53 
54  if (!use_cin)
55 
56  out.PutFullString(tag, message);
57 
58  else {
59 
60  for ( ; ; ) {
61 
62  cout << "> " << flush;
63 
64  getline(cin, message);
65 
66  if (message != "")
67  out.PutFullString(tag, message);
68  else
69  break;
70  }
71  }
72  }
73  catch(const JControlHostException& error) {
74  ERROR(error << endl);
75  }
76 }
77 
78 
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define ERROR(A)
Definition: JMessage.hh:66
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
ControlHost tag.
Definition: JTag.hh:38
int debug
debug level