1 #pragma once 2 3 #ifndef TFARMCONTROLLER_H 4 #define TFARMCONTROLLER_H 5 6 #include <vector> 7 8 #include "tfarmtask.h" 9 //#include "texception.h" 10 #include "tconvert.h" 11 //#include "tfilepath.h" 12 13 class TFilePath; 14 15 #ifdef TFARMAPI 16 #undef TFARMAPI 17 #endif 18 19 #ifdef _WIN32 20 #ifdef TFARM_EXPORTS 21 #define TFARMAPI __declspec(dllexport) 22 #else 23 #define TFARMAPI __declspec(dllimport) 24 #endif 25 #else 26 #define TFARMAPI 27 #endif 28 29 //------------------------------------------------------------------------------ 30 31 enum ServerState { Ready, Busy, NotResponding, Down, Offline, ServerUnknown }; 32 33 class ServerIdentity { 34 public: ServerIdentity(const QString & id,const QString & name)35 ServerIdentity(const QString &id, const QString &name) 36 : m_id(id), m_name(name) {} 37 38 QString m_id; 39 QString m_name; 40 }; 41 42 class ServerInfo { 43 public: 44 QString m_name; 45 QString m_ipAddress; 46 QString m_portNumber; 47 48 ServerState m_state; 49 50 QString m_platform; 51 52 int m_cpuCount; 53 unsigned int m_totPhysMem; 54 unsigned int m_totVirtMem; 55 56 // the following fields can be used just if the server state is not Down 57 unsigned int m_availPhysMem; 58 unsigned int m_availVirtMem; 59 QString m_currentTaskId; 60 }; 61 62 //------------------------------------------------------------------------------ 63 64 class TaskShortInfo { 65 public: TaskShortInfo(const QString & id,const QString & name,TaskState status)66 TaskShortInfo(const QString &id, const QString &name, TaskState status) 67 : m_id(id), m_name(name), m_status(status) {} 68 69 QString m_id; 70 QString m_name; 71 TaskState m_status; 72 }; 73 74 //------------------------------------------------------------------------------ 75 76 class TFARMAPI TFarmController { 77 public: ~TFarmController()78 virtual ~TFarmController() {} 79 80 virtual QString addTask(const TFarmTask &task, bool suspended) = 0; 81 82 virtual void removeTask(const QString &id) = 0; 83 virtual void suspendTask(const QString &id) = 0; 84 virtual void activateTask(const QString &id) = 0; 85 virtual void restartTask(const QString &id) = 0; 86 87 virtual void getTasks(std::vector<QString> &tasks) = 0; 88 virtual void getTasks(const QString &parentId, 89 std::vector<QString> &tasks) = 0; 90 virtual void getTasks(const QString &parentId, 91 std::vector<TaskShortInfo> &tasks) = 0; 92 93 virtual void queryTaskInfo(const QString &id, TFarmTask &task) = 0; 94 95 virtual void queryTaskShortInfo(const QString &id, QString &parentId, 96 QString &name, TaskState &status) = 0; 97 98 // used (by a server) to notify a server start 99 virtual void attachServer(const QString &name, const QString &addr, 100 int port) = 0; 101 102 // used (by a server) to notify a server stop 103 virtual void detachServer(const QString &name, const QString &addr, 104 int port) = 0; 105 106 // used by a server to notify a task submission error 107 virtual void taskSubmissionError(const QString &taskId, int errCode) = 0; 108 109 // used by a server to notify a task progress 110 virtual void taskProgress(const QString &taskId, int step, int stepCount, 111 int frameNumber, FrameState state) = 0; 112 113 // used by a server to notify a task completion 114 virtual void taskCompleted(const QString &taskId, int exitCode) = 0; 115 116 // fills the servers vector with the identities of the servers 117 virtual void getServers(std::vector<ServerIdentity> &servers) = 0; 118 119 // returns the state of the server whose id has been specified 120 virtual ServerState queryServerState2(const QString &id) = 0; 121 122 // fills info with the infoes about the server whose id is specified 123 virtual void queryServerInfo(const QString &id, ServerInfo &info) = 0; 124 125 // activates the server whose id has been specified 126 virtual void activateServer(const QString &id) = 0; 127 128 // deactivates the server whose id has been specified 129 // once deactivated, a server is not available for task rendering 130 virtual void deactivateServer(const QString &id, 131 bool completeRunningTasks = true) = 0; 132 }; 133 134 //------------------------------------------------------------------------------ 135 136 class TFARMAPI ControllerData { 137 public: 138 ControllerData(const QString &hostName = "", const QString &ipAddr = "", 139 int port = 0) m_hostName(hostName)140 : m_hostName(hostName), m_ipAddress(ipAddr), m_port(port) {} 141 142 bool operator==(const ControllerData &rhs) { 143 return m_hostName == rhs.m_hostName && m_ipAddress == rhs.m_ipAddress && 144 m_port == rhs.m_port; 145 } 146 147 QString m_hostName; 148 QString m_ipAddress; 149 int m_port; 150 }; 151 152 //------------------------------------------------------------------------------ 153 154 class TFARMAPI TFarmControllerFactory { 155 public: 156 TFarmControllerFactory(); 157 int create(const ControllerData &data, TFarmController **controller); 158 int create(const QString &hostname, int port, TFarmController **controller); 159 }; 160 161 //------------------------------------------------------------------------------ 162 163 void TFARMAPI loadControllerData(const TFilePath &fp, ControllerData &data); 164 165 #endif 166