Example #1
0
void iProtoServiceServer::processInternal() {
  wrappers::net::util::ServerPacketHandler packetHandler;
  while (m_running) {
    m_server.update(packetHandler);

    const ServerPacketHandler::tPacketList packets = packetHandler.getPackets();
    std::vector<ProcessRunner> runners;
    runners.reserve(packets.size());
    for (ServerPacketHandler::tPacketList::const_iterator packet = packets.begin(); packet != packets.end(); ++packet) {
      runners.push_back(ProcessRunner(m_server, packet->first, packet->second, ProcessRunner::tProc::from_method<iProtoServiceServer, &iProtoServiceServer::process>(this)));
    }
    for (u32 idx = 0; idx < packets.size(); ++idx) {
      m_workerPool.execute(&runners[idx]);
    }
    m_workerPool.wait();

    core::thread::thisthread::yield();
  }
}
bool ChangeWirelessCmd::ChangeWirelessTask::execute()
{
    std::string ip = robot->getBestIP();


    context().printLine(robot->name + ": changing wpa_supplicant config to " + toString(config));
    std::string command = remoteCommand("setprofile " + toString(config), ip);
    ProcessRunner r(context(), fromString(command));
    r = ProcessRunner(context(), fromString(command));
    r.run();
    if(r.error())
    {
        context().errorLine(robot->name + ": change wireless failed.");
        return false;
    }
    context().printLine(robot->name + ": change wireless finished.");
    return true;

}
Example #3
0
bool RestartCmd::RestartTask::execute()
{
  std::string ip = robot->getBestIP(context());

  context().printLine("restart: using ip " + ip + " for " + robot->name + ".");

  if(type < SINGLE_COMMANDS)
  {
    if(type == BHUMAND)
    {
      std::string command = remoteCommand("bhumand restart", ip);
      ProcessRunner r(context(), command);
      r.run();
      reportStatus(r);
    }
    else if(type == NAOQID)
    {
      std::string command = remoteCommand("sudo /etc/init.d/naoqi restart", ip);
      ProcessRunner r(context(), command);
      r.run();
      if(r.error())
      {
        context().errorLine(robot->name + ": Could not restart Naoqi.");
        return false;
      }
      else context().printLine(robot->name + ": restarted Naoqi.");
    }
    else if(type == ROBOT)
    {
      std::string command = remoteCommand("reboot", ip);
      ProcessRunner r(context(), command);
      r.run();
      reportStatus(r);
    }
    else
    {
      context().errorLine("Unkown restart command.");
      return false;
    }
  }
  else if(type == BHUMAND_AND_NAOQID)
  {
    std::string command = remoteCommand("bhumand stop", ip);
    ProcessRunner r(context(), command);
    r.run();
    if(r.error())
    {
      context().errorLine(robot->name + ": Failed to stop bhumand.");
      return false;
    }
    else
    {
      context().printLine(robot->name + ": bhumand stopped");
    }
    context().printLine(robot->name + ": waiting 2 seconds");
    Sleeper::msleep(2000);

    command = remoteCommand("sudo /etc/init.d/naoqi restart", ip);
    r = ProcessRunner(context(), command);
    r.run();
    if(r.error())
    {
      context().errorLine(robot->name + ": Failed to restart naoqid.");
      return false;
    }
    else context().printLine(robot->name + ": naoqid restarted");
    context().printLine(robot->name + ": waiting 2 seconds");
    Sleeper::msleep(2000);

    command = remoteCommand("bhumand start", ip);
    r = ProcessRunner(context(), command);
    r.run();
    if(r.error())
    {
      context().errorLine(robot->name + ": Failed to start bhumand.");
      return false;
    }
    else context().printLine(robot->name + ": bhumand started");
    context().printLine(robot->name + ": waiting 2 seconds");
    Sleeper::msleep(2000);
    context().printLine(robot->name + ": Done");
  }
  else
  {
    context().errorLine("Unkown restart command.");
    return false;
  }

  return true;
}