00001 /*************************************************************************** 00002 * Copyright (C) 1998-2009 by authors (see AUTHORS.txt) * 00003 * * 00004 * This file is part of LuxRender. * 00005 * * 00006 * Lux Renderer is free software; you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation; either version 3 of the License, or * 00009 * (at your option) any later version. * 00010 * * 00011 * Lux Renderer is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00018 * * 00019 * This project is based on PBRT ; see http://www.pbrt.org * 00020 * Lux Renderer website : http://www.luxrender.net * 00021 ***************************************************************************/ 00022 00023 #ifndef RENDER_SERVER_H 00024 #define RENDER_SERVER_H 00025 00026 #include "lux.h" 00027 00028 #include <fstream> 00029 #include <boost/thread/xtime.hpp> 00030 #include <boost/date_time/posix_time/posix_time.hpp> 00031 #include <boost/thread.hpp> 00032 #include <boost/bind.hpp> 00033 #include <boost/archive/text_oarchive.hpp> 00034 #include <boost/archive/text_iarchive.hpp> 00035 #include <boost/iostreams/filtering_stream.hpp> 00036 00037 namespace lux 00038 { 00039 00040 class RenderServer; 00041 00042 class NetworkRenderServerThread : public boost::noncopyable { 00043 public: 00044 NetworkRenderServerThread(RenderServer *server) : 00045 renderServer(server), serverThread(NULL), engineThread(NULL), 00046 infoThread(NULL), signal(SIG_NONE) { } 00047 00048 ~NetworkRenderServerThread() { 00049 if (engineThread) 00050 delete engineThread; 00051 00052 if (infoThread) 00053 delete infoThread; 00054 00055 if (serverThread) 00056 delete serverThread; 00057 } 00058 00059 void interrupt() { 00060 signal = SIG_EXIT; 00061 } 00062 00063 void join() { 00064 serverThread->join(); 00065 } 00066 00067 static void run(NetworkRenderServerThread *serverThread); 00068 friend class RenderServer; 00069 private: 00070 RenderServer *renderServer; 00071 boost::thread *serverThread; 00072 boost::thread *engineThread; 00073 boost::thread *infoThread; 00074 00075 // Dade - used to send signals to the thread 00076 enum ThreadSignal { SIG_NONE, SIG_EXIT }; 00077 ThreadSignal signal; 00078 00079 }; 00080 00081 // Dade - network rendering server 00082 class RenderServer { 00083 public: 00084 static const int DEFAULT_TCP_PORT = 18018; 00085 00086 enum ServerState { UNSTARTED, READY, BUSY, STOPPED }; 00087 00088 RenderServer(int threadCount, int tcpPort = DEFAULT_TCP_PORT); 00089 ~RenderServer(); 00090 00091 void start(); 00092 void join(); 00093 void stop(); 00094 00095 int getServerPort() { return tcpPort; } 00096 ServerState getServerState() { return state; } 00097 00098 friend class NetworkRenderServerThread; 00099 00100 private: 00101 static string createNewSessionID(); 00102 00103 bool validateAccess(std::basic_istream<char> &stream) const; 00104 00105 int threadCount; 00106 int tcpPort; 00107 ServerState state; 00108 string currentSID; 00109 NetworkRenderServerThread *serverThread; 00110 }; 00111 00112 }//namespace lux 00113 00114 #endif // RENDER_SERVER_H