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

sue_sel.hpp

Go to the documentation of this file.
00001 #ifndef SENTRY_SUE_SEL_HPP
00002 #define SENTRY_SUE_SEL_HPP
00003 
00016 
00017 
00039 class SUEEventSelector {
00041     struct TimeoutsListItem {
00042         TimeoutsListItem *next;
00043         class SUETimeoutHandler *handler; 
00044     } *timeouts;
00046     struct SignalListItem {
00047         SignalListItem *next;
00048         class SUESignalHandler *handler;
00049     } *signalhandlers;
00051 
00055     class SUEFdHandler** fdhandlers;
00057     int fdhandlerssize;
00059 
00064     bool breakflag;
00065 private:
00067     void ResizeFdHandlers(int newsize);
00068 public:
00070     SUEEventSelector();
00072     virtual ~SUEEventSelector();
00074 
00083     void RegisterFdHandler(SUEFdHandler *h);
00085 
00088     void RemoveFdHandler(SUEFdHandler *h);
00089        
00091 
00105     void RegisterTimeoutHandler(SUETimeoutHandler *h);
00107 
00110     void RemoveTimeoutHandler(SUETimeoutHandler *h);
00111 
00112 
00114 
00116     void RegisterSignalHandler(SUESignalHandler *h);
00118     void RemoveSignalHandler(SUESignalHandler *h);
00119         
00120         
00122 
00141     void Go();   
00143 
00148     void Break();
00149         
00151 
00156     virtual void HandleSelectFailure(int rc) {}
00157 private:
00158     // several private functions used to decomposite Go()
00159     struct timeval* ComputeClosestTimeout(struct timeval &timeout);
00160     void SetupFdSets(struct SelectDescriptorsSet &);
00161     void HandleSignals();
00162     void HandleFds(struct SelectDescriptorsSet &);
00163     void HandleTimeouts(struct timeval &current);
00164 };
00165 
00167 
00177 class SUEFdHandler {
00178     friend class SUEEventSelector;
00179 protected:
00180     int fd;               
00181 public:
00183 
00188     SUEFdHandler(int a_fd = -1); 
00190 
00195     virtual ~SUEFdHandler();
00196 
00198 
00203     virtual void FdHandle(bool a_r, bool a_w, bool a_ex) = 0; 
00204 
00206 
00214     void SetFd(int a_fd) { fd = a_fd; }
00215 
00217 
00218 
00221     virtual bool WantRead() const { return true; }
00223 
00226     virtual bool WantWrite() const { return false; }
00228 
00231     virtual bool WantExcept() const { return false; }
00233 };
00234 
00235 
00236 
00238 
00246 class SUETimeoutHandler {
00247     friend class SUEEventSelector;
00249     long sec;  
00251     long usec;
00252 public:
00254 
00257     SUETimeoutHandler(long a_sec, long a_usec);
00258 
00260 
00263     SUETimeoutHandler();
00264 
00266 
00269     virtual ~SUETimeoutHandler();
00270 
00272 
00276     void Set(long a_sec, long a_usec);
00277 
00279 
00285     void SetFromNow(long a_sec, long a_usec = 0);
00286 
00288     void Get(long &a_sec, long &a_usec) const;
00289 
00291     void GetRemainingTime(long &a_sec, long &a_usec) const;
00292 
00294     bool operator < (const SUETimeoutHandler &other) const
00295      { return (sec < other.sec)||(sec == other.sec && usec < other.usec); }
00296 
00298     bool IsBefore(long a_sec, long a_usec) const
00299      { return (sec < a_sec)||(sec == a_sec && usec < a_usec); }
00300  
00302 
00311     virtual void TimeoutHandle() = 0; 
00312 };
00313 
00314 
00315 
00316 
00318 
00323 class SUESignalHandler {
00324     friend class SUEEventSelector;
00325 protected:
00326     int signo;
00327 public:
00328     SUESignalHandler(int a_sig) : signo(a_sig) {}
00329     virtual ~SUESignalHandler() {}
00330 
00331     virtual void SignalHandle() = 0;
00332 };
00333 
00334 
00336 
00339 class SUEException {
00340     const char *s;
00341 public:
00342     SUEException(const char* a) : s(a) {}
00343     SUEException() : s("") {}
00344     SUEException(const SUEException &e) : s(e.s) {}
00345     ~SUEException() {}
00346     const char* Get() { return s; }
00347 };
00348 
00349 
00350 
00351 #endif // sentry

Generated on Fri Feb 27 13:17:25 2004 for SUE Library by doxygen1.2.18