Skip to content
Snippets Groups Projects
Commit b968e7d9 authored by sbund's avatar sbund
Browse files

Finished SocketHandle state() implementation

parent 3f4a9a83
No related branches found
No related tags found
No related merge requests found
Showing with 193 additions and 7 deletions
......@@ -197,6 +197,21 @@ satcom::lib::ClientSocketHandle<Policy>::cast_dynamic(FileHandle handle)
return cast_static(handle);
}
template <class Policy>
prefix_ void satcom::lib::ClientSocketHandle<Policy>::state(SocketStateMap & map, unsigned lod)
{
map["handle"] = prettyName(typeid(*this));
this->body().state(map,lod);
}
template <class Policy>
prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::dumpState(unsigned lod)
{
SocketStateMap map;
state(map,lod);
return detail::dumpState(map);
}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
......
......@@ -125,7 +125,11 @@ namespace lib {
static ClientSocketHandle cast_static(FileHandle handle);
static ClientSocketHandle cast_dynamic(FileHandle handle);
// we need to override both since SocketHandle is *not* polymorphic
void state(SocketStateMap & map, unsigned lod=0);
std::string dumpState(unsigned lod=0);
protected:
ClientSocketHandle(FileHandle other, bool isChecked);
explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
......
......@@ -74,6 +74,24 @@ satcom::lib::ProtocolClientSocketHandle<SocketProtocol>::cast_dynamic(FileHandle
return cast_static(handle);
}
template <class SocketProtocol>
prefix_ void
satcom::lib::ProtocolClientSocketHandle<SocketProtocol>::state(SocketStateMap & map,
unsigned lod)
{
map["handle"] = prettyName(typeid(*this));
this->body().state(map,lod);
}
template <class SocketProtocol>
prefix_ std::string
satcom::lib::ProtocolClientSocketHandle<SocketProtocol>::dumpState(unsigned lod)
{
SocketStateMap map;
state(map,lod);
return detail::dumpState(map);
}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
......
......@@ -63,6 +63,9 @@ namespace lib {
static ProtocolClientSocketHandle cast_static(FileHandle handle);
static ProtocolClientSocketHandle cast_dynamic(FileHandle handle);
void state(SocketStateMap & map, unsigned lod=0);
std::string dumpState(unsigned lod=0);
protected:
ProtocolClientSocketHandle(FileHandle other, bool isChecked);
......
......@@ -75,6 +75,24 @@ satcom::lib::ProtocolServerSocketHandle<SocketProtocol>::cast_dynamic(FileHandle
return cast_static(handle);
}
template <class SocketProtocol>
prefix_ void
satcom::lib::ProtocolServerSocketHandle<SocketProtocol>::state(SocketStateMap & map,
unsigned lod)
{
map["handle"] = prettyName(typeid(*this));
this->body().state(map,lod);
}
template <class SocketProtocol>
prefix_ std::string
satcom::lib::ProtocolServerSocketHandle<SocketProtocol>::dumpState(unsigned lod)
{
SocketStateMap map;
state(map,lod);
return detail::dumpState(map);
}
template <class SocketProtocol>
prefix_ satcom::lib::ProtocolServerSocketHandle<SocketProtocol>::
ProtocolServerSocketHandle(FileHandle other, bool isChecked)
......
......@@ -65,6 +65,9 @@ namespace lib {
static ProtocolServerSocketHandle cast_static(FileHandle handle);
static ProtocolServerSocketHandle cast_dynamic(FileHandle handle);
void state(SocketStateMap & map, unsigned lod=0);
std::string dumpState(unsigned lod=0);
protected:
ProtocolServerSocketHandle(FileHandle other, bool isChecked);
......
......@@ -64,6 +64,15 @@ BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle)
MySocketHandle::ClientSocketHandle client = h.accept();
BOOST_CHECK_EQUAL( client.fd(), -1 );
BOOST_CHECK_EQUAL( h.dumpState(),
"handle: satcom::lib::ProtocolServerSocketHandle<(anonymous namespace)::MyProtocol>\n"
"file.handle: -1\n"
"file.refcount: 2\n"
"socket.policy: satcom::lib::SocketPolicy<satcom::lib::test::SomeAddressingPolicy, satcom::lib::test::SomeFramingPolicy, satcom::lib::test::SomeCommunicationPolicy, satcom::lib::test::SomeReadPolicy, satcom::lib::test::SomeWritePolicy, satcom::lib::test::SomeBufferingPolicy>\n"
"socket.protocol: (anonymous namespace)::MyProtocol\n"
"socket.server: true\n" );
}
{
......
......@@ -135,6 +135,21 @@ satcom::lib::ServerSocketHandle<Policy>::cast_dynamic(FileHandle handle)
return cast_static(handle);
}
template <class Policy>
prefix_ void satcom::lib::ServerSocketHandle<Policy>::state(SocketStateMap & map, unsigned lod)
{
map["handle"] = prettyName(typeid(*this));
this->body().state(map,lod);
}
template <class Policy>
prefix_ std::string satcom::lib::ServerSocketHandle<Policy>::dumpState(unsigned lod)
{
SocketStateMap map;
state(map,lod);
return detail::dumpState(map);
}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
......
......@@ -98,6 +98,10 @@ namespace lib {
static ServerSocketHandle cast_static(FileHandle handle);
static ServerSocketHandle cast_dynamic(FileHandle handle);
// we need to override both since SocketHandle is *not* polymorphic
void state(SocketStateMap & map, unsigned lod=0);
std::string dumpState(unsigned lod=0);
protected:
ServerSocketHandle(FileHandle other, bool isChecked);
explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol);
......
......@@ -28,6 +28,7 @@
// Custom includes
#include <sstream>
#include <sys/socket.h>
#include "Utils/TypeInfo.hh"
//#include "SocketHandle.mpp"
#define prefix_
......@@ -63,8 +64,11 @@ prefix_ bool satcom::lib::SocketBody::v_eof()
prefix_ void satcom::lib::SocketBody::state(SocketStateMap & map, unsigned lod)
{
map["handle.server"] = isServer() ? "true" : "false";
map["handle.protocol"] = typeid(protocol()).name();
map["file.handle"] = fd();
map["file.refcount"] = refcount();
map["socket.server"] = isServer();
map["socket.protocol"] = prettyName(typeid(protocol()));
map["socket.policy"] = prettyName(typeid(protocol().policy()));
protocol().state(map,lod);
}
......
......@@ -58,6 +58,16 @@ prefix_ bool satcom::lib::SocketBody::isServer()
return isServer_;
}
///////////////////////////////////////////////////////////////////////////
// satcom::lib::detail::ConvertibleString
prefix_ satcom::lib::detail::ConvertibleString::ConvertibleString()
{}
prefix_ satcom::lib::detail::ConvertibleString::ConvertibleString(bool v)
: std::string(v ? "true" : "false")
{}
///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_
......
// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.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
// 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.
// Definition of non-inline template functions
#include "SocketHandle.ih"
// Custom includes
#include <boost/lexical_cast.hpp>
#define prefix_
///////////////////////////////ct.p////////////////////////////////////////
template <class T>
prefix_ satcom::lib::detail::ConvertibleString &
satcom::lib::detail::ConvertibleString::operator+=(ConvertibleString const & other)
{
if (!empty())
this->std::string::operator+=(", ");
this->std::string::operator+=(other);
return *this;
}
///////////////////////////////ct.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
......@@ -26,6 +26,8 @@
// Custom includes
#include <typeinfo>
#include <boost/lexical_cast.hpp>
#include "Utils/TypeInfo.hh"
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
......@@ -156,6 +158,7 @@ prefix_ bool satcom::lib::check_socket_cast(Source handle)
template <class SocketPolicy>
prefix_ void satcom::lib::SocketHandle<SocketPolicy>::state(SocketStateMap & map, unsigned lod)
{
map["handle"] = prettyName(typeid(*this));
body().state(map,lod);
}
......@@ -167,6 +170,13 @@ prefix_ std::string satcom::lib::SocketHandle<SocketPolicy>::dumpState(unsigned
return detail::dumpState(map);
}
///////////////////////////////////////////////////////////////////////////
// satcom::lib::detail::ConvertibleString
template <class T>
prefix_ satcom::lib::detail::ConvertibleString::ConvertibleString(T const & other)
: std::string(boost::lexical_cast<std::string>(other))
{}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
......
......@@ -20,6 +20,9 @@
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// TODO: Create a SocketHandleBase class and move some non-Policy
// dependent code there
#ifndef HH_SocketHandle_
#define HH_SocketHandle_ 1
......@@ -76,8 +79,8 @@ namespace lib {
static SocketHandle cast_static(FileHandle handle);
static SocketHandle cast_dynamic(FileHandle handle);
void state(SocketStateMap & map, unsigned lod);
std::string dumpState(unsigned lod);
void state(SocketStateMap & map, unsigned lod=0);
std::string dumpState(unsigned lod=0);
protected:
explicit SocketHandle(std::auto_ptr<SocketProtocol> protocol, bool isServer);
......@@ -108,7 +111,7 @@ namespace lib {
///////////////////////////////hh.e////////////////////////////////////////
#include "SocketHandle.cci"
//#include "SocketHandle.ct"
#include "SocketHandle.ct"
#include "SocketHandle.cti"
#endif
......
......@@ -37,6 +37,17 @@ namespace lib {
class SocketProtocol;
namespace detail {
class ConvertibleString : public std::string
{
public:
ConvertibleString();
ConvertibleString(bool v);
template <class T>
ConvertibleString(T const & other);
template <class T>
ConvertibleString & operator+= (ConvertibleString const & other);
};
struct StateMapOrdering
: public std::binary_function<std::string,std::string,bool>
......@@ -46,7 +57,7 @@ namespace lib {
}
typedef std::map< std::string, std::string, detail::StateMapOrdering > SocketStateMap;
typedef std::map< std::string, detail::ConvertibleString, detail::StateMapOrdering > SocketStateMap;
namespace detail {
std::string dumpState(SocketStateMap const & map);
......
......@@ -86,6 +86,15 @@ BOOST_AUTO_UNIT_TEST(socketHandle)
BOOST_CHECK_THROW( satcom::lib::dynamic_socket_cast<SomeSocketHandle>(
satcom::lib::FileHandle(FDHandle())),
std::bad_cast );
BOOST_CHECK_EQUAL( myh.dumpState(),
"handle: satcom::lib::SocketHandle<satcom::lib::SocketPolicy<satcom::lib::test::SomeAddressingPolicy, satcom::lib::test::SomeFramingPolicy, satcom::lib::test::SomeCommunicationPolicy, satcom::lib::test::SomeReadPolicy, satcom::lib::test::SomeWritePolicy, satcom::lib::test::SomeBufferingPolicy> >\n"
"file.handle: -1\n"
"file.refcount: 3\n"
"socket.policy: satcom::lib::SocketPolicy<satcom::lib::test::SomeAddressingPolicy, satcom::lib::test::SomeFramingPolicy, satcom::lib::test::SomeCommunicationPolicy, satcom::lib::test::SomeReadPolicy, satcom::lib::test::SomeWritePolicy, satcom::lib::test::SomeBufferingPolicy>\n"
"socket.protocol: satcom::lib::test::SomeProtocol\n"
"socket.server: false\n" );
}
///////////////////////////////cc.e////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment