|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tfarmserver.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tfarmexecutor.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <vector></vector>
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class TFarmServerStub::Imp final : public TFarmExecutor {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
Imp(TFarmServer *server, int port) : TFarmExecutor(port), m_server(server) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_server);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// TFarmExecutor overrides
|
|
Shinya Kitaoka |
473e70 |
QString execute(const std::vector<qstring> &argv) override;</qstring>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFarmServer *m_server;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QString TFarmServerStub::Imp::execute(const std::vector<qstring> &argv) {</qstring>
|
|
Toshihiro Shimizu |
890ddd |
#ifdef DEBUG
|
|
Shinya Kitaoka |
120a6e |
std::cout << "executing " << argv[0].c_str() << endl;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (argv.size() > 0) {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef DEBUG
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)argv.size(); ++i) std::cout << argv[i] << " ";
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (argv[0] == "addTask" && argv.size() == 3) {
|
|
Shinya Kitaoka |
120a6e |
int ret = m_server->addTask(argv[1], argv[2]);
|
|
Shinya Kitaoka |
120a6e |
return QString::number(ret);
|
|
Shinya Kitaoka |
120a6e |
} else if (argv[0] == "terminateTask" && argv.size() > 1) {
|
|
Shinya Kitaoka |
120a6e |
int ret = m_server->terminateTask(argv[1]);
|
|
Shinya Kitaoka |
120a6e |
return QString::number(ret);
|
|
Shinya Kitaoka |
120a6e |
} else if (argv[0] == "getTasks") {
|
|
Shinya Kitaoka |
120a6e |
std::vector<qstring> tasks;</qstring>
|
|
Shinya Kitaoka |
120a6e |
int ret = m_server->getTasks(tasks);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QString reply(QString::number(ret));
|
|
Shinya Kitaoka |
120a6e |
reply += ",";
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<qstring>::iterator it = tasks.begin();</qstring>
|
|
Shinya Kitaoka |
120a6e |
for (; it != tasks.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
reply += *it;
|
|
Shinya Kitaoka |
120a6e |
reply += ",";
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!reply.isEmpty()) reply.remove(reply.length() - 1, 1);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return reply;
|
|
Shinya Kitaoka |
120a6e |
} else if (argv[0] == "queryHwInfo") {
|
|
Shinya Kitaoka |
120a6e |
TFarmServer::HwInfo hwInfo;
|
|
Shinya Kitaoka |
120a6e |
m_server->queryHwInfo(hwInfo);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QString ret;
|
|
Shinya Kitaoka |
120a6e |
ret += QString::number((int)hwInfo.m_cpuCount);
|
|
Shinya Kitaoka |
120a6e |
ret += ",";
|
|
Shinya Kitaoka |
120a6e |
ret += QString::number((int)(hwInfo.m_totPhysMem / 1024));
|
|
Shinya Kitaoka |
120a6e |
ret += ",";
|
|
Shinya Kitaoka |
120a6e |
ret += QString::number((int)(hwInfo.m_availPhysMem / 1024));
|
|
Shinya Kitaoka |
120a6e |
ret += ",";
|
|
Shinya Kitaoka |
120a6e |
ret += QString::number((int)(hwInfo.m_totVirtMem / 1024));
|
|
Shinya Kitaoka |
120a6e |
ret += ",";
|
|
Shinya Kitaoka |
120a6e |
ret += QString::number((int)(hwInfo.m_availVirtMem / 1024));
|
|
Shinya Kitaoka |
120a6e |
ret += ",";
|
|
Shinya Kitaoka |
120a6e |
ret += QString::number(hwInfo.m_type);
|
|
Shinya Kitaoka |
120a6e |
return ret;
|
|
Shinya Kitaoka |
120a6e |
} else if (argv[0] == "attachController" && argv.size() > 3) {
|
|
Shinya Kitaoka |
120a6e |
int port = argv[3].toInt();
|
|
Shinya Kitaoka |
120a6e |
m_server->attachController(argv[1], argv[2], port);
|
|
Shinya Kitaoka |
120a6e |
return "";
|
|
Shinya Kitaoka |
120a6e |
} else if (argv[0] == "detachController" && argv.size() > 3) {
|
|
Shinya Kitaoka |
120a6e |
int port = argv[3].toInt();
|
|
Shinya Kitaoka |
120a6e |
m_server->detachController(argv[1], argv[2], port);
|
|
Shinya Kitaoka |
120a6e |
return "";
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return "";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFarmServerStub::TFarmServerStub(TFarmServer *farmServer, int port)
|
|
Shinya Kitaoka |
120a6e |
: m_imp(new Imp(farmServer, port)) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TFarmServerStub::~TFarmServerStub() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TFarmServerStub::run() {
|
|
Shinya Kitaoka |
120a6e |
m_imp->run();
|
|
Shinya Kitaoka |
120a6e |
return m_imp->getExitCode();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TFarmServerStub::shutdown() {
|
|
Shinya Kitaoka |
120a6e |
TTcpIpClient client;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int socketId;
|
|
Shinya Kitaoka |
120a6e |
int ret =
|
|
Shinya Kitaoka |
120a6e |
client.connect(TSystem::getHostName(), "", m_imp->getPort(), socketId);
|
|
Shinya Kitaoka |
120a6e |
if (ret == OK) {
|
|
Shinya Kitaoka |
120a6e |
ret = client.send(socketId, "shutdown");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TFarmServerStub::getPort() const { return m_imp->getPort(); }
|