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