20{
   23 
   24  string  hostname;
   25  JTag    tag;
   26  string  message;
   27  bool    any;
   29 
   30  try {
   31 
   32    JParser<> zap(
"Example program to test communication with JControlHost server.");
 
   33 
   36    zap[
'm'] = 
make_field(message)         = 
"hello world";
 
   39 
   40    zap(argc, argv);
   41  }
   42  catch(const exception &error) {
   43    FATAL(error.what() << endl);
 
   44  }
   45 
   46 
   47  const string pid = argv[0];
   48 
   49  try {
   50 
   52 
   53    DEBUG(
"Subscription: " << tag << endl);
 
   54 
   55    socket.MyId(pid);
   56 
   57    if (any) {
   59    }    
   60    else {
   62    }
   63        
   64   socket.SendMeAlways();
   65 
   66    DEBUG(
"Send message: " 
   67          << "tag <"    << tag     << "> " 
   68          << "string <" << message << ">" << endl);
   69    
   70    socket.PutFullString(tag, message);
   71 
   72    {
   73      DEBUG(
"Test GetFullString()." << endl);
 
   74 
   76      string  buffer;
   77 
   78      for (useconds_t i = 0; i != 10000; ++i) {
   79 
   80        if (socket.CheckHead(prefix) > 0) {
   81      
   83                << "time "   << i                << " us " 
   84                << 
"tag <"   << prefix.
getTag()  << 
"> "  
   85                << 
"length " << prefix.
getSize() << endl);
 
   86 
   87          
   88          socket.GetFullString(buffer);
   89      
   90          NOTICE(
"string <" << buffer << 
">" << endl);
 
   91 
   93 
   94          break;
   95 
   96        } else
   97 
   98          usleep(1);
   99      }
  100 
  102        FATAL(
"Timeout." << endl);
 
  103      }
  104    }
  105 
  106 
  107    {
  108      DEBUG(
"Test WhereIs()." << endl);
 
  109 
  110      string answer;
  111 
  112      ControlHost::WhereIs(hostname, pid, answer);
  113 
  114      istringstream is(answer);
  115 
  116      for (string buffer; is >> buffer; ) {
  117 
  118        NOTICE(
"Host: " << buffer << endl);
 
  119 
  121      }
  122    }
  123 
  124 
  125    try {
  126       
  127      DEBUG(
"Test Throw(true)." << endl);
 
  128     
  129      socket.close();
  130      
  131      try {
  132        
  133        ControlHost::Throw(true);
  134        
  135        socket.PutFullString(tag[0], message);
  136 
  138      }
  140 
  141        NOTICE(
"Exception test: " << error.
what() << endl);
 
  142 
  144      }
  145      
  146 
  147      DEBUG(
"Test Throw(false)." << endl);
 
  148 
  149      ControlHost::Throw(false);
  150      
  151      int retcd = socket.PutFullString(tag[0], message);
  152      
  153      NOTICE(
"Return code test: " << retcd << endl);
 
  154 
  156    }
  158      NOTICE(
"Exception test failed: " << error.
what() << endl);
 
  159    }
  160  }
  163  }
  164 
  165  return 0;
  166}
#define DEBUG(A)
Message macros.
 
#define ASSERT(A,...)
Assert macro.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
virtual const char * what() const override
Get error message.
 
int getSize() const
Get size.
 
std::string toString() const
Convert tag to string.
 
const JTag & getTag() const
Get tag.
 
Utility class to parse command line options.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
int getIPnumber(const std::string &host_name)
Get IP number.
 
std::string getHostname()
Get host name.
 
Auxiliary class for all subscription.
 
Auxiliary class for any subscription.