00001 /* 00002 * Copyright (C) 2006, iRex Technologies B.V. 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2, or (at your option) 00007 * any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef RENDERTHREAD_H_ 00020 #define RENDERTHREAD_H_ 00021 #include "PageInfo.h" 00022 #include <signal.h> 00023 #include <pthread.h> 00024 00025 00027 // Render Thread controller 00029 struct Controller; 00030 class CRenderThread; 00031 struct ThreadParam 00032 { 00033 TodoList * todoList; 00034 PageList * pageList; 00035 GBool bQuit; 00036 Controller* ctrl; 00037 CRenderThread * thread; 00038 }; 00039 00040 class CRenderThread 00041 { 00042 private: 00043 enum threadState 00044 { 00045 Initialized = 0, 00046 Rendering = 1, 00047 RenderFinished = 2, 00048 ToAbort = 3, 00049 }; 00050 00051 pthread_t thread; // render thread 00052 pthread_cond_t cond; // condition variable 00053 pthread_mutex_t mutex; // to protect cond 00054 pthread_mutex_t abort; // to protect abort variables 00055 GBool bRunning; 00056 CPageInfo * renderingPage; 00057 ThreadParam * param; 00058 00059 void initialize(); 00060 void destroy(); 00061 void adjustPageList(const int center); // memory control 00062 static void * threadProc(void *); 00063 static GBool abortCheckFunc(void *data); 00064 static threadState abortState; // used to control abort 00065 00066 public: 00067 CRenderThread(void); 00068 ~CRenderThread(void); 00069 public: 00070 void start(ThreadParam * param); 00071 void stop(); 00072 void clearTodoList(); 00073 void addTodoItem(TodoItem * item, GBool bHead = gTrue); 00074 void signal(); 00075 void renderPageNow(TodoItem * item); // abort & render right now 00076 GBool isInRendering(TodoItem * item); // query state 00077 }; 00078 00079 #endif