Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TFARMCONTROLLER_H
Toshihiro Shimizu 890ddd
#define TFARMCONTROLLER_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using std::vector;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfarmtask.h"
Toshihiro Shimizu 890ddd
//#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
//#include "tfilepath.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFilePath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef TFARMAPI
Toshihiro Shimizu 890ddd
#undef TFARMAPI
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#ifdef TFARM_EXPORTS
Toshihiro Shimizu 890ddd
#define TFARMAPI __declspec(dllexport)
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TFARMAPI __declspec(dllimport)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TFARMAPI
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
enum ServerState {
Toshihiro Shimizu 890ddd
	Ready,
Toshihiro Shimizu 890ddd
	Busy,
Toshihiro Shimizu 890ddd
	NotResponding,
Toshihiro Shimizu 890ddd
	Down,
Toshihiro Shimizu 890ddd
	Offline,
Toshihiro Shimizu 890ddd
	ServerUnknown
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ServerIdentity
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ServerIdentity(const QString &id, const QString &name)
Toshihiro Shimizu 890ddd
		: m_id(id), m_name(name) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString m_id;
Toshihiro Shimizu 890ddd
	QString m_name;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ServerInfo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	QString m_name;
Toshihiro Shimizu 890ddd
	QString m_ipAddress;
Toshihiro Shimizu 890ddd
	QString m_portNumber;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ServerState m_state;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString m_platform;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int m_cpuCount;
Toshihiro Shimizu 890ddd
	unsigned int m_totPhysMem;
Toshihiro Shimizu 890ddd
	unsigned int m_totVirtMem;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// the following fields can be used just if the server state is not Down
Toshihiro Shimizu 890ddd
	unsigned int m_availPhysMem;
Toshihiro Shimizu 890ddd
	unsigned int m_availVirtMem;
Toshihiro Shimizu 890ddd
	QString m_currentTaskId;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TaskShortInfo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TaskShortInfo(const QString &id, const QString &name, TaskState status)
Toshihiro Shimizu 890ddd
		: m_id(id), m_name(name), m_status(status) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString m_id;
Toshihiro Shimizu 890ddd
	QString m_name;
Toshihiro Shimizu 890ddd
	TaskState m_status;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFARMAPI TFarmController
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual ~TFarmController() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual QString addTask(const TFarmTask &task, bool suspended) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void removeTask(const QString &id) = 0;
Toshihiro Shimizu 890ddd
	virtual void suspendTask(const QString &id) = 0;
Toshihiro Shimizu 890ddd
	virtual void activateTask(const QString &id) = 0;
Toshihiro Shimizu 890ddd
	virtual void restartTask(const QString &id) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void getTasks(vector<qstring> &tasks) = 0;</qstring>
Toshihiro Shimizu 890ddd
	virtual void getTasks(const QString &parentId, vector<qstring> &tasks) = 0;</qstring>
Toshihiro Shimizu 890ddd
	virtual void getTasks(const QString &parentId, vector<taskshortinfo> &tasks) = 0;</taskshortinfo>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void queryTaskInfo(const QString &id, TFarmTask &task) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void queryTaskShortInfo(
Toshihiro Shimizu 890ddd
		const QString &id,
Toshihiro Shimizu 890ddd
		QString &parentId,
Toshihiro Shimizu 890ddd
		QString &name,
Toshihiro Shimizu 890ddd
		TaskState &status) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// used (by a server) to notify a server start
Toshihiro Shimizu 890ddd
	virtual void attachServer(const QString &name, const QString &addr, int port) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// used (by a server) to notify a server stop
Toshihiro Shimizu 890ddd
	virtual void detachServer(const QString &name, const QString &addr, int port) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// used by a server to notify a task submission error
Toshihiro Shimizu 890ddd
	virtual void taskSubmissionError(const QString &taskId, int errCode) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// used by a server to notify a task progress
Toshihiro Shimizu 890ddd
	virtual 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) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// used by a server to notify a task completion
Toshihiro Shimizu 890ddd
	virtual void taskCompleted(const QString &taskId, int exitCode) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// fills the servers vector with the identities of the servers
Toshihiro Shimizu 890ddd
	virtual void getServers(vector<serveridentity> &servers) = 0;</serveridentity>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// returns the state of the server whose id has been specified
Toshihiro Shimizu 890ddd
	virtual ServerState queryServerState2(const QString &id) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// fills info with the infoes about the server whose id is specified
Toshihiro Shimizu 890ddd
	virtual void queryServerInfo(const QString &id, ServerInfo &info) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// activates the server whose id has been specified
Toshihiro Shimizu 890ddd
	virtual void activateServer(const QString &id) = 0;
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
	virtual void deactivateServer(const QString &id, bool completeRunningTasks = true) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFARMAPI ControllerData
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ControllerData(const QString &hostName = "", const QString &ipAddr = "", int port = 0)
Toshihiro Shimizu 890ddd
		: m_hostName(hostName), m_ipAddress(ipAddr), m_port(port)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator==(const ControllerData &rhs)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_hostName == rhs.m_hostName &&
Toshihiro Shimizu 890ddd
			   m_ipAddress == rhs.m_ipAddress &&
Toshihiro Shimizu 890ddd
			   m_port == rhs.m_port;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QString m_hostName;
Toshihiro Shimizu 890ddd
	QString m_ipAddress;
Toshihiro Shimizu 890ddd
	int m_port;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TFARMAPI TFarmControllerFactory
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TFarmControllerFactory();
Toshihiro Shimizu 890ddd
	int create(const ControllerData &data, TFarmController **controller);
Toshihiro Shimizu 890ddd
	int create(const QString &hostname, int port, TFarmController **controller);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TFARMAPI loadControllerData(const TFilePath &fp, ControllerData &data);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif