Example #1
0
int subCmd_post(int argc, char **argv, qi::ApplicationSession& app, qi::JsonOption prettyPrint)
{
  po::options_description     desc("Usage: qicli post <ServicePattern.SignalPattern> [<JsonParameter>...]");
  std::string                 fullName;
  std::vector<std::string>    argList;

  desc.add_options()
      ("signal", po::value<std::string>(&fullName)->required(), "signal's name")
      ("arg", po::value<std::vector<std::string> >(&argList), "method's args")
      ("hidden", "post hidden signals if they match the given pattern")
      ("json", "signal parameters' will be treaded as JSON strings")
      ("almemory", "post on almemory event")
      ("help", "Print this help message and exit");

  po::positional_options_description positionalOptions;
  positionalOptions.add("signal", 1);
  positionalOptions.add("arg", -1);

  po::variables_map vm;
  if (!poDefault(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions)
                 .style(qicli_call_cmd_style), vm, desc))
    return 1;

  SessionHelper session(app, prettyPrint);

  if (vm.count("almemory"))
  {
    if (argList.empty() || argList.size() > 1)
      throw std::runtime_error("bad number of argument, almemory events only accept one argument");
   session.postOnAlmemory(fullName, argList[0], vm.count("json"));
  }
  else
    session.post(fullName, argList, vm.count("hidden"), vm.count("json"));
  return 0;
}
Example #2
0
int subCmd_call(int argc, char **argv, qi::ApplicationSession& app, qi::JsonOption prettyPrint)
{
  po::options_description     desc("Usage: qicli call <ServicePattern.MethodPattern> [<JsonParameter>...]");
  std::string                 fullName;
  std::vector<std::string>    argList;
  unsigned int                callCount = 0;

  desc.add_options()
      ("method", po::value<std::string>(&fullName)->required(), "method's name")
      ("arg", po::value<std::vector<std::string> >(&argList), "method's args")
      ("bench", po::value<unsigned int>(&callCount), "bench the call time using given iteration count")
      ("hidden", "call hidden methods if they match the given pattern")
      ("json", "method parameters' will be treaded as JSON strings")
      ("continue", "continue on error")
      ("help", "Print this help message and exit");

  po::positional_options_description positionalOptions;
  positionalOptions.add("method", 1);
  positionalOptions.add("arg", -1);

  po::variables_map vm;
  if (!poDefault(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions)
                 .style(qicli_call_cmd_style), vm, desc))
    return 1;
  SessionHelper session(app, prettyPrint);

  session.call(fullName, argList, vm.count("hidden"), vm.count("json"), vm.count("continue"), callCount);
  return 0;
}
Example #3
0
int subCmd_set(int argc, char **argv, qi::ApplicationSession& app, qi::JsonOption prettyPrint)
{
  po::options_description   desc("Usage: qicli set <ServicePattern.PropertyPattern>... <JsonParameter>");
  std::vector<std::string>  argList;

  desc.add_options()
      ("prop", po::value<std::vector<std::string> >(&argList), "property's name")
      ("hidden", "set hidden properties if they match the given pattern")
      ("json", "parameter will be treaded as a JSON string")
      ("continue", "continue on error")
      ("help", "Print this help message and exit");

  po::positional_options_description positionalOptions;
  positionalOptions.add("prop", -1);

  po::variables_map vm;
  if (!poDefault(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions)
                 .style(qicli_call_cmd_style), vm, desc))
    return 1;

  if (argList.size() < 2)
  {
    showHelp(desc);
    return 1;
  }
  std::string jsonValue = argList.back();
  argList.pop_back();

  SessionHelper session(app, prettyPrint);
  session.set(argList, jsonValue, vm.count("hidden"), vm.count("json"), vm.count("continue"));
  return 0;
}
Example #4
0
int subCmd_get(int argc, char **argv, qi::ApplicationSession& app, qi::JsonOption prettyPrint)
{
  po::options_description   desc("Usage: qicli get <ServicePattern.PropertyPattern>...");
  std::vector<std::string>  patternList;

  desc.add_options()
      ("prop,p", po::value<std::vector<std::string> >(&patternList), "property's name")
      ("hidden", "get hidden properties if they match the given pattern")
      ("continue", "continue on error")
      ("help,h", "Print this help message and exit");

  po::positional_options_description positionalOptions;
  positionalOptions.add("prop", -1);

  po::variables_map vm;
  if (!poDefault(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions), vm, desc))
    return 1;

  SessionHelper session(app, prettyPrint);

  if (patternList.empty())
      patternList.push_back("*.*");
  session.get(patternList, vm.count("hidden"), vm.count("continue"));
  return 0;
}
Example #5
0
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;
}
Example #6
0
int subCmd_info(int argc, char **argv, qi::ApplicationSession& app, qi::JsonOption prettyPrint)
{
  po::options_description     desc("Usage: qicli info [<ServicePattern>...]");
  std::vector<std::string>    serviceList;
  bool zOpt = false;

  desc.add_options()
      ("service,s", po::value<std::vector<std::string> >(&serviceList), "service to display")
      ("help,h", "Print this help message and exit")
      ("list,l", "List services (default when no service specified)")
      ("details,d", "print service info, methods, signals and properties")
      ("hidden", "show hidden services, methods, signals and properties")
      ("show-doc", "show documentation for methods, signals and properties")
      ("raw-signature", "show the raw signature")
      (",z", po::bool_switch(&zOpt), "prints the result in a parseable format");

  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;

  bool details = false;
  if (vm.count("details") && vm.count("list"))
    throw std::runtime_error("You cannot specify --list and --details together.");

  //smart details/list
  if (vm.count("details"))
    details = true;
  else if (vm.count("list"))
    details = false;
  else {
    //list/details not specified, use details if services have been specified.
    details = (serviceList.size()) != 0;
  }

  if (serviceList.empty())
    serviceList.push_back("*");

  SessionHelper session(app, prettyPrint);
  session.info(serviceList, details, vm.count("hidden"), vm.count("show-doc"), vm.count("raw-signature"), zOpt);
  return 0;
}
Example #7
0
int subCmd_watch(int argc, char **argv, qi::ApplicationSession& app, qi::JsonOption prettyPrint)
{
  po::options_description   desc("Usage: qicli watch <ServicePattern.SignalPattern>...");
  std::vector<std::string>  patternList;

  desc.add_options()
      ("signal,s", po::value<std::vector<std::string> >(&patternList), "service's name")
      ("time,t", "Print time")
      ("hidden", "watch hidden signals if they match the given pattern")
      ("continue", "continue on error")
      ("almemory", "watch ALMemory events")
      ("help,h", "Print this help message and exit");

  po::positional_options_description positionalOptions;
  positionalOptions.add("signal", -1);

  po::variables_map vm;
  if (!poDefault(po::command_line_parser(argc, argv).options(desc).positional(positionalOptions), vm, desc))
    return 1;

  SessionHelper session(app, prettyPrint);

  if (patternList.empty())
  {
    if (vm.count("almemory"))
      patternList.push_back("*");
    else
      patternList.push_back("*.*");
  }
  if (vm.count("almemory"))
    session.watchAlmemory(patternList, vm.count("time"));
  else
    session.watch(patternList, vm.count("time"), vm.count("hidden"), vm.count("continue"));
  ::getchar();
  return 0;
}
Example #8
0
int subCmd_top(int argc, char **argv, qi::ApplicationSession& app)
{
  po::options_description     desc("Usage: qicli top [-i interval] [<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-directory,s", po::value<std::string>(&sdUrl), "url to connect to")
  ("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")
  ("interval,i", po::value<float>(&interval)->default_value(1), "Poll interval in seconds");

  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.startSession();
  qi::SessionPtr s = app.session();
  qiLogVerbose() << "Resolving services";
  // resolve target service names
  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 (objectMap.empty())
    return 0;

  qiLogVerbose() << "Monitoring services: " << boost::join(servicesOk, ",");
  for(ObjectMap::value_type& ov: objectMap)
  {
    maxServiceLength = std::max(maxServiceLength, (unsigned int)ov.first.size());
    ov.second.async<void>("enableStats", true);
  }
  boost::thread t(&main_loop);
  qi::Application::atStop(boost::bind(&boost::thread::interrupt, boost::ref(t)));
  qi::Application::run();
  t.join();
  qiLogInfo() << "Disabling statistics gathering..." << std::endl;
  std::vector<qi::Future<void> > futures;
  for(ObjectMap::value_type& ov: objectMap)
  {
    futures.push_back(ov.second.async<void>("enableStats", false));
  }
  qi::waitForAll(futures);
  return 0;
}
Example #9
0
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.startSession();
  qi::SessionPtr s = app.session();

  qiLogVerbose() << "Resolving services";

  // import module
  qi::AnyModule mod = qi::import("qicore");

  // get service Logger
  qi::LogManagerPtr logger = app.session()->service("LogManager");

  qi::LogMessage msg;

  msg.source = __FILE__;
  msg.source += ':';
  msg.source += __FUNCTION__;
  msg.source += ':';
  msg.source += boost::lexical_cast<std::string>(__LINE__);

  msg.level = qi::LogLevel_Info;
  if (vm.count("level"))
  {
    int level = vm["level"].as<int>();

    if (level > 6)
      level = qi::LogLevel_Debug;
    else if (level <= 0)
      level = qi::LogLevel_Silent;

    msg.level = static_cast<qi::LogLevel>(level);
  }
  if (vm.count("verbose"))
    msg.level = qi::LogLevel_Verbose;

  if (vm.count("debug"))
    msg.level = qi::LogLevel_Debug;

  msg.category = "qicli.qilog.logsend";
  if (vm.count("category"))
    msg.category = vm["category"].as<std::string>();

  msg.location = qi::os::getMachineId() + ":" + boost::lexical_cast<std::string>(qi::os::getpid());

  if (vm.count("message"))
    msg.message = vm["message"].as<std::string>();

  msg.date = qi::Clock::now();
  msg.systemDate = qi::SystemClock::now();

  std::vector<qi::LogMessage> msgs;
  msgs.push_back(msg);
  logger->log(msgs);

  logger.reset();

  return 0;
}
Example #10
0
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;
}
Example #11
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();
  }