/* This is for emacs: -*-Mode: C++;-*- */ /* Copyright 2002, Andreas Rottmann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #if !defined(__LIB_SIGCX_GTK_DISPATCH_H) #define __LIB_SIGCX_GTK_DISPATCH_H #include #include #include namespace SigCX { /** GTK+ Dispatcher. * * Implements a dispatcher on top of the GTK/GDK event loop. */ class GtkDispatcher : public SignalDispatcher { struct FileEvent { GtkDispatcher *disp; guint tag; Handler cb; Event ev; FileEvent() {} FileEvent(GtkDispatcher *_disp, guint _tag, const Handler& _cb, Event _ev) : disp(_disp), tag(_tag), cb(_cb), ev(_ev) {} }; struct TimerEvent { GtkDispatcher *disp; guint tag; Handler cb; TimerEvent () {} TimerEvent (GtkDispatcher *_disp, guint _tag, const Handler& _cb) : disp (_disp), tag (_tag), cb (_cb) {} }; typedef std::map FMap; typedef std::map TMap; FMap fevents_; TMap tevents_; static void input_callback (gpointer, gint, GdkInputCondition); static gint timer_callback (gpointer); public: GtkDispatcher(); virtual ~GtkDispatcher(); virtual HandlerID add_input_handler(const Handler& h, int fd); virtual HandlerID add_output_handler(const Handler& h, int fd); virtual HandlerID add_exception_handler(const Handler& h, int fd); virtual HandlerID add_timeout_handler(const Handler& h, const TimeVal& tv); virtual void remove(HandlerID id); virtual bool run(bool infinite = true); virtual void move(Dispatcher& d); virtual bool idle() const; virtual void exit(); private: Threads::Mutex mutex_; }; } #endif