Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfarmserver.h"
Toshihiro Shimizu 890ddd
//#include "ttcpip.h"
Toshihiro Shimizu 890ddd
#include "tfarmproxy.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FarmServerProxy final : public TFarmServer, public TFarmProxy {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FarmServerProxy(const QString &hostName, const QString &addr, int port)
Shinya Kitaoka 120a6e
      : TFarmProxy(hostName, addr, port) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // TFarmServer interface implementation
Shinya Kitaoka 473e70
  int addTask(const QString &taskid, const QString &cmdline) override;
Shinya Kitaoka 473e70
  int terminateTask(const QString &taskid) override;
otakuto 158f9f
  int getTasks(std::vector<qstring> &tasks) override;</qstring>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void queryHwInfo(HwInfo &hwInfo) override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  void attachController(const QString &name, const QString &addr,
Shinya Kitaoka 38fd86
                        int port) override;
Shinya Kitaoka 38fd86
  void detachController(const QString &name, const QString &addr,
Shinya Kitaoka 38fd86
                        int port) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FarmServerProxy::addTask(const QString &taskid, const QString &cmdline) {
Shinya Kitaoka 120a6e
  QString data("addTask");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += taskid;
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += cmdline;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Shinya Kitaoka 120a6e
  if (reply.isEmpty()) return -1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int rc = reply.toInt();
Shinya Kitaoka 120a6e
  return rc;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FarmServerProxy::terminateTask(const QString &taskid) {
Shinya Kitaoka 120a6e
  QString data("terminateTask");
Shinya Kitaoka 120a6e
  data += ",";
Shinya Kitaoka 120a6e
  data += taskid;
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
otakuto 158f9f
int FarmServerProxy::getTasks(std::vector<qstring> &tasks) {</qstring>
Shinya Kitaoka 120a6e
  QString data("getTasks");
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
otakuto 158f9f
  std::vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  int count = extractArgs(reply, argv);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(count > 0);
Shinya Kitaoka 120a6e
  int taskCount = argv[0].toInt();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tasks.clear();
Shinya Kitaoka 120a6e
  std::vector<qstring>::iterator it = argv.begin();</qstring>
Shinya Kitaoka 120a6e
  std::advance(it, 1);
Shinya Kitaoka 120a6e
  for (; it != argv.end(); ++it) tasks.push_back(*it);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return taskCount;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FarmServerProxy::queryHwInfo(HwInfo &hwInfo) {
Shinya Kitaoka 120a6e
  QString data("queryHwInfo");
Shinya Kitaoka 120a6e
  QString reply = sendToStub(data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // la stringa restituita contiene le informazioni desiderate separate da ","
otakuto 158f9f
  std::vector<qstring> argv;</qstring>
Shinya Kitaoka 120a6e
  extractArgs(reply, argv);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(argv.size() > 4);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int cpuCount, totPhysMem, totVirtMem, availPhysMem, availVirtMem;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  cpuCount     = argv[0].toInt();
Shinya Kitaoka 120a6e
  totPhysMem   = argv[1].toInt();
Shinya Kitaoka 120a6e
  availPhysMem = argv[2].toInt();
Shinya Kitaoka 120a6e
  totVirtMem   = argv[3].toInt();
Shinya Kitaoka 120a6e
  availVirtMem = argv[4].toInt();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  hwInfo.m_cpuCount     = cpuCount;
Shinya Kitaoka 120a6e
  hwInfo.m_totPhysMem   = totPhysMem;
Shinya Kitaoka 120a6e
  hwInfo.m_totVirtMem   = totVirtMem;
Shinya Kitaoka 120a6e
  hwInfo.m_availPhysMem = availPhysMem;
Shinya Kitaoka 120a6e
  hwInfo.m_availVirtMem = availVirtMem;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (argv.size() > 5) hwInfo.m_type = (TFarmPlatform)argv[5].toInt();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FarmServerProxy::attachController(const QString &name, const QString &addr,
Shinya Kitaoka 120a6e
                                       int port) {
Shinya Kitaoka 120a6e
  QString data("attachController");
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
  sendToStub(data);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FarmServerProxy::detachController(const QString &name, const QString &addr,
Shinya Kitaoka 120a6e
                                       int port) {
Shinya Kitaoka 120a6e
  QString data("detachController");
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
Shinya Kitaoka 120a6e
}  // anonymous namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmServerFactory::TFarmServerFactory() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFarmServerFactory::~TFarmServerFactory() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFarmServerFactory::create(const QString &hostName, const QString &addr,
Shinya Kitaoka 120a6e
                               int port, TFarmServer **tfserver) {
Shinya Kitaoka 120a6e
  *tfserver = new FarmServerProxy(hostName, addr, port);
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}