latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiGtkServer.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 11.11.2001 00030 * revisions ..: $Id: ltiGtkServer.h,v 1.3 2006/02/08 12:56:33 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_GTK_SERVER_H_ 00034 #define _LTI_GTK_SERVER_H_ 00035 00036 #include "ltiConfig.h" 00037 00038 #ifdef HAVE_GTK 00039 00040 #include <gtk/gtk.h> 00041 00042 #include "ltiThread.h" 00043 #include "ltiSemaphore.h" 00044 #include "ltiMutex.h" 00045 00046 namespace lti { 00047 00048 /** 00049 * Server to administrate gtk GUI. 00050 */ 00051 class gtkServer : public object { 00052 public: 00053 /** 00054 * default constructor 00055 */ 00056 gtkServer(); 00057 00058 /** 00059 * destructor 00060 */ 00061 virtual ~gtkServer(); 00062 00063 /** 00064 * start the server. 00065 * @return true if successful or if already started, false if 00066 * something went wrong. 00067 */ 00068 bool start(); 00069 00070 /** 00071 * stop the server. 00072 * 00073 * It will not be possible to restart the server after this. You can 00074 * stop the server before the end of the application, to close all 00075 * GTK widgets and its main loop. 00076 * @return true if successful, of false otherwise. 00077 */ 00078 static bool shutdown(); 00079 00080 /** 00081 * return true if the gtk-server is active (alive) or false otherwise 00082 */ 00083 static bool isAlive(); 00084 00085 protected: 00086 /** 00087 * An instance of this class will be the GUI server object, called 00088 * gtkServer 00089 */ 00090 class guiThread : public thread { 00091 public: 00092 /** 00093 * default constructor 00094 */ 00095 guiThread(); 00096 00097 /** 00098 * destructor 00099 */ 00100 virtual ~guiThread(); 00101 00102 /** 00103 * wait until the initialization of the gui toolkit 00104 * is ready 00105 */ 00106 void start(); 00107 00108 /** 00109 * stop the gui-thread. Once stopped, it cannot be restarted due 00110 * to a GDK limitation :-( 00111 */ 00112 virtual void stop(); 00113 00114 protected: 00115 /** 00116 * the job to be independently executed in a new thread 00117 */ 00118 virtual void run(); 00119 00120 /** 00121 * clean up the run() method 00122 */ 00123 virtual void cleanUp(); 00124 00125 /** 00126 * initializes GUI toolkit 00127 */ 00128 static void toolkitInit(); 00129 00130 /** 00131 * enters event handling routine of the toolkit 00132 */ 00133 static void toolkitMainLoop(); 00134 00135 /** 00136 * wait until initialization of toolkit is ready 00137 */ 00138 static void waitUntilInitReady(); 00139 00140 /** 00141 * semaphore used to indicate if initialization is ready 00142 */ 00143 static semaphore initReady; 00144 00145 /** 00146 * timeout gtk-callback function, called as first when the 00147 * main-loop has been initialized! 00148 */ 00149 static gint initializationTimeout(gpointer data); 00150 00151 /** 00152 * Stop the gtk-application 00153 */ 00154 static gint applicationEnd(gpointer data); 00155 00156 }; 00157 00158 /** 00159 * the gui server (just one for all gui elements...) 00160 */ 00161 static guiThread theThread; 00162 00163 /** 00164 * flag to indicate if server thread is already on 00165 */ 00166 static bool alreadyStarted; 00167 00168 /** 00169 * mutex to protect flag alreadyStarted 00170 */ 00171 static mutex lock; 00172 00173 /** 00174 * static method called at the end of the application, to ensure 00175 * the proper finalization of the GTK main loop. 00176 */ 00177 static void toolkitAbort(); 00178 }; 00179 00180 } 00181 00182 #endif 00183 #endif