ionflux.org | Impressum

GlibMultiplexer.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_GLIBMULTIPLEXER
00002 #define IONFLUX_TOOLS_GLIBMULTIPLEXER
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * GlibMultiplexer.hpp                 Glib based IO event multiplexer.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <sstream>
00032 #include <vector>
00033 #include <signal.h>
00034 #include <gtkmm/main.h>
00035 #include "ionflux/IOHandler.hpp"
00036 #include "ionflux/Reporter.hpp"
00037 #include "ionflux/IOMultiplexer.hpp"
00038 
00039 namespace Ionflux
00040 {
00041 
00042 namespace Tools
00043 {
00044 
00045 class GlibMultiplexer;
00046 
00053 class GlibIOEventInfo
00054 : public sigc::trackable
00055 {
00056     public:
00058         IOEvent event;
00060         IOHandler *handler;
00062         sigc::connection signalCon;
00063 #ifdef HAVE_WINSOCK
00064 
00065         WSAEVENT socketEvent;
00066 #endif
00067 
00068         GlibMultiplexer *target;
00069         
00070         // Constructor.
00071         GlibIOEventInfo() : target(0) { }
00073         bool ioHandler(Glib::IOCondition ioCond);
00074 };
00075 
00092 class GlibMultiplexer
00093 : public sigc::trackable, public IOMultiplexer
00094 {
00095     protected:
00097         static sig_atomic_t shutdown;
00099         Ionflux::Tools::Reporter log;
00101         std::vector<GlibIOEventInfo *> events;
00103         std::vector<GlibIOEventInfo *> trash;
00105         std::vector<GlibIOEventInfo *> newEvents;
00107         bool running;
00109         Gtk::Main* kit;
00111         int argc;
00113         char** argv;
00115         Gtk::Window* mainWindow;
00116         
00123         virtual void clearEvent(GlibIOEventInfo* eventInfo);
00124         
00130         virtual void clearEvents();
00131         
00138         virtual void addEvent(GlibIOEventInfo* eventInfo);
00139         
00145         virtual void addEvents();
00146         
00147     public:
00152         GlibMultiplexer();
00153         
00161         GlibMultiplexer(int initArgc, char** initArgv);
00162         
00171         GlibMultiplexer(int initArgc, char** initArgv, 
00172             Gtk::Window* initMainWin);
00173         
00178         virtual ~GlibMultiplexer();
00179         
00187         virtual void registerEvent(IOHandler* handler, IOEvent event);
00188         
00196         virtual void removeEvent(IOHandler* handler, IOEvent event);
00197         
00210         virtual bool processEvent(GlibIOEventInfo* eventInfo, 
00211             Glib::IOCondition ioCond);
00212         
00217         virtual void run();
00218         
00223         virtual void quit();
00224         
00229         virtual bool isRunning();
00230         
00237         virtual void runHandler();
00238         
00245         virtual bool quitHandler();
00246         
00253         static void shutdownHandler(int signum);
00254         
00259         virtual Reporter& getLog();
00260         
00267         virtual void setMainWindow(Gtk::Window* newMainWindow);
00268         
00273         virtual Gtk::Window* getMainWindow();
00274 };
00275 
00276 }
00277 
00278 }
00279 
00283 #endif

Generated on Tue Mar 14 20:58:29 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6