tahoma2d/toonz/sources/toonzfarm/tfarm/tfarmserver_c.cpp

153 lines
4.2 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "tfarmserver.h"
//#include "ttcpip.h"
#include "tfarmproxy.h"
#include "tconvert.h"
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------
class FarmServerProxy final : public TFarmServer, public TFarmProxy {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
FarmServerProxy(const QString &hostName, const QString &addr, int port)
: TFarmProxy(hostName, addr, port) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// TFarmServer interface implementation
2016-06-19 20:06:29 +12:00
int addTask(const QString &taskid, const QString &cmdline) override;
int terminateTask(const QString &taskid) override;
int getTasks(std::vector<QString> &tasks) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void queryHwInfo(HwInfo &hwInfo) override;
2016-03-19 06:57:51 +13:00
2016-06-20 14:23:05 +12:00
void attachController(const QString &name, const QString &addr,
int port) override;
void detachController(const QString &name, const QString &addr,
int port) override;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int FarmServerProxy::addTask(const QString &taskid, const QString &cmdline) {
QString data("addTask");
data += ",";
data += taskid;
data += ",";
data += cmdline;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QString reply = sendToStub(data);
if (reply.isEmpty()) return -1;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int rc = reply.toInt();
return rc;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int FarmServerProxy::terminateTask(const QString &taskid) {
QString data("terminateTask");
data += ",";
data += taskid;
QString reply = sendToStub(data);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return 0;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
int FarmServerProxy::getTasks(std::vector<QString> &tasks) {
2016-06-15 18:43:10 +12:00
QString data("getTasks");
QString reply = sendToStub(data);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// la stringa restituita contiene le informazioni desiderate separate da ","
std::vector<QString> argv;
2016-06-15 18:43:10 +12:00
int count = extractArgs(reply, argv);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(count > 0);
int taskCount = argv[0].toInt();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
tasks.clear();
std::vector<QString>::iterator it = argv.begin();
std::advance(it, 1);
for (; it != argv.end(); ++it) tasks.push_back(*it);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return taskCount;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FarmServerProxy::queryHwInfo(HwInfo &hwInfo) {
QString data("queryHwInfo");
QString reply = sendToStub(data);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// la stringa restituita contiene le informazioni desiderate separate da ","
std::vector<QString> argv;
2016-06-15 18:43:10 +12:00
extractArgs(reply, argv);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(argv.size() > 4);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int cpuCount, totPhysMem, totVirtMem, availPhysMem, availVirtMem;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
cpuCount = argv[0].toInt();
totPhysMem = argv[1].toInt();
availPhysMem = argv[2].toInt();
totVirtMem = argv[3].toInt();
availVirtMem = argv[4].toInt();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
hwInfo.m_cpuCount = cpuCount;
hwInfo.m_totPhysMem = totPhysMem;
hwInfo.m_totVirtMem = totVirtMem;
hwInfo.m_availPhysMem = availPhysMem;
hwInfo.m_availVirtMem = availVirtMem;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (argv.size() > 5) hwInfo.m_type = (TFarmPlatform)argv[5].toInt();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FarmServerProxy::attachController(const QString &name, const QString &addr,
int port) {
QString data("attachController");
data += ",";
data += name;
data += ",";
data += addr;
data += ",";
data += QString::number(port);
sendToStub(data);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void FarmServerProxy::detachController(const QString &name, const QString &addr,
int port) {
QString data("detachController");
data += ",";
data += name;
data += ",";
data += addr;
data += ",";
data += QString::number(port);
QString reply = sendToStub(data);
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
} // anonymous namespace
2016-03-19 06:57:51 +13:00
//==============================================================================
2016-06-15 18:43:10 +12:00
TFarmServerFactory::TFarmServerFactory() {}
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TFarmServerFactory::~TFarmServerFactory() {}
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int TFarmServerFactory::create(const QString &hostName, const QString &addr,
int port, TFarmServer **tfserver) {
*tfserver = new FarmServerProxy(hostName, addr, port);
return 0;
2016-03-19 06:57:51 +13:00
}