// $Id$ // // Copyright (C) 2006 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief FileHandle inline non-template implementation */ //#include "FileHandle.ih" // Custom includes #include "../Utils/senfassert.hh" #include #include "../Utils/Exception.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // senf::FileBody prefix_ senf::FileBody::FileBody(int fd) : fd_(fd) {} prefix_ senf::FileHandle senf::FileBody::handle() { return FileHandle(ptr(this)); } prefix_ int senf::FileBody::fd() const { return fd_; } prefix_ void senf::FileBody::fd(int fd) { fd_ = fd; } prefix_ bool senf::FileBody::eof() const { return v_eof(); } prefix_ bool senf::FileBody::valid() const { return fd_!=-1 && v_valid(); } prefix_ bool senf::FileBody::readable() const { return pollCheck(fd(),true); } prefix_ void senf::FileBody::waitReadable() const { pollCheck(fd(),true,true); } prefix_ bool senf::FileBody::writeable() const { return pollCheck(fd(),false); } prefix_ void senf::FileBody::waitWriteable() const { pollCheck(fd(),false,true); } /////////////////////////////////////////////////////////////////////////// // senf::FileHandle prefix_ void senf::FileHandle::close() { body().close(); } prefix_ void senf::FileHandle::terminate() { body().terminate(); } prefix_ bool senf::FileHandle::readable() const { return body().readable(); } prefix_ void senf::FileHandle::waitReadable() const { body().waitReadable(); } prefix_ bool senf::FileHandle::writeable() const { return body().writeable(); } prefix_ void senf::FileHandle::waitWriteable() const { body().waitWriteable(); } prefix_ bool senf::FileHandle::blocking() const { return body().blocking(); } prefix_ void senf::FileHandle::blocking(bool status) { body().blocking(status); } prefix_ bool senf::FileHandle::eof() const { return body().eof(); } prefix_ bool senf::FileHandle::valid() const { return body_ && body().valid(); } prefix_ bool senf::FileHandle::boolean_test() const { return valid() && !eof(); } prefix_ int senf::FileHandle::fd() const { return body().fd(); } prefix_ senf::FileHandle::FileHandle() : body_(0) {} prefix_ senf::FileHandle::~FileHandle() { if (body_ && ! body().is_shared()) body().destroyClose(); } prefix_ senf::FileHandle::FileHandle(std::auto_ptr body) : body_(body.release()) {} prefix_ senf::FileHandle::FileHandle(FileBody::ptr body) : body_(body) {} prefix_ senf::FileBody & senf::FileHandle::body() { SENF_ASSERT(body_); return *body_; } prefix_ senf::FileBody const & senf::FileHandle::body() const { SENF_ASSERT(body_); return *body_; } prefix_ senf::FileBody & senf::FileHandle::body(FileHandle & handle) { return handle.body(); } prefix_ senf::FileBody const & senf::FileHandle::body(FileHandle const & handle) { return handle.body(); } prefix_ void senf::FileHandle::fd(int fd) { body().fd(fd); } prefix_ senf::FileHandle::FileHandle senf::FileHandle::cast_static(FileHandle handle) { return handle; } prefix_ senf::FileHandle senf::FileHandle::cast_dynamic(FileHandle handle) { return handle; } prefix_ int senf::retrieve_filehandle(FileHandle handle) { return handle.fd(); } ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // comment-column: 40 // End: