ARPDAS_QNX6 1.0
Selector.h
Go to the documentation of this file.
00001 /**
00002  * \file Selector.h
00003  */
00004 #ifndef SELECTOR_H_INCLUDED
00005 #define SELECTOR_H_INCLUDED
00006 
00007 #include <map>
00008 #include <time.h>
00009 #include "Timeout.h"
00010 
00011 class Selector;
00012 
00013 class Selectee {
00014   public:
00015     Selectee(int fd_in, int flag);
00016     Selectee();
00017     ~Selectee();
00018     /**
00019      * @return non-zero if we should quit
00020      */
00021     virtual int ProcessData(int flag) = 0;
00022     virtual Timeout *GetTimeout();
00023 
00024     int fd;
00025     int flags;
00026     Selector *Stor;
00027 };
00028 
00029 typedef std::map<int,Selectee *> SelecteeMap;
00030 
00031 class Selector {
00032   public:
00033     static const int Sel_Read = 1;
00034     static const int Sel_Write = 2;
00035     static const int Sel_Except = 4;
00036     static const int Sel_Timeout = 8;
00037     Selector();
00038     ~Selector();
00039     void add_child(Selectee *P);
00040     void delete_child(int fd_in);
00041     int update_flags(int fd_in, int flag);
00042     void set_gflag( unsigned gflag_index );
00043     /**
00044      * Method to map a global flag number to a bit mask to be
00045      * set in a Selectee's flags word.
00046      * @param gflag_index global flag bit number
00047      * @return bit mask selecting the specified global flag.
00048      */
00049     static inline int gflag(unsigned gflag_index) {
00050       return( 1 << (gflag_index+4) );
00051     }
00052     void event_loop();
00053   private:
00054     SelecteeMap S;
00055     bool children_changed;
00056     int gflags;
00057     virtual int ProcessTimeout();
00058     virtual Timeout *GetTimeout();
00059 };
00060 
00061 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines