Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tfarmcontroller.h"
Toshihiro Shimizu 890ddd
#include "ttcpip.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfarmproxy.h"
Toshihiro Shimizu 890ddd
#include "tfilepath_io.h"
Toshihiro Shimizu 890ddd
2fc36c
#include <sstream></sstream>
Shinya Kitaoka 9eb50d
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class Controller final : public TFarmController, public TFarmProxy {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Controller(const QString &hostName, const QString &addr, int port)
Shinya Kitaoka 120a6e
      : TFarmProxy(hostName, addr, port) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // TFarmController interface implementation
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  QString addTask(const TFarmTask &task, bool suspended) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void removeTask(const QString &id) override;
Shinya Kitaoka 473e70
  void suspendTask(const QString &id) override;
Shinya Kitaoka 473e70
  void activateTask(const QString &id) override;
Shinya Kitaoka 473e70
  void restartTask(const QString &id) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void getTasks(vector<qstring> &tasks) override;</qstring>
Shinya Kitaoka 473e70
  void getTasks(const QString &parentId, vector<qstring> &tasks) override;</qstring>
Shinya Kitaoka 473e70
  void getTasks(const QString &parentId, vector<taskshortinfo> &tasks) override;</taskshortinfo>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void queryTaskInfo(const QString &id, TFarmTask &task) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void queryTaskShortInfo(const QString &id, QString &parentId, QString &name,
Shinya Kitaoka 473e70
                          TaskState &status) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void attachServer(const QString &name, const QString &addr,
Shinya Kitaoka 38fd86
                    int port) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void detachServer(const QString &name, const QString &addr,
Shinya Kitaoka 38fd86
                    int port) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void taskSubmissionError(const QString &taskId, int errCode) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void taskProgress(const QString &taskId, int step, int stepCount,
Shinya Kitaoka 473e70
                    int frameNumber, FrameState state) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void taskCompleted(const QString &taskId, int exitCode) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // fills the servers vector with the names of the servers
Shinya Kitaoka 473e70
  void getServers(vector<serveridentity> &servers) override;</serveridentity>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // returns the state of the server whose id has been specified
Shinya Kitaoka 473e70
  ServerState queryServerState2(const QString &id) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // fills info with the infoes about the server whose id has been specified
Shinya Kitaoka 473e70
  void queryServerInfo(const QString &id, ServerInfo &info) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // activates the server whose id has been specified
Shinya Kitaoka 473e70
  void activateServer(const QString &id) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // deactivates the server whose id has been specified
Shinya Kitaoka 120a6e
  // once deactivated, a server is not available for task rendering
Shinya Kitaoka 38fd86
  void deactivateServer(const QString &id,
Shinya Kitaoka 38fd86
                        bool completeRunningTasks = true) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString Controller::addTask(const TFarmTask &task, bool suspended) {
Shinya Kitaoka 120a6e
  int i, count = task.getTaskCount();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString data("addTask@TFarmTask_2");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += task.m_name;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += task.getCommandLine(true);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += task.m_user;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += task.m_hostName;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(suspended);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(task.m_stepCount);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(task.m_priority);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(task.m_platform);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  int depCount = task.m_dependencies->getTaskCount();
Shinya Kitaoka 120a6e
  data += QString::number(depCount);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  i = 0;
Shinya Kitaoka 120a6e
  for (; i < depCount; ++i) {
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += task.m_dependencies->getTaskId(i);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < count; ++i) {
Shinya Kitaoka 120a6e
    TFarmTask &tt      = const_cast<tfarmtask &="">(task);</tfarmtask>
Shinya Kitaoka 120a6e
    TFarmTask *subtask = tt.getTask(i);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += subtask->m_name;
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += subtask->getCommandLine(true);
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += subtask->m_user;
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += subtask->m_hostName;
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += QString::number(subtask->m_stepCount);
Shinya Kitaoka 120a6e
    data += ",";
Shinya Kitaoka 120a6e
    data += QString::number(subtask->m_priority);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Shinya Kitaoka 120a6e
  // MessageBox(NULL, data.c_str(), "ciao", 0);
Shinya Kitaoka 120a6e
  return reply;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::removeTask(const QString &id) {
Shinya Kitaoka 120a6e
  QString data("removeTask");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::suspendTask(const QString &id) {
Shinya Kitaoka 120a6e
  QString data("suspendTask");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::activateTask(const QString &id) {
Shinya Kitaoka 120a6e
  QString data("activateTask");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::restartTask(const QString &id) {
Shinya Kitaoka 120a6e
  QString data("restartTask");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::getTasks(vector<qstring> &tasks) {</qstring>
Shinya Kitaoka 120a6e
  QString data("getTasks@vector");
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
Shinya Kitaoka 120a6e
  vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  extractArgs(reply, argv);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tasks.clear();
Shinya Kitaoka 120a6e
  std::vector<qstring>::iterator it = argv.begin();</qstring>
Shinya Kitaoka 120a6e
  for (; it != argv.end(); ++it) tasks.push_back(*it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::getTasks(const QString &parentId, vector<qstring> &tasks) {</qstring>
Shinya Kitaoka 120a6e
  QString data("getTasks@string@vector");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += parentId;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni deiderate separate da ","
Shinya Kitaoka 120a6e
  vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  extractArgs(reply, argv);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tasks.clear();
Shinya Kitaoka 120a6e
  std::vector<qstring>::iterator it = argv.begin();</qstring>
Shinya Kitaoka 120a6e
  for (; it != argv.end(); ++it) tasks.push_back(*it);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::getTasks(const QString &parentId,
Shinya Kitaoka 120a6e
                          vector<taskshortinfo> &tasks) {</taskshortinfo>
Shinya Kitaoka 120a6e
  QString data("getTasks@string@vector$TaskShortInfo");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += parentId;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
Shinya Kitaoka 120a6e
  vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  extractArgs(reply, argv);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tasks.clear();
Shinya Kitaoka 120a6e
  std::vector<qstring>::iterator it = argv.begin();</qstring>
Shinya Kitaoka 120a6e
  for (; it != argv.end(); ++it) {
Shinya Kitaoka 120a6e
    QString id   = *it++;
Shinya Kitaoka 120a6e
    QString name = *it++;
Shinya Kitaoka 120a6e
    TaskState status;
Shinya Kitaoka 120a6e
    status = (TaskState)(*it).toInt();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    tasks.push_back(TaskShortInfo(id, name, status));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::queryTaskInfo(const QString &id, TFarmTask &task) {
Shinya Kitaoka 120a6e
  QString data("queryTaskInfo_2");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
Shinya Kitaoka 120a6e
  vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  int count = extractArgs(reply, argv);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (reply == "") return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert(argv.size() > 15);
Shinya Kitaoka 120a6e
  int incr    = 0;
Shinya Kitaoka 120a6e
  task.m_name = argv[incr++];
Shinya Kitaoka 120a6e
  task.parseCommandLine(argv[incr++]);
Shinya Kitaoka 120a6e
  task.m_priority = argv[incr++].toInt();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  task.m_user     = argv[incr++];
Shinya Kitaoka 120a6e
  task.m_hostName = argv[incr++];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  task.m_id       = argv[incr++];
Shinya Kitaoka 120a6e
  task.m_parentId = argv[incr++];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  task.m_status = (TaskState)argv[incr++].toInt();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  task.m_server         = argv[incr++];
Shinya Kitaoka 120a6e
  task.m_submissionDate = QDateTime::fromString(argv[incr++]);
Shinya Kitaoka 120a6e
  task.m_startDate      = QDateTime::fromString(argv[incr++]);
Shinya Kitaoka 120a6e
  task.m_completionDate = QDateTime::fromString(argv[incr++]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  task.m_successfullSteps = argv[incr++].toInt();
Shinya Kitaoka 120a6e
  task.m_failedSteps      = argv[incr++].toInt();
Shinya Kitaoka 120a6e
  task.m_stepCount        = argv[incr++].toInt();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (incr < count) {
Shinya Kitaoka 120a6e
    task.m_platform = (TFarmPlatform)argv[incr++].toInt();
Shinya Kitaoka 120a6e
    int depCount    = 0;
Shinya Kitaoka 120a6e
    depCount        = argv[incr++].toInt();
Shinya Kitaoka 120a6e
    if (depCount > 0) {
Shinya Kitaoka 120a6e
      task.m_dependencies = new TFarmTask::Dependencies;
Shinya Kitaoka 120a6e
      for (int i = 0; i < depCount; ++i) task.m_dependencies->add(argv[incr++]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::queryTaskShortInfo(const QString &id, QString &parentId,
Shinya Kitaoka 120a6e
                                    QString &name, TaskState &status) {
Shinya Kitaoka 120a6e
  QString data("queryTaskShortInfo");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
Shinya Kitaoka 120a6e
  vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  extractArgs(reply, argv);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(argv.size() == 3);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  parentId = argv[0];
Shinya Kitaoka 120a6e
  name     = argv[1];
Shinya Kitaoka 120a6e
  status   = (TaskState)argv[2].toInt();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::attachServer(const QString &name, const QString &addr,
Shinya Kitaoka 120a6e
                              int port) {
Shinya Kitaoka 120a6e
  QString data("attachServer");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += name;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += addr;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(port);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::detachServer(const QString &name, const QString &addr,
Shinya Kitaoka 120a6e
                              int port) {
Shinya Kitaoka 120a6e
  QString data("detachServer");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += name;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += addr;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(port);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::taskSubmissionError(const QString &taskId, int errCode) {
Shinya Kitaoka 120a6e
  QString data("taskSubmissionError");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += taskId;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(errCode);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::taskProgress(const QString &taskId, int step, int stepCount,
Shinya Kitaoka 120a6e
                              int frameNumber, FrameState state) {
Shinya Kitaoka 120a6e
  QString data("taskProgress");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += taskId;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(step);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(stepCount);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(frameNumber);
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(state);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::taskCompleted(const QString &taskId, int exitCode) {
Shinya Kitaoka 120a6e
  QString data("taskCompleted");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += taskId;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(exitCode);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::getServers(vector<serveridentity> &servers) {</serveridentity>
Shinya Kitaoka 120a6e
  QString data("getServers");
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
Shinya Kitaoka 120a6e
  vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  extractArgs(reply, argv);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  servers.clear();
Shinya Kitaoka 120a6e
  std::vector<qstring>::iterator it = argv.begin();</qstring>
Shinya Kitaoka 120a6e
  for (; it != argv.end(); it += 2)
Shinya Kitaoka 120a6e
    servers.push_back(ServerIdentity(*it, *(it + 1)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ServerState Controller::queryServerState2(const QString &name) {
Shinya Kitaoka 120a6e
  QString data("queryServerState2");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += name;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ServerState serverState = (ServerState)reply.toInt();
Shinya Kitaoka 120a6e
  return serverState;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::queryServerInfo(const QString &id, ServerInfo &info) {
Shinya Kitaoka 120a6e
  QString data("queryServerInfo");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Shinya Kitaoka 120a6e
  if (reply != "") {
Shinya Kitaoka 120a6e
    // la stringa restituita contiene le informazioni desiderate separate da ","
Shinya Kitaoka 120a6e
    vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
    extractArgs(reply, argv);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    info.m_name       = argv[0];
Shinya Kitaoka 120a6e
    info.m_ipAddress  = argv[1];
Shinya Kitaoka 120a6e
    info.m_portNumber = argv[2];
Shinya Kitaoka 120a6e
    info.m_state      = (ServerState)argv[3].toInt();
Shinya Kitaoka 120a6e
    info.m_platform   = argv[4];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int cpuCount, totPhysMem, totVirtMem, availPhysMem, availVirtMem;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    cpuCount             = argv[5].toInt();
Shinya Kitaoka 120a6e
    totPhysMem           = argv[6].toInt();
Shinya Kitaoka 120a6e
    totVirtMem           = argv[7].toInt();
Shinya Kitaoka 120a6e
    availPhysMem         = argv[8].toInt();
Shinya Kitaoka 120a6e
    availVirtMem         = argv[9].toInt();
Shinya Kitaoka 120a6e
    info.m_currentTaskId = argv[10];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    info.m_cpuCount     = cpuCount;
Shinya Kitaoka 120a6e
    info.m_totPhysMem   = totPhysMem;
Shinya Kitaoka 120a6e
    info.m_totVirtMem   = totVirtMem;
Shinya Kitaoka 120a6e
    info.m_availPhysMem = availPhysMem;
Shinya Kitaoka 120a6e
    info.m_availVirtMem = availVirtMem;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::activateServer(const QString &id) {
Shinya Kitaoka 120a6e
  QString data("activateServer");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Controller::deactivateServer(const QString &id,
Shinya Kitaoka 120a6e
                                  bool completeRunningTasks) {
Shinya Kitaoka 120a6e
  QString data("deactivateServer");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += id;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += QString::number(completeRunningTasks);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // anonymous namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmControllerFactory::TFarmControllerFactory() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int TFarmControllerFactory::create(const ControllerData &data,
Shinya Kitaoka 120a6e
                                   TFarmController **controller)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  *controller = new Controller(data.m_hostName, data.m_ipAddress, data.m_port);
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFarmControllerFactory::create(const QString &hostname, int port,
Shinya Kitaoka 120a6e
                                   TFarmController **controller) {
Shinya Kitaoka 120a6e
  *controller = new Controller(hostname, "", port);
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void loadControllerData(const TFilePath &fp, ControllerData &data) {
Shinya Kitaoka 120a6e
  Tifstream is(fp);
Shinya Kitaoka 120a6e
  if (!is || !is.good()) {
Shinya Kitaoka 120a6e
    throw TException(L"Unable to get Farm Controller Data (looking for '" +
Shinya Kitaoka 120a6e
                     fp.getWideString() + L"')");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  while (!is.eof()) {
Shinya Kitaoka 120a6e
    char line[1024];
Shinya Kitaoka 120a6e
    is.getline(line, 1024);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (line[0] != '#' && QString(line) != "") {
2fc36c
      std::stringstream iss(line);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      char hostName[512];
Shinya Kitaoka 120a6e
      char ipAddr[80];
Shinya Kitaoka 120a6e
      int port;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      iss >> hostName >> ipAddr >> port;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      data.m_hostName  = hostName;
Shinya Kitaoka 120a6e
      data.m_ipAddress = ipAddr;
Shinya Kitaoka 120a6e
      data.m_port      = port;
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}