Scheduler: Remove obsolete 'Scheduler' class
[senf.git] / PPI / IOEvent.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief IOEvent public header */
25
26 #ifndef HH_IOEvent_
27 #define HH_IOEvent_ 1
28
29 // Custom includes
30 #include "../Scheduler/Scheduler.hh"
31 #include "Events.hh"
32 #include "../Utils/Exception.hh"
33
34 //#include "IOEvent.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38 namespace ppi {
39
40     /** \brief IOEvent event information
41
42         Information passed to the IOEvent event handler
43      */
44     struct IOEventInfo
45     {
46         unsigned events;                ///< Type of event signaled
47                                         /**< The value is a combination of the flags from
48                                              IOEvent::EventFlags */
49     };
50
51     /** \brief FileHandle based I/O read/write event
52
53         An IOEvent is signaled, whenever the FileHandle \a handle becomes readable or writable. The
54         type of event is specified using the \a events mask with values from EventFlags.
55
56         There are two types of flags:
57         
58         \li <em>Event flags</em> (\ref Read, \ref Prio, \ref Write) specify the type of event. The
59             callback will be called whenever one of the specified events occurs on the filehandle
60         \li <em>Error flags</em> (\ref Hup, \ref Err) specify some type of error condition on the
61             filehandle. If you specify an error flag when registering the event, the error condition
62             will be passed to the callback, otherwise an ErrorException or HangupException will be
63             thrown.
64
65         \see IOEventInfo
66
67         \ingroup event_group
68       */
69     class IOEvent
70         : public EventImplementation<IOEventInfo>
71     {
72     public:
73         ///////////////////////////////////////////////////////////////////////////
74         // Types
75
76         // This is stupid, however there is no way to import the Scheduler::EventId enum together
77         // with the enumeration symbols
78
79         enum EventFlags { 
80               Read  = scheduler::FdEvent::EV_READ   /**< FileHandle is readable */
81             , Prio = scheduler::FdEvent::EV_PRIO    /**< FileHandle priority data is readable */
82             , Write = scheduler::FdEvent::EV_WRITE  /**< FileHandle is writable */
83             , Hup = scheduler::FdEvent::EV_HUP      /**< Hangup condition on FileHandle */
84             , Err = scheduler::FdEvent::EV_ERR      /**< Some other error condition on FileHandle */
85         };
86
87         ///////////////////////////////////////////////////////////////////////////
88         ///\name Structors and default members
89         ///@{
90
91         template <class Handle>
92         IOEvent(Handle handle, unsigned events);
93
94         ///@}
95         ///////////////////////////////////////////////////////////////////////////
96
97         /** \brief Unhandled error condition */
98         struct ErrorException : public senf::Exception
99         { ErrorException() : senf::Exception("senf::ppi::IOEvent::ErrorException"){} };
100
101         /** \brief Unhandled hangup condition */
102         struct HangupException : public senf::Exception
103         { HangupException() : senf::Exception("senf::ppi::IOEvent::HangupException"){} };
104
105     protected:
106
107     private:
108         virtual void v_enable();
109         virtual void v_disable();
110         
111         void cb(int event);
112
113         int fd_;
114         scheduler::FdEvent event_;
115     };
116
117     
118 }}
119
120 ///////////////////////////////hh.e////////////////////////////////////////
121 //#include "IOEvent.cci"
122 //#include "IOEvent.ct"
123 #include "IOEvent.cti"
124 #endif
125
126 \f
127 // Local Variables:
128 // mode: c++
129 // fill-column: 100
130 // comment-column: 40
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"
135 // End: