19 int main(
int argc,
char* argv[])
32 JParser<> zap(
"Example program to test communication with JControlHost server.");
36 zap[
'm'] =
make_field(message) =
"hello world";
44 catch(
const exception &error) {
45 FATAL(error.what() << endl);
49 const string pid = argv[0];
53 JControlHost socket(hostname);
55 DEBUG(
"Subscription: " << tag << endl);
60 socket.Subscribe(JSubscriptionAny(tag));
63 socket.Subscribe(JSubscriptionAll(tag));
66 socket.SendMeAlways();
68 DEBUG(
"Send message: "
69 <<
"tag <" << tag <<
"> "
70 <<
"string <" << message <<
">" << endl);
72 socket.PutFullString(tag, message);
75 DEBUG(
"Test GetFullString()." << endl);
80 for (useconds_t i = 0; i != 10000; ++i) {
82 if (socket.CheckHead(prefix) > 0) {
85 <<
"time " << i <<
" us "
86 <<
"tag <" << prefix.getTag() <<
"> "
87 <<
"length " << prefix.getSize() << endl);
90 socket.GetFullString(buffer);
92 NOTICE(
"string <" << buffer <<
">" << endl);
103 if (prefix.toString() ==
"") {
104 FATAL(
"Timeout." << endl);
110 DEBUG(
"Test WhereIs()." << endl);
114 ControlHost::WhereIs(hostname, pid, answer);
116 istringstream is(answer);
118 for (
string buffer; is >> buffer; ) {
120 NOTICE(
"Host: " << buffer << endl);
129 DEBUG(
"Test Throw(true)." << endl);
135 ControlHost::Throw(
true);
137 socket.PutFullString(tag[0], message);
141 catch(
const JException& error) {
143 NOTICE(
"Exception test: " << error.what() << endl);
149 DEBUG(
"Test Throw(false)." << endl);
151 ControlHost::Throw(
false);
153 int retcd = socket.PutFullString(tag[0], message);
155 NOTICE(
"Return code test: " << retcd << endl);
159 catch(
const JSocketException& error) {
160 NOTICE(
"Exception test failed: " << error.what() << endl);
163 catch(
const JSocketException& error) {
164 FATAL(error.what() << endl);
int getIPnumber(const std::string &host_name)
Get IP number.
Utility class to parse command line options.
#define ASSERT(A)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
General purpose messaging.
std::string getHostname()
Get host name.
Utility class to parse command line options.
Hostname and IP address functions.
#define DEBUG(A)
Message macros.
int main(int argc, char *argv[])