switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / IOEvent.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief IOEvent public header */
30
31 #ifndef HH_SENF_PPI_IOEvent_
32 #define HH_SENF_PPI_IOEvent_ 1
33
34 // Custom includes
35 #include <senf/Scheduler/FdEvent.hh>
36 #include <senf/Utils/Exception.hh>
37 #include "Events.hh"
38
39 //#include "IOEvent.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43 namespace ppi {
44
45     /** \brief IOEvent event information
46
47         Information passed to the IOEvent event handler
48      */
49     struct IOEventInfo
50     {
51         unsigned events;                ///< Type of event signaled
52                                         /**< The value is a combination of the flags from
53                                              IOEvent::EventFlags */
54     };
55
56     /** \brief FileHandle based I/O read/write event
57
58         An IOEvent is signaled, whenever the FileHandle \a handle becomes readable or writable. The
59         type of event is specified using the \a events mask with values from EventFlags.
60
61         There are two types of flags:
62
63         \li <em>Event flags</em> (\ref Read, \ref Prio, \ref Write) specify the type of event. The
64             callback will be called whenever one of the specified events occurs on the filehandle
65         \li <em>Error flags</em> (\ref Hup, \ref Err) specify some type of error condition on the
66             filehandle. If you specify an error flag when registering the event, the error condition
67             will be passed to the callback, otherwise an ErrorException or HangupException will be
68             thrown.
69
70         \see IOEventInfo
71
72         \ingroup event_group
73       */
74     class IOEvent
75         : public EventImplementation<IOEventInfo>
76     {
77     public:
78         //-////////////////////////////////////////////////////////////////////////
79         // Types
80
81         // This is stupid, however there is no way to import the Scheduler::EventId enum together
82         // with the enumeration symbols
83
84         enum EventFlags {
85               Read  = scheduler::FdEvent::EV_READ   /**< FileHandle is readable */
86             , Prio = scheduler::FdEvent::EV_PRIO    /**< FileHandle priority data is readable */
87             , Write = scheduler::FdEvent::EV_WRITE  /**< FileHandle is writable */
88             , Hup = scheduler::FdEvent::EV_HUP      /**< Hangup condition on FileHandle */
89             , Err = scheduler::FdEvent::EV_ERR      /**< Some other error condition on FileHandle */
90         };
91
92         //-////////////////////////////////////////////////////////////////////////
93         ///\name Structors and default members
94         //\{
95
96         IOEvent();
97
98         template <class Handle>
99         IOEvent(Handle handle, unsigned events);
100
101         //\}
102         //-////////////////////////////////////////////////////////////////////////
103
104         template <class Handle>
105         void set(Handle handle, unsigned events);
106
107         /** \brief Unhandled error condition */
108         struct ErrorException : public senf::Exception
109         { ErrorException() : senf::Exception("senf::ppi::IOEvent::ErrorException") {} };
110
111         /** \brief Unhandled hangup condition */
112         struct HangupException : public senf::Exception
113         { HangupException() : senf::Exception("senf::ppi::IOEvent::HangupException") {} };
114
115     private:
116         virtual void v_enable();
117         virtual void v_disable();
118
119         void cb(int event);
120
121         int fd_;
122         scheduler::FdEvent event_;
123     };
124
125 }}
126
127 //-/////////////////////////////////////////////////////////////////////////////////////////////////
128 #include "IOEvent.cci"
129 #include "IOEvent.ct"
130 #include "IOEvent.cti"
131 #endif
132
133 \f
134 // Local Variables:
135 // mode: c++
136 // fill-column: 100
137 // comment-column: 40
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // End: