// $Id$
//
// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
//
// 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
// Custom includes
#include <typeinfo>
-#include <boost/lexical_cast.hpp>
-#include "Utils/TypeInfo.hh"
+#include "../Utils/senfassert.hh"
+#include "../Utils/TypeInfo.hh"
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
-template <class SocketPolicy>
-prefix_ senf::SocketHandle<SocketPolicy>::SocketHandle()
+///////////////////////////////////////////////////////////////////////////
+// senf::SocketHandle<SPolicy>
+
+template <class SPolicy>
+prefix_ senf::SocketHandle<SPolicy>::SocketHandle()
{}
-template <class SocketPolicy>
+template <class SPolicy>
template <class OtherPolicy>
-prefix_ senf::SocketHandle<SocketPolicy>::SocketHandle(SocketHandle<OtherPolicy> other,
+prefix_ senf::SocketHandle<SPolicy>::SocketHandle(SocketHandle<OtherPolicy> other,
typename IsCompatible<OtherPolicy>::type *)
: FileHandle(other)
{}
-template <class SocketPolicy>
+template <class SPolicy>
template <class OtherPolicy>
-prefix_ typename senf::SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type const &
-senf::SocketHandle<SocketPolicy>::operator=(SocketHandle<OtherPolicy> other)
+prefix_ typename senf::SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const &
+senf::SocketHandle<SPolicy>::operator=(SocketHandle<OtherPolicy> other)
{
assign(other);
return *this;
}
-template <class SocketPolicy>
+template <class SPolicy>
prefix_
-senf::SocketHandle<SocketPolicy>::SocketHandle(std::auto_ptr<SocketProtocol> protocol,
- bool isServer)
- : FileHandle(std::auto_ptr<FileBody>(new SocketBody(protocol,isServer)))
+senf::SocketHandle<SPolicy>::SocketHandle(std::auto_ptr<SocketBody> body)
+ : FileHandle(std::auto_ptr<FileBody>(body.release()))
{}
-template <class SocketPolicy>
-prefix_ senf::SocketHandle<SocketPolicy>::SocketHandle(FileHandle other, bool isChecked)
+template <class SPolicy>
+prefix_ senf::SocketHandle<SPolicy>::SocketHandle(FileHandle other, bool isChecked)
: FileHandle(other)
{
- BOOST_ASSERT( isChecked );
- BOOST_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
+ SENF_ASSERT( isChecked );
+ SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
}
-template <class SocketPolicy>
-prefix_ senf::SocketBody & senf::SocketHandle<SocketPolicy>::body()
+template <class SPolicy>
+prefix_ senf::SocketBody & senf::SocketHandle<SPolicy>::body()
{
- BOOST_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
+ SENF_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) );
return static_cast<SocketBody &>(FileHandle::body());
}
-template <class SocketPolicy>
-prefix_ senf::SocketBody const & senf::SocketHandle<SocketPolicy>::body()
+template <class SPolicy>
+prefix_ senf::SocketBody const & senf::SocketHandle<SPolicy>::body()
const
{
- BOOST_ASSERT( dynamic_cast<SocketBody const *>(&FileHandle::body()) );
+ SENF_ASSERT( dynamic_cast<SocketBody const *>(&FileHandle::body()) );
return static_cast<SocketBody const &>(FileHandle::body());
}
-template <class SocketPolicy>
-prefix_ senf::SocketProtocol const & senf::SocketHandle<SocketPolicy>::protocol()
+template <class SPolicy>
+prefix_ senf::SocketProtocol & senf::SocketHandle<SPolicy>::protocol()
const
{
return body().protocol();
}
-template <class SocketPolicy>
-prefix_ void senf::SocketHandle<SocketPolicy>::assign(FileHandle other)
+template <class SPolicy>
+prefix_ void senf::SocketHandle<SPolicy>::assign(FileHandle other)
{
FileHandle::operator=(other);
}
-template <class SocketPolicy>
-prefix_ senf::SocketHandle<SocketPolicy>
-senf::SocketHandle<SocketPolicy>::cast_static(FileHandle handle)
+template <class SPolicy>
+prefix_ senf::SocketHandle<SPolicy>
+senf::SocketHandle<SPolicy>::cast_static(FileHandle handle)
{
return SocketHandle(handle,true);
}
-template <class SocketPolicy>
-prefix_ senf::SocketHandle<SocketPolicy>
-senf::SocketHandle<SocketPolicy>::cast_dynamic(FileHandle handle)
+template <class SPolicy>
+prefix_ senf::SocketHandle<SPolicy>
+senf::SocketHandle<SPolicy>::cast_dynamic(FileHandle handle)
{
// throws bad_cast if the body is not a SocketBody
SocketBody & body (dynamic_cast<SocketBody&>(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);
}
boost::is_convertible<Target*,FileHandle*>::value &&
( boost::is_convertible<Source,Target>::value ||
boost::is_convertible<Target,Source>::value ) ));
- BOOST_ASSERT( check_socket_cast<Target>(handle) );
+ SENF_ASSERT( check_socket_cast<Target>(handle) );
return Target::cast_static(handle);
}
template <class Target, class Source>
prefix_ Target senf::dynamic_socket_cast(Source handle)
{
- BOOST_STATIC_ASSERT((
- boost::is_convertible<Source*,FileHandle*>::value &&
- boost::is_convertible<Target*,FileHandle*>::value &&
- ( boost::is_convertible<Source,Target>::value ||
- boost::is_convertible<Target,Source>::value ) ));
- return Target::cast_dynamic(handle);
+// BOOST_STATIC_ASSERT((
+// boost::is_convertible<Source*,FileHandle*>::value &&
+// boost::is_convertible<Target*,FileHandle*>::value &&
+// ( boost::is_convertible<Source,Target>::value ||
+// boost::is_convertible<Target,Source>::value ) ));
+ try {
+ return Target::cast_dynamic(handle);
+ }
+ SENF_WRAP_EXC(std::bad_cast)
}
template <class Target, class Source>
prefix_ bool senf::check_socket_cast(Source handle)
{
- BOOST_STATIC_ASSERT((
- boost::is_convertible<Source*,FileHandle*>::value &&
- boost::is_convertible<Target*,FileHandle*>::value &&
- ( boost::is_convertible<Source,Target>::value ||
- boost::is_convertible<Target,Source>::value ) ));
+// BOOST_STATIC_ASSERT((
+// boost::is_convertible<Source*,FileHandle*>::value &&
+// boost::is_convertible<Target*,FileHandle*>::value &&
+// ( boost::is_convertible<Source,Target>::value ||
+// boost::is_convertible<Target,Source>::value ) ));
// we don't have a non-throwing variant of cast_dynamic
// for two reasons:
// a) since the handle is passed back by value, we cannot return
return true;
}
-template <class SocketPolicy>
-prefix_ void senf::SocketHandle<SocketPolicy>::state(SocketStateMap & map, unsigned lod)
+template <class SPolicy>
+prefix_ void senf::SocketHandle<SPolicy>::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 <class SocketPolicy>
-prefix_ std::string senf::SocketHandle<SocketPolicy>::dumpState(unsigned lod)
+template <class SPolicy>
+prefix_ std::string senf::SocketHandle<SPolicy>::dumpState(unsigned lod)
{
SocketStateMap map;
state(map,lod);
return detail::dumpState(map);
}
+template <class SPolicy>
+template <class Facet>
+prefix_ Facet & senf::SocketHandle<SPolicy>::facet()
+
+{
+ try {
+ return dynamic_cast<Facet &>(protocol());
+ }
+ SENF_WRAP_EXC(std::bad_cast)
+}
+
///////////////////////////////////////////////////////////////////////////
-// senf::detail::ConvertibleString
+// senf::ProtocolSocketBody<SProtocol>
-template <class T>
-prefix_ senf::detail::ConvertibleString::ConvertibleString(T const & other)
- : std::string(boost::lexical_cast<std::string>(other))
+template <class SProtocol>
+prefix_ senf::ProtocolSocketBody<SProtocol>::ProtocolSocketBody(bool isServer)
+ : SocketBody(isServer)
{}
+template <class SProtocol>
+prefix_ senf::ProtocolSocketBody<SProtocol>::ProtocolSocketBody(bool isServer, int fd)
+ : SocketBody(isServer, fd)
+{}
+
+///////////////////////////////////////////////////////////////////////////
+
+template <class SPolicy>
+prefix_ std::ostream & senf::operator<<(std::ostream & os, SocketHandle<SPolicy> handle)
+{
+ os << handle.dumpState();
+ return os;
+}
+
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
// End: