<commit_before>/*
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2012 Aldebaran Robotics
*/

#include <iostream>
#include <iomanip>
#include <istream>
#include <sstream>

#include <qitype/genericobject.hpp>
#include <qi/future.hpp>
#include <qimessaging/session.hpp>

qi::Session session;
std::map<const std::string, qi::ObjectPtr> services;

typedef std::vector<std::string> command;

static int calcOffsetMethod(const qi::MetaObject::MethodMap &mmaps) {
  qi::MetaObject::MethodMap::const_iterator it;
  int max = 0;
  for (it = mmaps.begin(); it != mmaps.end(); ++it) {
    int cur = it->second.sigreturn().size();
    if (cur > max)
      max = cur;
  }
  return max;
}

static int calcOffsetSignal(const qi::MetaObject::SignalMap &mmaps) {
  qi::MetaObject::SignalMap::const_iterator it;
  int max = 0;
  for (it = mmaps.begin(); it != mmaps.end(); ++it) {
    int cur = it->second.signature().size();
    if (cur > max)
      max = cur;
  }
  return max;
}

/****************
*    SERVICE    *
****************/
static void cmd_service(const command           &cmd,
                        command::const_iterator &it)
{
  if (it == cmd.end())
  {
    std::cerr << "service: not enough parameters" << std::endl;
    return;
  }

  std::vector<qi::ServiceInfo> servs = session.services();
  for (unsigned int i = 0; i < servs.size(); ++i)
  {
    if (servs[i].name() != *it)
      continue;
    std::cout << servs[i].name() << std::endl
              << "  id:       " << servs[i].serviceId() << std::endl
              << "  machine:  " << servs[i].machineId() << std::endl
              << "  process:  " << servs[i].processId() << std::endl
              << "  endpoints:" << std::endl;
    for (std::vector<std::string>::const_iterator it2 = servs[i].endpoints().begin();
         it2 != servs[i].endpoints().end();
         ++it2)
    {
      std::cout << "    " << *it2 << std::endl;
    }

    std::cout << "  methods:" << std::endl;
    qi::Future<qi::ObjectPtr> fut = session.service(*it);
    if (fut.hasError()) {
      std::cerr << "service: could not get object: " << fut.error() << std::endl;
      continue;
    }

    qi::ObjectPtr obj = fut.value();
    services[*it] = obj;

    const qi::MetaObject &mobj = obj->metaObject();
    qi::MetaObject::MethodMap methods = mobj.methodMap();
    int offset = calcOffsetMethod(methods);
    qi::MetaObject::MethodMap::const_iterator it2;
    for (it2 = methods.begin(); it2 != methods.end(); ++it2) {
      std::cout << "    " << std::right << std::setfill('0') << std::setw(2) << it2->second.uid() << std::setw(0) << " "
                << std::left << std::setfill(' ') << std::setw(offset) << it2->second.sigreturn() << std::setw(0)
                << " " << it2->second.signature() << std::endl;
    }
    std::cout << "  events:" << std::endl;
    qi::MetaObject::SignalMap events = mobj.signalMap();
    qi::MetaObject::SignalMap::const_iterator it3;
    offset = calcOffsetSignal(events);
    for (it3 = events.begin(); it3 != events.end(); ++it3) {
      std::cout << "    " << std::right << std::setfill('0') << std::setw(2) << it2->second.uid() << std::setw(0) << " "
                << it3->second.signature() << std::endl;
    }
  }
}

/****************
*    SERVICES   *
****************/
static void cmd_services(const command           &cmd,
                         command::const_iterator &QI_UNUSED(it))
{
  bool enum_all = false;
  if (std::find(cmd.begin(), cmd.end(), "-v") != cmd.end())
    enum_all = true;
  std::vector<qi::ServiceInfo> servs = session.services();
  for (unsigned int i = 0; i < servs.size(); ++i)
  {
    std::cout << "[" << servs[i].serviceId() << "] "
              << servs[i].name() << std::endl;
    if (enum_all) {
      command ncmd;
      command::const_iterator it;

      ncmd.push_back(servs[i].name());
      it = ncmd.begin();
      cmd_service(ncmd, it);
      std::cout << std::endl;<commit_msg>qicli: fix events display<commit_after>/*
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2012 Aldebaran Robotics
*/

#include <iostream>
#include <iomanip>
#include <istream>
#include <sstream>

#include <qitype/genericobject.hpp>
#include <qi/future.hpp>
#include <qimessaging/session.hpp>

qi::Session session;
std::map<const std::string, qi::ObjectPtr> services;

typedef std::vector<std::string> command;

static int calcOffsetMethod(const qi::MetaObject::MethodMap &mmaps) {
  qi::MetaObject::MethodMap::const_iterator it;
  int max = 0;
  for (it = mmaps.begin(); it != mmaps.end(); ++it) {
    int cur = it->second.sigreturn().size();
    if (cur > max)
      max = cur;
  }
  return max;
}

/****************
*    SERVICE    *
****************/
static void cmd_service(const command           &cmd,
                        command::const_iterator &it)
{
  if (it == cmd.end())
  {
    std::cerr << "service: not enough parameters" << std::endl;
    return;
  }

  std::vector<qi::ServiceInfo> servs = session.services();
  for (unsigned int i = 0; i < servs.size(); ++i)
  {
    if (servs[i].name() != *it)
      continue;
    std::cout << servs[i].name() << std::endl
              << "  id:       " << servs[i].serviceId() << std::endl
              << "  machine:  " << servs[i].machineId() << std::endl
              << "  process:  " << servs[i].processId() << std::endl
              << "  endpoints:" << std::endl;
    for (std::vector<std::string>::const_iterator it2 = servs[i].endpoints().begin();
         it2 != servs[i].endpoints().end();
         ++it2)
    {
      std::cout << "    " << *it2 << std::endl;
    }

    std::cout << "  methods:" << std::endl;
    qi::Future<qi::ObjectPtr> fut = session.service(*it);
    if (fut.hasError()) {
      std::cerr << "service: could not get object: " << fut.error() << std::endl;
      continue;
    }

    qi::ObjectPtr obj = fut.value();
    services[*it] = obj;

    const qi::MetaObject &mobj = obj->metaObject();
    qi::MetaObject::MethodMap methods = mobj.methodMap();
    int offset = calcOffsetMethod(methods);
    qi::MetaObject::MethodMap::const_iterator it2;
    for (it2 = methods.begin(); it2 != methods.end(); ++it2) {
      std::cout << "    " << std::right << std::setfill('0') << std::setw(3) << it2->second.uid() << std::setw(0) << " "
                << std::left << std::setfill(' ') << std::setw(offset) << it2->second.sigreturn() << std::setw(0)
                << " " << it2->second.signature() << std::endl;
    }
    std::cout << "  events:" << std::endl;
    qi::MetaObject::SignalMap events = mobj.signalMap();
    qi::MetaObject::SignalMap::const_iterator it3;
    for (it3 = events.begin(); it3 != events.end(); ++it3) {
      std::cout << "    " << std::right << std::setfill('0') << std::setw(3) << it3->second.uid() << std::setw(0) << " "
                << std::left << std::setfill(' ') << std::setw(offset) << "" << std::setw(0)
                << " " << it3->second.signature() << std::endl;
    }
  }
}

/****************
*    SERVICES   *
****************/
static void cmd_services(const command           &cmd,
                         command::const_iterator &QI_UNUSED(it))
{
  bool enum_all = false;
  if (std::find(cmd.begin(), cmd.end(), "-v") != cmd.end())
    enum_all = true;
  std::vector<qi::ServiceInfo> servs = session.services();
  for (unsigned int i = 0; i < servs.size(); ++i)
  {
    std::cout << "[" << servs[i].serviceId() << "] "
              << servs[i].name() << std::endl;
    if (enum_all) {
      command ncmd;
      command::const_iterator it;

      ncmd.push_back(servs[i].name());
      it = ncmd.begin();
      cmd_service(ncmd, it);
      std::cout << std::endl;
{'fraction_non_alphanumeric': 0.22073841319717202, 'fraction_numerical': 0.008379156847342237, 'mean_word_length': 2.9074168797953965, 'pattern_counts': {'":': 0, '<': 271, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5774742', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2598, 'n_words': 506}