git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[senf.git] / Socket / FileHandle.cci
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 // Definition of inline non-template functions
24
25 //#include "FileHandle.ih"
26
27 // Custom includes
28 #include <errno.h>
29 #include "Utils/Exception.hh"
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // satcom::lib::FileBody
36
37 prefix_ satcom::lib::FileBody::FileBody(int fd)
38     : fd_(fd)
39 {}
40
41 prefix_  satcom::lib::FileBody::~FileBody()
42 {
43     if (valid())
44         try {
45             close();
46         }
47         catch (...) {
48             terminate();
49         }
50 }
51
52 prefix_ void satcom::lib::FileBody::close()
53 {
54     if (!valid())
55         throw SystemException(EBADF);
56     v_close();
57     fd_ = -1;
58 }
59
60 prefix_ void satcom::lib::FileBody::terminate()
61 {
62     if (valid()) {
63         v_terminate();
64         fd_ = -1;
65     }
66 }
67
68 prefix_ int satcom::lib::FileBody::fd()
69     const
70 {
71     return fd_;
72 }
73
74 prefix_ void satcom::lib::FileBody::fd(int fd)
75 {
76     fd_ = fd;
77 }
78
79 prefix_ bool satcom::lib::FileBody::eof()
80     const
81 {
82     return v_eof();
83 }
84
85 prefix_ bool satcom::lib::FileBody::valid()
86     const
87 {
88     return fd_!=-1 && v_valid();
89 }
90
91 prefix_ bool satcom::lib::FileBody::readable()
92     const
93 {
94     return pollCheck(fd(),true);
95 }
96
97 prefix_ void satcom::lib::FileBody::waitReadable()
98     const
99 {
100     pollCheck(fd(),true,true);
101 }
102
103 prefix_ bool satcom::lib::FileBody::writeable()
104     const
105 {
106     return pollCheck(fd(),false);
107 }
108
109 prefix_ void satcom::lib::FileBody::waitWriteable()
110     const
111 {
112     pollCheck(fd(),false,true);
113 }
114
115 ///////////////////////////////////////////////////////////////////////////
116 // satcom::lib::FileHandle
117
118 prefix_ void satcom::lib::FileHandle::close()
119 {
120     body().close();
121 }
122
123 prefix_ void satcom::lib::FileHandle::terminate()
124 {
125     body().terminate();
126 }
127
128 prefix_ bool satcom::lib::FileHandle::readable()
129     const
130 {
131     return body().readable();
132 }
133
134 prefix_ void satcom::lib::FileHandle::waitReadable()
135     const
136 {
137     body().waitReadable();
138 }
139
140 prefix_ bool satcom::lib::FileHandle::writeable()
141     const
142 {
143     return body().writeable();
144 }
145
146 prefix_ void satcom::lib::FileHandle::waitWriteable()
147     const
148 {
149     body().waitWriteable();
150 }
151
152 prefix_ bool satcom::lib::FileHandle::blocking()
153     const
154 {
155     return body().blocking();
156 }
157
158 prefix_ void satcom::lib::FileHandle::blocking(bool status)
159 {
160     body().blocking(status);
161 }
162
163 prefix_ bool satcom::lib::FileHandle::eof()
164     const
165 {
166     return body().eof();
167 }
168
169 prefix_ bool satcom::lib::FileHandle::valid()
170     const
171 {
172     return body().valid();
173 }
174
175 prefix_ satcom::lib::FileHandle::operator bool ()
176     const
177 {
178     return valid() && !eof();
179 }
180
181 prefix_ bool satcom::lib::FileHandle::operator!()
182     const
183 {
184     return ! (valid() && !eof());
185 }
186
187 prefix_ int satcom::lib::FileHandle::fd()
188     const
189 {
190     return body().fd();
191 }
192
193 prefix_  satcom::lib::FileHandle::FileHandle(std::auto_ptr<FileBody> body)
194     : body_(body.release())
195 {}
196
197 prefix_ satcom::lib::FileBody & satcom::lib::FileHandle::body()
198 {
199     return *body_;
200 }
201
202 prefix_ satcom::lib::FileBody const & satcom::lib::FileHandle::body()
203     const
204 {
205     return *body_;
206 }
207
208 prefix_ satcom::lib::FileBody & satcom::lib::FileHandle::body(FileHandle & handle)
209 {
210     return handle.body();
211 }
212
213 prefix_ satcom::lib::FileBody const &
214 satcom::lib::FileHandle::body(FileHandle const & handle)
215 {
216     return handle.body();
217 }
218
219 prefix_ void satcom::lib::FileHandle::fd(int fd)
220 {
221     body().fd(fd);
222 }
223
224 prefix_ satcom::lib::FileHandle::FileHandle
225 satcom::lib::FileHandle::cast_static(FileHandle handle)
226 {
227     return handle;
228 }
229
230 prefix_ satcom::lib::FileHandle
231 satcom::lib::FileHandle::cast_dynamic(FileHandle handle)
232 {
233     return handle;
234 }
235
236 ///////////////////////////////cci.e///////////////////////////////////////
237 #undef prefix_
238
239 \f
240 // Local Variables:
241 // mode: c++
242 // c-file-style: "satcom"
243 // End: