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