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

UnixEventRegistry.h

00001 #ifndef _UNEVT_UnixEventRegistry_H_  // -*-c++-*-
00002 
00003 #ifdef __GNUG__
00004 #  pragma interface
00005 #endif
00006 
00007 /* $Header: /home/hopper/src/cvs/C++/UniEvent/UniEvent/UnixEventRegistry.h,v 1.11 2002/08/29 00:58:05 hopper Exp $ */
00008 
00009 // For a log, see ../ChangeLog
00010 
00011 #include <LCore/enum_set.h>
00012 
00013 #define _UNEVT_UnixEventRegistry_H_
00014 
00015 namespace strmod {
00016 namespace unievent {
00017 
00018 class Dispatcher;
00019 class EventPtr;
00020 
00021 /** \class UnixEventRegistry UnixEventRegistry.h UniEvent/UnixEventRegistry.h
00022  * \brief Manages events associated with various file descriptors and/or
00023  * signals.
00024  */
00025 class UnixEventRegistry
00026 {
00027  public:
00028    /** These enums are intended to be used with the enum_set, FDCondSet.
00029     * In maintaining this enum, FD_Readable must be first, and FD_Invalid must
00030     * be last.
00031     * \note fd means file descriptor.
00032     */
00033    enum FDConditions {
00034       FD_Readable, //!< Can the fd be read from without blocking?
00035       FD_Writeable, //!< Can the fd be written to without blocking?
00036       FD_Error,  //!< Is the fd in some kind of error state?
00037       FD_Closed, //!< Has the fd been closed by another process?
00038       FD_Invalid //!< Was the fd never opened?
00039    };
00040    //! A set of 0 or more FDConditions.
00041    typedef lcore::enum_set<FDConditions, FD_Readable, FD_Invalid> FDCondSet;
00042    //! The set of all FDConditions
00043    static const FDCondSet all_fdconds;
00044 
00045    //! This is an abstract base class, so the constructor has little meaning.
00046    inline UnixEventRegistry();
00047    //! An abstract base class with no members, has nothing to destruct.
00048    inline virtual ~UnixEventRegistry();
00049 
00050    //! Register the event '*ev' to be fired on file descriptor condition true.
00051    virtual void registerFDCond(int fd,
00052                                const FDCondSet &condbits,
00053                                const EventPtr &ev) = 0;
00054 
00055    //! Removes all entries associated with a particular file descriptor.
00056    virtual void freeFD(int fd) = 0;
00057 
00058    /** On the given signal, post the given event.
00059     * @param signo The number of the signal to post an event for.
00060     * @param ev The event to post.
00061     */
00062    virtual void onSignal(int signo, const EventPtr &e) = 0;
00063 
00064    /** Stop posting the given event for the given signal.
00065     * @param signo The signal to stop posting the event for.
00066     * @param ev The event to stop posting.
00067     */
00068    virtual void clearSignal(int signo, const EventPtr &e) = 0;
00069 
00070    /** Stop posting any events for the given signal.
00071     * @param signo The signal to stop posting events for.
00072     *
00073     * This function should be avoided as you may interfere unkowingly with other
00074     * parts of the program that are still depending on their events being posted
00075     * when the signal happens.
00076     */
00077    virtual void clearSignal(int signo) = 0;
00078 
00079    //! Actually call the UNIX poll system call, and dispatch resulting events.
00080    virtual void doPoll(bool wait = false) = 0;
00081 
00082  protected:
00083    //! Maximum number of signals the handled_by_S can keep track of
00084    static const unsigned int max_handled_by_S = 128;
00085    /** Keeps track of which UnixEventRegistry is handling which signal.
00086     *
00087     * This is so that instances of derived classes (since this is an abstract
00088     * class) have a scratchpad to use to communicate with eachother about who's
00089     * handling which signal.  This scratchpad is used both to allow actual
00090     * signal handlers to know which class to poke when a signal does arrive, and
00091     * also so that different handlers don't both try to handle the same signal.
00092     */
00093    static UnixEventRegistry *handled_by_S[max_handled_by_S];
00094 };
00095 
00096 //-----------------------------inline functions--------------------------------
00097 
00098 inline UnixEventRegistry::UnixEventRegistry()
00099 {
00100 }
00101 
00102 inline UnixEventRegistry::~UnixEventRegistry()
00103 {
00104 }
00105 
00106 } // namespace unievent
00107 } // namespace strmod
00108 
00109 #endif

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