Socket: Add a 'facet<>()' member to access protocol-facets from generic socket handles
[senf.git] / Socket / SocketHandle.cti
index f059c56..cbd9089 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// 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
@@ -113,7 +113,7 @@ 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
+    // throws bad_cast if the policy is not compatible (already wrapped ...)
     SPolicy::checkBaseOf(body.protocol().policy());
     return cast_static(handle);
 }
@@ -138,7 +138,10 @@ prefix_ Target senf::dynamic_socket_cast(Source handle)
         boost::is_convertible<Target*,FileHandle*>::value &&
         ( boost::is_convertible<Source,Target>::value ||
           boost::is_convertible<Target,Source>::value ) ));
-    return Target::cast_dynamic(handle);
+    try {
+        return Target::cast_dynamic(handle);
+    }
+    SENF_WRAP_EXC(std::bad_cast)
 }
 
 template <class Target, class Source>
@@ -184,6 +187,17 @@ prefix_ std::string senf::SocketHandle<SPolicy>::dumpState(unsigned lod)
     return detail::dumpState(map);
 }
 
+template <class SPolicy>
+template <class Facet>
+prefix_ Facet const & senf::SocketHandle<SPolicy>::facet()
+
+{
+    try {
+        return dynamic_cast<Facet const &>(protocol());
+    }
+    SENF_WRAP_EXC(std::bad_cast)
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::ProtocolSocketBody<SProtocol>