#include #include #include #include #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JTimekeeper.hh" #include "JSystem/JTime.hh" #include "JNet/JControlHost.hh" /** * \file * * Auxiliary program to send messages to ControlHost server. * * The option -H \[:port] correponds to the hostname and the port of the server, respectively. * The options -t and -T correspond to the ControlHost tag(s) for free and all subscription, respectively. * The option -R corresponds to the rate at which messages will be sent. * \author mdejong */ int main(int argc, const char *argv[]) { using namespace std; using namespace JPP; string hostname; JTag tag; JTag Tag; double rate_Hz; int numberOfEvents; int size; int debug; try { JParser<> zap("Auxiliary program to send messages to ControlHost server."); zap['H'] = make_field(hostname) = "localhost"; zap['t'] = make_field(tag) = DISPTAG_UNDEFINED; zap['T'] = make_field(Tag) = DISPTAG_UNDEFINED; zap['R'] = make_field(rate_Hz); zap['n'] = make_field(numberOfEvents) = numeric_limits::max(); zap['s'] = make_field(size) = 1024; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (tag == DISPTAG_UNDEFINED && Tag == DISPTAG_UNDEFINED) { FATAL("No tags specified."); } JControlHost::Throw(true); try { JControlHost out(hostname); JTimekeeper timer((long long int) (1.0e6 / rate_Hz)); vector buffer(size); for (int i = 0; i != size; ++i) { buffer[i] = 'a' + (i%26); } int all = 0; int few = 0; timer.reset(); const long long int t0 = getLocalTime(); for (int i = 1; i <= numberOfEvents; ++i) { if (Tag != DISPTAG_UNDEFINED) { out.PutFullData(Tag, buffer.data(), buffer.size()); ++all; } if (tag != DISPTAG_UNDEFINED) { out.PutFullData(tag, buffer.data(), buffer.size()); ++few; } if (i%100 == 0) { const long long int t1 = getLocalTime(); DEBUG("Time [us] " << setw(10) << t1 - t0 << endl); DEBUG(" [us] " << setw(10) << timer.getDelay() / i << endl); DEBUG("Count all " << setw(10) << all << endl); DEBUG("Count few " << setw(10) << few << endl); } timer.wait(); } } catch(const JControlHostException& error) { ERROR(error << endl); } }