00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_RENDERFARM_H
00024 #define LUX_RENDERFARM_H
00025
00026 #include <vector>
00027 #include <string>
00028 #include <sstream>
00029
00030 #include <boost/thread.hpp>
00031 #include <boost/thread/xtime.hpp>
00032 #include <boost/date_time/posix_time/posix_time.hpp>
00033
00034 namespace lux
00035 {
00036
00037 class RenderFarm;
00038
00039 class FilmUpdaterThread : public boost::noncopyable {
00040 public:
00041 FilmUpdaterThread(RenderFarm *rFarm, Scene *scn) :
00042 renderFarm(rFarm), scene(scn), thread(NULL), signal(SIG_NONE) { }
00043
00044 ~FilmUpdaterThread() {
00045 delete thread;
00046 }
00047
00048 void interrupt() {
00049 signal = SIG_EXIT;
00050 thread->join();
00051 }
00052
00053 friend class RenderFarm;
00054 private:
00055 static void updateFilm(FilmUpdaterThread *filmUpdaterThread);
00056
00057 RenderFarm *renderFarm;
00058 Scene *scene;
00059 boost::thread *thread;
00060
00061
00062 int signal;
00063 static const int SIG_NONE = 0;
00064 static const int SIG_EXIT = 1;
00065 };
00066
00067 class RenderFarm {
00068 public:
00069 RenderFarm() : serverUpdateInterval(3*60), filmUpdateThread(NULL) {}
00070 ~RenderFarm() {
00071 if (filmUpdateThread)
00072 delete filmUpdateThread;
00073 }
00074
00075 bool connect(const string &serverName);
00076
00077 void disconnectAll();
00078 void disconnect(const string &serverName);
00079
00080 void send(const std::string &command);
00081 void send(const std::string &command, const std::string &name, const ParamSet ¶ms);
00082 void send(const std::string &command, const std::string &name);
00083 void send(const std::string &command, float x, float y);
00084 void send(const std::string &command, float x, float y, float z);
00085 void send(const std::string &command, float a, float x, float y, float z);
00086 void send(const std::string &command, float ex, float ey, float ez, float lx, float ly, float lz, float ux, float uy, float uz);
00087 void send(const std::string &command, float tr[16]);
00088 void send(const std::string &command, const string &name, const string &type, const string &texname, const ParamSet ¶ms);
00089 void send(const std::string &command, const std::string &name, float a, float b, const std::string &transform);
00090
00092 void flush();
00093
00094 int getServerCount() { return serverInfoList.size(); }
00095 int getServersStatus(RenderingServerInfo *info, int maxInfoCount);
00096
00097
00098 void startFilmUpdater(Scene *scene);
00099 void stopFilmUpdater();
00101 void updateFilm(Scene *scene);
00102
00103 public:
00104
00105 int serverUpdateInterval;
00106
00107 private:
00108 struct ExtRenderingServerInfo {
00109 ExtRenderingServerInfo(string n, string p, string id) : name(n),
00110 port(p), sid(id), timeLastContact(boost::posix_time::second_clock::local_time()),
00111 numberOfSamplesReceived(0.0), flushed(false) { }
00112
00113 string name;
00114 string port;
00115 string sid;
00116
00117 boost::posix_time::ptime timeLastContact;
00118
00119
00120 double numberOfSamplesReceived;
00121
00122 bool flushed;
00123 };
00124
00125 static void decodeServerName(const string &serverName, string &name, string &port);
00126 void disconnect(const ExtRenderingServerInfo &serverInfo);
00127 void sendFile(std::string file);
00128
00129
00130 boost::mutex serverListMutex;
00131 std::vector<ExtRenderingServerInfo> serverInfoList;
00132
00133 std::stringstream netBuffer;
00134
00135
00136 FilmUpdaterThread *filmUpdateThread;
00137 };
00138
00139 }
00140
00141 #endif //LUX_ERROR_H