int subCmd_logView(int argc, char **argv, qi::ApplicationSession& app) { po::options_description desc("Usage: qicli log-view"); desc.add_options() ("help,h", "Print this help message and exit") ("verbose,v", "Set maximum logs verbosity shown to verbose.") ("debug,d", "Set maximum logs verbosity shown to debug.") ("level,l", po::value<int>()->default_value(4), "Change the log minimum level: [0-6] (default:4). This option accepts the same arguments' format than --qi-log-level.") ("filters,f", po::value<std::string>(), "Set log filtering options. This option accepts the same arguments' format than --qi-log-filters.") ; po::variables_map vm; if (!poDefault(po::command_line_parser(argc, argv).options(desc), vm, desc)) return 1; qiLogVerbose() << "Connecting to service directory"; app.start(); qi::SessionPtr s = app.session(); qiLogVerbose() << "Resolving services"; qi::AnyObject logger = s->service("LogManager"); qi::AnyObject listener = logger.call<qi::AnyObject>("getListener"); listener.call<void>("clearFilters"); if (vm.count("level")) { int level = vm["level"].as<int>(); if (level > 6) level = 6; else if (level <= 0) level = 0; listener.call<void>("addFilter", "*", level); } if (vm.count("verbose")) listener.call<void>("addFilter", "*", 5); if (vm.count("debug")) listener.call<void>("addFilter", "*", 6); if (vm.count("filters")) { std::string filters = vm["filters"].as<std::string>(); setFilter(filters, listener); } listener.connect("onLogMessage", &onMessage); app.run(); return 0; }
SessionHelper::SessionHelper(qi::ApplicationSession& app) : _session(app.session()) { app.start(); _servicesInfos = _session->services(); }
int subCmd_logSend(int argc, char **argv, qi::ApplicationSession& app) { po::options_description desc("Usage: qicli log-send <message>"); desc.add_options() ("help,h", "Print this help message and exit") ("verbose,v", "Set sent message verbosity to verbose.") ("debug,d", "Set sent message verbosity to debug.") ("level,l", po::value<int>()->default_value(4), "Change the log minimum level: [0-6] (default:4). This option accepts the same arguments' format than --qi-log-level.") ("category,c", po::value<std::string>(), "Message's category (default: \"qicli.qilog.logsend\").") ("message,m", po::value<std::string>(), "Message to send.") ; po::positional_options_description positionalOptions; positionalOptions.add("message", -1); po::variables_map vm; if (!poDefault(po::command_line_parser(argc, argv) .options(desc).positional(positionalOptions), vm, desc)) return 1; qiLogVerbose() << "Connecting to service directory"; app.start(); qi::SessionPtr s = app.session(); qiLogVerbose() << "Resolving services"; qi::AnyObject logger = s->service("LogManager"); qi::os::timeval tv(qi::SystemClock::now()); std::string source(__FILE__); source += ':'; source += __FUNCTION__; source += ':'; source += boost::lexical_cast<std::string>(__LINE__); int level = 4; if (vm.count("level")) { level = vm["level"].as<int>(); if (level > 6) level = 6; else if (level <= 0) level = 0; } if (vm.count("verbose")) level = 5; if (vm.count("debug")) level = 6; std::string category = "qicli.qilog.logsend"; if (vm.count("category")) category = vm["category"].as<std::string>(); std::string location = qi::os::getMachineId() + ":" + boost::lexical_cast<std::string>(qi::os::getpid());; std::string message = ""; if (vm.count("message")) message = vm["message"].as<std::string>(); // timestamp qi::AnyReferenceVector timeVectRef; timeVectRef.push_back(qi::AnyReference::from(tv.tv_sec)); timeVectRef.push_back(qi::AnyReference::from(tv.tv_usec)); qi::AnyValue timeVal = qi::AnyValue::makeTuple(timeVectRef); qi::AnyReferenceVector msgVectRef; msgVectRef.push_back(qi::AnyReference::from(source)); msgVectRef.push_back(qi::AnyReference::from(level)); msgVectRef.push_back(timeVal.asReference()); //timestamp msgVectRef.push_back(qi::AnyReference::from(category)); msgVectRef.push_back(qi::AnyReference::from(location)); msgVectRef.push_back(qi::AnyReference::from(message)); msgVectRef.push_back(qi::AnyReference::from(0)); std::vector<qi::AnyValue> msgs; msgs.push_back(qi::AnyValue::makeTuple(msgVectRef)); logger.call<void>("log", qi::AnyValue::from(msgs)); logger.reset(); return 0; }
int subCmd_trace(int argc, char **argv, qi::ApplicationSession& app) { po::options_description desc("Usage: qicli trace [<ServicePattern>..]"); std::vector<std::string> serviceList; desc.add_options() ("numeric,n", po::bool_switch(&numeric), "Do not resolve slot Ids to names") ("full,f", po::bool_switch(&full), "Do not abreviate anything") ("service,s", po::value<std::vector<std::string> >(&objectNames), "Object(s) to monitor, specify multiple times, comma-separate, use '*' for all, use '-globPattern' to remove from list") ("print,p", po::bool_switch(&printMo), "Print out the Metaobject and exit") ("disable,d", po::bool_switch(&disableTrace), "Disable trace on objects and exit") ("trace-status", po::bool_switch(&traceState), "Show trace status on objects and exit"); po::positional_options_description positionalOptions; positionalOptions.add("service", -1); po::variables_map vm; if (!poDefault(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions), vm, desc)) return 1; qiLogVerbose() << "Connecting to service directory"; app.start(); qi::SessionPtr s = app.session(); qiLogVerbose() << "Resolving services"; std::vector<std::string> allServices; std::vector<qi::ServiceInfo> si = s->services(); for (unsigned i=0; i<si.size(); ++i) allServices.push_back(si[i].name()); std::vector<std::string> services = parseServiceList(objectNames, allServices); std::vector<std::string> servicesOk; qiLogVerbose() << "Fetching services: " << boost::join(services, ","); // access services for (unsigned i=0; i<services.size(); ++i) { qi::AnyObject o; try { o = s->service(services[i]); } catch (const std::exception& e) { qiLogError() << "Error fetching " << services[i] << " : " << e.what(); services[i] = ""; continue; } if (!o) { qiLogError() << "Error fetching " << services[i]; services[i] = ""; continue; } objectMap[services[i]] = o; servicesOk.push_back(services[i]); if (printMo) { std::cout << "\n\n" << services[i] << "\n"; qi::details::printMetaObject(std::cout, o.metaObject()); } if (disableTrace) { try { o.call<void>("enableTrace", false); } catch(...) {} } if (traceState) { try { bool s = o.call<bool>("isTraceEnabled"); std::cout << services[i] << ": " << s << std::endl; } catch(...) {} } } if (printMo || disableTrace || traceState || objectMap.empty()) return 0; qiLogVerbose() << "Monitoring services: " << boost::join(servicesOk, ","); foreach(ObjectMap::value_type& ov, objectMap) { maxServiceLength = std::max(maxServiceLength, (unsigned int)ov.first.size()); ov.second.connect("traceObject", (boost::function<void(qi::EventTrace)>) boost::bind(&onTrace, ov, _1)).async(); }