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

started ServerSocketHandle interface

parent c2d39593
No related branches found
No related tags found
No related merge requests found
// $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.
#ifndef HH_AddressingPolicy_
#define HH_AddressingPolicy_ 1
// Custom includes
#include "SocketPolicy.hh"
//#include "AddressingPolicy.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace satcom {
namespace lib {
struct NoAddressingPolicy : public AddressingPolicyBase
{
typedef satcom::lib::nil Address;
};
}}
///////////////////////////////hh.e////////////////////////////////////////
//#include "AddressingPolicy.cci"
//#include "AddressingPolicy.ct"
//#include "AddressingPolicy.cti"
//#include "AddressingPolicy.mpp"
#endif
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
namespace satcom { namespace satcom {
namespace lib { namespace lib {
template <class Policy> class ServerSocketHandle;
/** \brief /** \brief
*/ */
template <class Policy> template <class Policy>
...@@ -45,6 +47,7 @@ namespace lib { ...@@ -45,6 +47,7 @@ namespace lib {
typedef typename Policy::AddressingPolicy::Address Address; typedef typename Policy::AddressingPolicy::Address Address;
typedef typename boost::call_traits<Address>::param_type AddressParam; typedef typename boost::call_traits<Address>::param_type AddressParam;
typedef ServerSocketHandle<Policy> ServerSocketHandle;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///\name Structors and default members ///\name Structors and default members
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
// Custom includes // Custom includes
#include "ProtocolServerSocketHandle.hh" #include "ProtocolServerSocketHandle.hh"
#include "SocketProtocol.test.hh" #include "ServerSocketHandle.test.hh"
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle) BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle)
{ {
typedef satcom::lib::ProtocolServerSocketHandle<satcom::lib::test::SomeProtocol> MySocketHandle; typedef satcom::lib::ProtocolServerSocketHandle<
satcom::lib::test::SomeConnectedProtocol> MySocketHandle;
MySocketHandle h; MySocketHandle h;
h.protocol(); h.protocol();
......
...@@ -52,6 +52,37 @@ satcom::lib::ServerSocketHandle<SocketPolicy>::operator=(ServerSocketHandle<Othe ...@@ -52,6 +52,37 @@ satcom::lib::ServerSocketHandle<SocketPolicy>::operator=(ServerSocketHandle<Othe
return *this; return *this;
} }
///////////////////////////////////////////////////////////////////////////
// Server socket interface
template <class Policy>
prefix_ void satcom::lib::ServerSocketHandle<Policy>::bind(AddressParam addr)
{
Policy::AddressingPolicy::bind(*this,addr);
}
template <class Policy>
prefix_ typename satcom::lib::ServerSocketHandle<Policy>::Address
satcom::lib::ServerSocketHandle<Policy>::local()
{
typename Policy::AddressingPolicy::Address addr;
this->local(addr);
return addr;
}
template <class Policy>
prefix_ void satcom::lib::ServerSocketHandle<Policy>::local(Address & addr)
{
Policy::AddressingPolicy::local(*this,addr);
}
template <class Policy>
prefix_ typename satcom::lib::ServerSocketHandle<Policy>::ClientSocketHandle
satcom::lib::ServerSocketHandle<Policy>::accept()
{
return Policy::CommunicationPolicy::accept(*this);
}
///////////////////////////////cti.e/////////////////////////////////////// ///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_ #undef prefix_
......
...@@ -24,7 +24,11 @@ ...@@ -24,7 +24,11 @@
#define HH_ServerSocketHandle_ 1 #define HH_ServerSocketHandle_ 1
// Custom includes // Custom includes
#include <boost/static_assert.hpp>
#include <boost/call_traits.hpp>
#include "SocketHandle.hh" #include "SocketHandle.hh"
#include "CommunicationPolicy.hh"
#include "AddressingPolicy.hh"
//#include "ServerSocketHandle.mpp" //#include "ServerSocketHandle.mpp"
///////////////////////////////hh.p//////////////////////////////////////// ///////////////////////////////hh.p////////////////////////////////////////
...@@ -32,16 +36,28 @@ ...@@ -32,16 +36,28 @@
namespace satcom { namespace satcom {
namespace lib { namespace lib {
template <class Policy> class ClientSocketHandle;
/** \brief /** \brief
*/ */
template <class SocketPolicy> template <class Policy>
class ServerSocketHandle class ServerSocketHandle
: public SocketHandle<SocketPolicy> : public SocketHandle<Policy>
{ {
// FIXME: Are theese necessary ... hmm ...
BOOST_STATIC_ASSERT((boost::is_convertible< typename Policy::CommunicationPolicy *,
ConnectedCommunicationPolicy *>::value ));
BOOST_STATIC_ASSERT(!(boost::is_convertible< typename Policy::AddressingPolicy *,
NoAddressingPolicy *>::value ));
public: public:
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Types // Types
typedef typename Policy::AddressingPolicy::Address Address;
typedef typename boost::call_traits<Address>::param_type AddressParam;
typedef ClientSocketHandle<Policy> ClientSocketHandle;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///\name Structors and default members ///\name Structors and default members
///@{ ///@{
...@@ -54,14 +70,28 @@ namespace lib { ...@@ -54,14 +70,28 @@ namespace lib {
// conversion constructors // conversion constructors
template <class OtherPolicy> template <class OtherPolicy>
ServerSocketHandle(ServerSocketHandle<OtherPolicy> other, ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
typename SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type * = 0); typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
template <class OtherPolicy>
typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
operator=(ServerSocketHandle<OtherPolicy> other);
///@} ///@}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template <class OtherPolicy> ///////////////////////////////////////////////////////////////////////////
typename SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type const & ///\name Server socket interface
operator=(ServerSocketHandle<OtherPolicy> other); ///@{
void bind (AddressParam addr);
Address local ();
void local (Address & addr);
ClientSocketHandle
accept ();
///@}
protected: protected:
explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol); explicit ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol);
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
// Custom includes // Custom includes
#include "ServerSocketHandle.hh" #include "ServerSocketHandle.hh"
#include "SocketProtocol.test.hh" #include "ServerSocketHandle.test.hh"
#include "ClientSocketHandle.hh"
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
...@@ -36,14 +37,16 @@ ...@@ -36,14 +37,16 @@
///////////////////////////////cc.p//////////////////////////////////////// ///////////////////////////////cc.p////////////////////////////////////////
namespace { namespace {
namespace sl = satcom::lib; namespace sl = satcom::lib;
class MySocketHandle class MySocketHandle
: public sl::ServerSocketHandle<sl::test::SomeProtocol::Policy> : public sl::ServerSocketHandle<sl::test::SomeConnectedProtocol::Policy>
{ {
public: public:
MySocketHandle() MySocketHandle()
: sl::ServerSocketHandle<sl::test::SomeProtocol::Policy>(std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeProtocol())) : sl::ServerSocketHandle<sl::test::SomeConnectedProtocol::Policy>(
std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeConnectedProtocol()))
{} {}
}; };
} }
...@@ -60,6 +63,10 @@ BOOST_AUTO_UNIT_TEST(serverSocketHandle) ...@@ -60,6 +63,10 @@ BOOST_AUTO_UNIT_TEST(serverSocketHandle)
MySocketHandle myh; MySocketHandle myh;
OtherSocketHandle ssh (myh); OtherSocketHandle ssh (myh);
ssh = myh; ssh = myh;
BOOST_CHECK_NO_THROW( myh.bind(0) );
BOOST_CHECK_EQUAL( myh.local(), 2u );
// BOOST_CHECK_NO_THROW( myh.accept() );
} }
......
// $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.
#ifndef HH_ServerSocketHandle_test_
#define HH_ServerSocketHandle_test_ 1
// Custom includes
#include "SocketPolicy.test.hh"
#include "SocketProtocol.hh"
//#include "ServerSocketHandle.test.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace satcom {
namespace lib {
namespace test {
typedef satcom::lib::MakeSocketPolicy<
SomeAddressingPolicy,
SomeFramingPolicy,
ConnectedCommunicationPolicy,
SomeReadPolicy,
SomeWritePolicy,
SomeBufferingPolicy
>::policy SomeConnectedPolicy;
class SomeConnectedProtocol
: public ConcreteSocketProtocol<SomeConnectedPolicy>
{
~SomeConnectedProtocol() {}
void init_client() const {}
void init_server() const {}
unsigned available() const { return Policy::ReadPolicy::TEST_SIZE; }
bool eof() const { return false; }
};
}}}
///////////////////////////////hh.e////////////////////////////////////////
//#include "ServerSocketHandle.test.cci"
//#include "ServerSocketHandle.test.ct"
//#include "ServerSocketHandle.test.cti"
//#include "ServerSocketHandle.test.mpp"
#endif
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
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