Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

SimpleDispatcher.h

00001 #ifndef _UNEVT_SimpleDispatcher_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright 1991-2002 Eric M. Hopper <hopper@omnifarious.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by the Free Software Foundation; either version 2 of the License, or
00009  *     (at your option) any later version.
00010  * 
00011  *     This program is distributed in the hope that it will be useful, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #  pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/UniEvent/UniEvent/SimpleDispatcher.h,v 1.12 2002/11/25 05:40:05 hopper Exp $ */
00026 
00027 // For log see ../ChangeLog
00028 
00029 #include <UniEvent/Dispatcher.h>
00030 
00031 #define _UNEVT_SimpleDispatcher_H_
00032 
00033 namespace strmod {
00034 namespace unievent {
00035 
00036 class Event;
00037 
00038 /** \class SimpleDispatcher SimpleDispatcher.h UniEvent/SimpleDispatcher.h
00039  * \brief A class that does the minimum necessary to support the Dispatcher
00040  * interface.
00041  */
00042 class SimpleDispatcher : public Dispatcher
00043 {
00044  public:
00045    static const UNEVT_ClassIdent identifier;
00046 
00047    //! Create one.
00048    SimpleDispatcher();
00049    //! Destroy one.
00050    virtual ~SimpleDispatcher();
00051 
00052    inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00053 
00054    virtual void addEvent(const EventPtr &ev);
00055 
00056    virtual void dispatchEvents(unsigned int numevents,
00057                                Dispatcher *enclosing = 0);
00058    virtual void dispatchUntilEmpty(Dispatcher *enclosing = 0);
00059    inline virtual void stopDispatching();
00060    virtual void interrupt();
00061 
00062    virtual bool isQueueEmpty() const;
00063 
00064    virtual void addBusyPollEvent(const EventPtr &ev);
00065    virtual bool onQueueEmpty(const EventPtr &ev);
00066    virtual bool onInterrupt(const EventPtr &ev);
00067 
00068  protected:
00069    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00070 
00071  private:
00072    class Imp;
00073    Imp &imp_;
00074    bool stop_flag_;
00075 
00076    inline void i_DispatchEvent(Imp &imp, Dispatcher *enclosing);
00077    unsigned int i_dispatchNEvents(unsigned int n, bool checkbusypoll,
00078                                   Dispatcher *enclosing);
00079    inline unsigned int checkEmptyBusy(Imp &imp, bool &checkbusy);
00080    void dispatchNEvents(unsigned int n, Dispatcher *enclosing);
00081 
00082    // Purposely left undefined.
00083    SimpleDispatcher(const SimpleDispatcher &b);
00084    const SimpleDispatcher &operator =(const SimpleDispatcher &b);
00085 };
00086 
00087 //-----------------------------inline functions--------------------------------
00088 
00089 inline int SimpleDispatcher::AreYouA(const lcore::ClassIdent &cid) const
00090 {
00091    return((identifier == cid) || Dispatcher::AreYouA(cid));
00092 }
00093 
00094 void SimpleDispatcher::stopDispatching()
00095 {
00096    stop_flag_ = true;
00097 }
00098 
00099 }; // namespace unievent
00100 }; // namespace strmod
00101 
00102 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1