00001 /*************************************************************************** 00002 * Copyright (C) 1998-2008 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 <boost/thread.hpp> 00029 #include <boost/bind.hpp> 00030 00031 namespace lux 00032 { 00033 00034 class RenderServer; 00035 00036 class NetworkRenderServerThread : public boost::noncopyable { 00037 public: 00038 NetworkRenderServerThread(RenderServer *renderServer) : 00039 renderServer(renderServer), serverThread(NULL), engineThread(NULL), 00040 infoThread(NULL), signal(SIG_NONE) { } 00041 00042 ~NetworkRenderServerThread() { 00043 if (engineThread) 00044 delete engineThread; 00045 00046 if (infoThread) 00047 delete infoThread; 00048 00049 if (serverThread) 00050 delete serverThread; 00051 } 00052 00053 void interrupt() { 00054 signal = SIG_EXIT; 00055 } 00056 00057 void join() { 00058 serverThread->join(); 00059 } 00060 00061 static void run(NetworkRenderServerThread *serverThread); 00062 friend class RenderServer; 00063 private: 00064 RenderServer *renderServer; 00065 boost::thread *serverThread; 00066 boost::thread *engineThread; 00067 boost::thread *infoThread; 00068 00069 // Dade - used to send signals to the thread 00070 enum ThreadSignal { SIG_NONE, SIG_EXIT }; 00071 ThreadSignal signal; 00072 00073 }; 00074 00075 // Dade - network rendering server 00076 class RenderServer { 00077 public: 00078 static const int DEFAULT_TCP_PORT = 18018; 00079 00080 enum ServerState { UNSTARTED, READY, BUSY, STOPPED }; 00081 00082 RenderServer(int threadCount, int tcpPort = DEFAULT_TCP_PORT); 00083 ~RenderServer(); 00084 00085 void start(); 00086 void join(); 00087 void stop(); 00088 00089 int getServerPort() { return tcpPort; } 00090 ServerState getServerState() { return state; } 00091 00092 friend class NetworkRenderServerThread; 00093 private: 00094 int threadCount; 00095 int tcpPort; 00096 ServerState state; 00097 NetworkRenderServerThread *serverThread; 00098 }; 00099 00100 }//namespace lux 00101 00102 #endif // RENDER_SERVER_H