X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FSocketHandle.cti;h=39b32734aa07196df15eee2ac2306b701a58ed0e;hb=d2459b6c8249291588fd3d0d125ed3d38e003b55;hp=aa618bcb8b1cfe36c68cbe43a90e7bef7bd73afd;hpb=8d2d26f114d3df0a60c5c516fcf40671b1e55558;p=senf.git diff --git a/Socket/SocketHandle.cti b/Socket/SocketHandle.cti index aa618bc..39b3273 100644 --- a/Socket/SocketHandle.cti +++ b/Socket/SocketHandle.cti @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// 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 @@ -27,6 +27,7 @@ #include "SocketHandle.ih" // Custom includes +#include "../Utils/senfassert.hh" #include #include #include "../Utils/TypeInfo.hh" @@ -34,84 +35,86 @@ #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// -template -prefix_ senf::SocketHandle::SocketHandle() +/////////////////////////////////////////////////////////////////////////// +// senf::SocketHandle + +template +prefix_ senf::SocketHandle::SocketHandle() {} -template +template template -prefix_ senf::SocketHandle::SocketHandle(SocketHandle other, +prefix_ senf::SocketHandle::SocketHandle(SocketHandle other, typename IsCompatible::type *) : FileHandle(other) {} -template +template template -prefix_ typename senf::SocketHandle::template IsCompatible::type const & -senf::SocketHandle::operator=(SocketHandle other) +prefix_ typename senf::SocketHandle::template IsCompatible::type const & +senf::SocketHandle::operator=(SocketHandle other) { assign(other); return *this; } -template +template prefix_ -senf::SocketHandle::SocketHandle(std::auto_ptr protocol, - bool isServer) - : FileHandle(std::auto_ptr(new SocketBody(protocol,isServer))) +senf::SocketHandle::SocketHandle(std::auto_ptr body) + : FileHandle(std::auto_ptr(body.release())) {} -template -prefix_ senf::SocketHandle::SocketHandle(FileHandle other, bool isChecked) +template +prefix_ senf::SocketHandle::SocketHandle(FileHandle other, bool isChecked) : FileHandle(other) { - BOOST_ASSERT( isChecked ); - BOOST_ASSERT( dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( isChecked ); + SENF_ASSERT( dynamic_cast(&FileHandle::body()) ); } -template -prefix_ senf::SocketBody & senf::SocketHandle::body() +template +prefix_ senf::SocketBody & senf::SocketHandle::body() { - BOOST_ASSERT( dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( dynamic_cast(&FileHandle::body()) ); return static_cast(FileHandle::body()); } -template -prefix_ senf::SocketBody const & senf::SocketHandle::body() +template +prefix_ senf::SocketBody const & senf::SocketHandle::body() const { - BOOST_ASSERT( dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( dynamic_cast(&FileHandle::body()) ); return static_cast(FileHandle::body()); } -template -prefix_ senf::SocketProtocol const & senf::SocketHandle::protocol() +template +prefix_ senf::SocketProtocol const & senf::SocketHandle::protocol() const { return body().protocol(); } -template -prefix_ void senf::SocketHandle::assign(FileHandle other) +template +prefix_ void senf::SocketHandle::assign(FileHandle other) { FileHandle::operator=(other); } -template -prefix_ senf::SocketHandle -senf::SocketHandle::cast_static(FileHandle handle) +template +prefix_ senf::SocketHandle +senf::SocketHandle::cast_static(FileHandle handle) { return SocketHandle(handle,true); } -template -prefix_ senf::SocketHandle -senf::SocketHandle::cast_dynamic(FileHandle handle) +template +prefix_ senf::SocketHandle +senf::SocketHandle::cast_dynamic(FileHandle handle) { // throws bad_cast if the body is not a SocketBody SocketBody & body (dynamic_cast(FileHandle::body(handle))); - // throws bad_cast if the policy is not compatible - SocketPolicy::checkBaseOf(body.protocol().policy()); + // throws bad_cast if the policy is not compatible (already wrapped ...) + SPolicy::checkBaseOf(body.protocol().policy()); return cast_static(handle); } @@ -123,7 +126,7 @@ prefix_ Target senf::static_socket_cast(Source handle) boost::is_convertible::value && ( boost::is_convertible::value || boost::is_convertible::value ) )); - BOOST_ASSERT( check_socket_cast(handle) ); + SENF_ASSERT( check_socket_cast(handle) ); return Target::cast_static(handle); } @@ -135,7 +138,10 @@ prefix_ Target senf::dynamic_socket_cast(Source handle) boost::is_convertible::value && ( boost::is_convertible::value || boost::is_convertible::value ) )); - return Target::cast_dynamic(handle); + try { + return Target::cast_dynamic(handle); + } + SENF_WRAP_EXC(std::bad_cast) } template @@ -161,20 +167,20 @@ prefix_ bool senf::check_socket_cast(Source handle) return true; } -template -prefix_ void senf::SocketHandle::state(SocketStateMap & map, unsigned lod) +template +prefix_ void senf::SocketHandle::state(SocketStateMap & map, unsigned lod) { // We use typeid here even though the type of *this is static // (SocketHandle is not polymorphic and has no vtable). This will // automatically include the SocketPolicy template parameter in // the type name and therefore show the \e static policy of the // socket handle. - map["handle"] = prettyName(typeid(*this)); + map["handle"] << prettyName(typeid(*this)); body().state(map,lod); } -template -prefix_ std::string senf::SocketHandle::dumpState(unsigned lod) +template +prefix_ std::string senf::SocketHandle::dumpState(unsigned lod) { SocketStateMap map; state(map,lod); @@ -182,13 +188,27 @@ prefix_ std::string senf::SocketHandle::dumpState(unsigned lod) } /////////////////////////////////////////////////////////////////////////// -// senf::detail::ConvertibleString +// senf::ProtocolSocketBody + +template +prefix_ senf::ProtocolSocketBody::ProtocolSocketBody(bool isServer) + : SocketBody(isServer) +{} -template -prefix_ senf::detail::ConvertibleString::ConvertibleString(T const & other) - : std::string(boost::lexical_cast(other)) +template +prefix_ senf::ProtocolSocketBody::ProtocolSocketBody(bool isServer, int fd) + : SocketBody(isServer, fd) {} +/////////////////////////////////////////////////////////////////////////// + +template +prefix_ std::ostream & senf::operator<<(std::ostream & os, SocketHandle handle) +{ + os << handle.dumpState(); + return os; +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_