454int main(
int argc,
char* argv[])
457 uint32_t type =
unkn;
458 bool uses_roy =
false;
459 bool use_gui =
false;
460 bool lm_mode =
false;
462 std::string dom_names = std::getenv(
"HOME") + std::string(
"/.doms.csk");
463 dom_map_type dom_names_map;
465 std::ofstream output_file;
467 unsigned int port = 0;
469 std::string filename;
470 std::string roy_setup;
472 std::string lserver =
"localhost:5553";
474 boost::asio::ip::tcp::endpoint endpoint;
476 po::options_description desc(
"Generic options");
478 (
"help,h",
"Print this help and exit.")
479 (
"version,v",
"Print the version and exit.")
482 , po::value<std::string>(&dom_names)->value_name(
"filename")
483 ,
"File that specifies a conversion from DOM IDs to a human readable name."
486 (
"gui,g",
"Use GUI (avalilable in UDP-monitoring and Ligier modes only).")
488 (
"ligier,l",
"Set Ligier mode.")
489 (
"udp,u",
"Force UDP mode (default).");
491 po::options_description lmdesc(
"Ligier-mode options");
495 , po::value<std::string>(&lserver)
496 ->default_value(
"localhost:5553")
497 ->value_name(
"server:[port]")
498 ,
"Set the Ligier server endpoint to read data from."
502 , po::value<std::string>(&tag)
503 ->default_value(
"IO_MONIT")
505 ,
"Set the Ligier tag to read data from."
508 po::options_description umdesc(
"UDP-mode options");
511 po::value<unsigned int>(&port)
513 ->value_name(
"port"),
514 "Set the expected data type to optical. If a port is not \
515provided the default one is used (56015).")
517 po::value<unsigned int>(&port)
519 ->value_name(
"port"),
520 "Set the expected data type to acoustic. If a port is not \
521provided the default one is used (56016).")
523 po::value<unsigned int>(&port)
525 ->value_name(
"port"),
526 "Set the expected data type to monitoring. If a port is \
527not provided the default one is used (56017).")
529 po::value<unsigned int>(&port)->value_name(
"port"),
530 "Listen on the specified port, automatically determining the \
533 po::value<std::string>(&filename)->value_name(
"filename"),
534 "Dumps the acquired data to a file.")
536 po::value<std::string>(&roy_setup)
537 ->implicit_value(
"HR_%n.%c:localhost:9999")
538 ->value_name(
"format:host:port"),
539 "Send the monitoring hit rates to the specified ROyWeb \
540server. The syntax is format:server_ip:server_port. \
541The format parameter can contain the following placeholders: %d for \
542DOM ID, %n for DOM name (if available, otherwise the DOM ID is used) \
543and %c for channel ID.");
546 std::string roy_server;
550 po::options_description global;
551 global.add(desc).add(lmdesc).add(umdesc);
553 po::variables_map vm;
555 po::command_line_parser(argc, argv).options(global).run()
559 if (vm.count(
"help")) {
567 if (vm.count(
"version")) {
568 std::cout << clbsk::version::v() << std::endl;
575 use_gui = vm.count(
"gui");
578 lm_mode = vm.count(
"ligier");
580 if (lm_mode && vm.count(
"udp")) {
581 throw std::runtime_error(
"You can specify only one mode. Both provided.");
584 if (vm.count(
"map")) {
585 std::ifstream
map(dom_names.c_str());
588 throw std::runtime_error(
589 std::string(
"Error reading map file: ")
590 + std::strerror(errno)
596 std::ifstream
map(dom_names.c_str());
602 po::variables_map vm;
603 po::options_description options;
604 options.add(lmdesc).add(desc);
607 po::command_line_parser(argc, argv).options(options).run()
617 po::variables_map vm;
618 po::options_description options;
619 options.add(desc).add(umdesc);
622 po::command_line_parser(argc, argv).options(options).run()
628 unsigned int counter = 0;
629 if (vm.count(
"port")) {
633 if (vm.count(
"optical")) {
637 if (vm.count(
"acoustic")) {
641 if (vm.count(
"monitoring")) {
648 throw std::runtime_error(
"More than one port provided.");
650 throw std::runtime_error(
"You must specify at least one port.");
654 if (use_gui && type !=
tmch) {
655 throw std::runtime_error(
"GUI is only available in monitoring mode");
658 if (vm.count(
"royweb")) {
660 throw std::runtime_error(
"you can use ROyWeb only with the"
661 " monitoring channel");
665 std::replace(roy_setup.begin(), roy_setup.end(),
':',
' ');
666 std::istringstream ss(roy_setup);
671 if (ss >> roy_server) {
674 if (ss >> roy_port) {
678 if (param_count != 3) {
679 throw std::runtime_error(
"you must specify all the parameters"
680 " or accept all the default one to use with ROyWeb.");
684 if (vm.count(
"dumpfile")) {
685 output_file.open(filename.c_str(), std::ios::binary);
687 throw std::runtime_error(
688 "Unable to open file "
697 }
catch (
const po::error& e) {
699 <<
"CLBSwissKnife: Error: " << e.what() <<
'\n'
705 }
catch (
const std::runtime_error& e) {
706 std::cerr <<
"CLBSwissKnife: Error: " << e.what() << std::endl;
710 boost::asio::io_service io_service;
721 boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(1));
723 boost::asio::posix::stream_descriptor keyb(io_service, ::dup(STDIN_FILENO));
725 boost::asio::signal_set window_resize(io_service, SIGWINCH);
728 gui::ScreenInitialiser init;
730 gui::Screen screen(io_service, lserver, stats);
732 keyb.async_read_some(
733 boost::asio::buffer(&key,
sizeof(key)),
739 boost::asio::placeholders::error,
740 boost::asio::placeholders::bytes_transferred
749 boost::asio::placeholders::error
759 , clbsk::consumer::Gui(
terminal_width, dom_names_map, stats, screen)
762 window_resize.async_wait(
765 boost::ref(window_resize),
767 boost::asio::placeholders::error,
768 boost::asio::placeholders::signal_number
775 std::cout <<
"Listening from: " << endpoint <<
':' << tag <<
'\n';
776 boost::asio::signal_set signals_handler(io_service, SIGWINCH, SIGINT);
778 signals_handler.async_wait(
781 boost::ref(signals_handler),
783 boost::asio::placeholders::error,
784 boost::asio::placeholders::signal_number
800 std::cout <<
"Listening port: " << port <<
'\n' <<
"Data type: ";
803 std::cout <<
"Acoustic\n";
804 }
else if (type ==
ttdc) {
805 std::cout <<
"Optical\n";
806 }
else if (type ==
tmch) {
807 std::cout <<
"Monitoring\n";
809 std::cout <<
"Automatically determined\n";
812 clbsk::consumer::ConsumerSet consumer_set;
814 trm::MonStreamer ms(roy_server, roy_port);
822 <<
") with tag format "
823 << templ << std::endl;
826 clbsk::consumer::Roy(
835 consumer_set.add(clbsk::consumer::File(output_file));
842 boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(1));
844 boost::asio::posix::stream_descriptor keyb(io_service, ::dup(STDIN_FILENO));
846 boost::asio::signal_set window_resize(io_service, SIGWINCH);
849 gui::ScreenInitialiser init;
851 std::string
const heading
852 =
"UDP " + boost::lexical_cast<std::string>(port);
854 gui::Screen screen(io_service, heading, stats);
856 keyb.async_read_some(
857 boost::asio::buffer(&key,
sizeof(key)),
863 boost::asio::placeholders::error,
864 boost::asio::placeholders::bytes_transferred
873 boost::asio::placeholders::error
877 window_resize.async_wait(
880 boost::ref(window_resize),
882 boost::asio::placeholders::error,
883 boost::asio::placeholders::signal_number
888 clbsk::consumer::Gui(
908 clbsk::consumer::Scrollback(
915 boost::asio::signal_set signals_handler(io_service, SIGWINCH, SIGINT);
917 signals_handler.async_wait(
920 , boost::ref(signals_handler)
922 , boost::asio::placeholders::error
923 , boost::asio::placeholders::signal_number