diff --git a/Socket/FileHandle.cci b/Socket/FileHandle.cci index 4e3269ccdec9238a3a33d4c79e0e2905449dee85..b04e7f25169ffc930350c58e411899c4170573b3 100644 --- a/Socket/FileHandle.cci +++ b/Socket/FileHandle.cci @@ -96,62 +96,73 @@ prefix_ bool satcom::lib::FileBody::ok() prefix_ void satcom::lib::FileHandle::close() { - body_->close(); + body().close(); } prefix_ void satcom::lib::FileHandle::terminate() { - body_->terminate(); + body().terminate(); } prefix_ void satcom::lib::FileHandle::flush() { - body_->flush(); + body().flush(); } prefix_ bool satcom::lib::FileHandle::readable() const { - return body_->readable(); + return body().readable(); } prefix_ bool satcom::lib::FileHandle::writeable() const { - return body_->writeable(); + return body().writeable(); } prefix_ bool satcom::lib::FileHandle::valid() const { - return body_->valid(); + return body().valid(); } prefix_ satcom::lib::FileHandle::operator bool () const { - return body_->ok(); + return body().ok(); } prefix_ bool satcom::lib::FileHandle::operator!() const { - return ! body_->ok(); + return ! body().ok(); } prefix_ int satcom::lib::FileHandle::fd() const { - return body_->fd(); + return body().fd(); } prefix_ satcom::lib::FileHandle::FileHandle(std::auto_ptr<FileBody> body) : body_(body.release()) {} +prefix_ satcom::lib::FileBody & satcom::lib::FileHandle::body() +{ + return *body_; +} + +prefix_ satcom::lib::FileBody const & satcom::lib::FileHandle::body() + const +{ + return *body_; +} + prefix_ int satcom::lib::FileHandle::fd(int fd) { - return body_->fd(fd); + return body().fd(fd); } ///////////////////////////////cci.e/////////////////////////////////////// diff --git a/Socket/FileHandle.hh b/Socket/FileHandle.hh index 70ed6985ea2349876d5f2122bd7890e15b505e2e..6f21f32ac5dc4249536fcead63d12628c3a430fd 100644 --- a/Socket/FileHandle.hh +++ b/Socket/FileHandle.hh @@ -74,6 +74,9 @@ namespace lib { protected: explicit FileHandle(std::auto_ptr<FileBody> body); + FileBody & body(); + FileBody const & body() const; + int fd(int fd); private: diff --git a/Socket/ProtocolClientSocketHandle.cti b/Socket/ProtocolClientSocketHandle.cti new file mode 100644 index 0000000000000000000000000000000000000000..bb7b6b0b0319ff26f05b89513c5f5a2a57b58639 --- /dev/null +++ b/Socket/ProtocolClientSocketHandle.cti @@ -0,0 +1,53 @@ +// $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 inline template functions + +//#include "ProtocolClientSocketHandle.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +template <class SocketProtocol> +prefix_ satcom::lib::ProtocolClientSocketHandle<SocketProtocol>::ProtocolClientSocketHandle() + : ClientSocketHandle<typename SocketProtocol::Policy>( + std::auto_ptr<satcom::lib::SocketProtocol>(new SocketProtocol())) +{} + +template <class SocketProtocol> +prefix_ SocketProtocol const & +satcom::lib::ProtocolClientSocketHandle<SocketProtocol>::protocol() +{ + BOOST_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()) ); + return static_cast<SocketProtocol const &>(this->body().protocol()); +} + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: diff --git a/Socket/ProtocolClientSocketHandle.hh b/Socket/ProtocolClientSocketHandle.hh index 7872b645b3c9bbc9e90bf0b3320b1f74ae71005d..42ef2d187c49febab29ca07118ecf46a6f6fab8a 100644 --- a/Socket/ProtocolClientSocketHandle.hh +++ b/Socket/ProtocolClientSocketHandle.hh @@ -24,6 +24,7 @@ #define HH_ProtocolClientSocketHandle_ 1 // Custom includes +#include "ClientSocketHandle.hh" //#include "ProtocolClientSocketHandle.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -47,24 +48,14 @@ namespace lib { ///\name Structors and default members ///@{ - // default default constructor - // default copy constructor - // default copy assignment - // default destructor - - // no conversion constructors + // TODO: Non-default constructors (via argument forwarding + // to the SocketProtocol::init(...) methods + ProtocolClientSocketHandle(); ///@} /////////////////////////////////////////////////////////////////////////// - ///\name Accessors - ///@{ - ///@} - /////////////////////////////////////////////////////////////////////////// - ///\name Mutators - ///@{ - - ///@} + Protocol const & protocol(); protected: @@ -77,7 +68,7 @@ namespace lib { ///////////////////////////////hh.e//////////////////////////////////////// //#include "ProtocolClientSocketHandle.cci" //#include "ProtocolClientSocketHandle.ct" -//#include "ProtocolClientSocketHandle.cti" +#include "ProtocolClientSocketHandle.cti" #endif diff --git a/Socket/ProtocolClientSocketHandle.test.cc b/Socket/ProtocolClientSocketHandle.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..9b078e8daee923b18ba204901c1657dee2025203 --- /dev/null +++ b/Socket/ProtocolClientSocketHandle.test.cc @@ -0,0 +1,90 @@ +// $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. + +// Unit tests + +//#include "ProtocolClientSocketHandle.test.hh" +//#include "ProtocolClientSocketHandle.test.ih" + +// Custom includes +#include "ProtocolClientSocketHandle.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +namespace { + namespace sl = satcom::lib; + + struct INetAddressingPolicy : public sl::AddressingPolicyBase {}; + struct UnixAddressingPolicy : public sl::AddressingPolicyBase {}; + + struct StreamFramingPolicy : public sl::FramingPolicyBase {}; + struct DgramFramingPolicy : public sl::FramingPolicyBase {}; + + struct ConnectedCommunicationPolicy : public sl::CommunicationPolicyBase {}; + struct UnconnectedCommunicationPolicy : public sl::CommunicationPolicyBase {}; + + struct ReadablePolicy : public sl::ReadPolicyBase {}; + struct UnreadablePolicy : public sl::ReadPolicyBase {}; + + struct WritablePolicy : public sl::WritePolicyBase {}; + struct UnwritablePolicy : public sl::WritePolicyBase {}; + + struct SocketBufferingPolicy : public sl::BufferingPolicyBase {}; + + typedef sl::MakeSocketPolicy< + INetAddressingPolicy, + StreamFramingPolicy, + ConnectedCommunicationPolicy, + ReadablePolicy, + WritablePolicy, + SocketBufferingPolicy + >::policy MyProtocol_Policy; + + class MyProtocol + : public sl::ConcreteSocketProtocol<MyProtocol_Policy> + { + public: + ~MyProtocol() {} + }; + +} + +BOOST_AUTO_UNIT_TEST(protocolClientSocketHandle) +{ + typedef sl::ProtocolClientSocketHandle<MyProtocol> MySocketHandle; + + MySocketHandle h; + h.protocol(); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: diff --git a/Socket/ProtocolServerSocketHandle.cti b/Socket/ProtocolServerSocketHandle.cti new file mode 100644 index 0000000000000000000000000000000000000000..16b72adbf54d70171d5c18c22274bac1ad0d6fb9 --- /dev/null +++ b/Socket/ProtocolServerSocketHandle.cti @@ -0,0 +1,54 @@ +// $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 inline template functions + +//#include "ProtocolServerSocketHandle.ih" + +// Custom includes + +#define prefix_ inline +///////////////////////////////cti.p/////////////////////////////////////// + +template <class SocketProtocol> +prefix_ satcom::lib::ProtocolServerSocketHandle<SocketProtocol>::ProtocolServerSocketHandle() + : ServerSocketHandle<typename SocketProtocol::Policy>( + std::auto_ptr<satcom::lib::SocketProtocol>(new SocketProtocol())) +{} + +template <class SocketProtocol> +prefix_ SocketProtocol const & +satcom::lib::ProtocolServerSocketHandle<SocketProtocol>::protocol() +{ + BOOST_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()) ); + return static_cast<SocketProtocol const &>(this->body().protocol()); +} + + +///////////////////////////////cti.e/////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: diff --git a/Socket/ProtocolServerSocketHandle.hh b/Socket/ProtocolServerSocketHandle.hh new file mode 100644 index 0000000000000000000000000000000000000000..4d468b72c0cb5e91bbfbb5a6310a5a2ec0735ed4 --- /dev/null +++ b/Socket/ProtocolServerSocketHandle.hh @@ -0,0 +1,78 @@ +// $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_ProtocolServerSocketHandle_ +#define HH_ProtocolServerSocketHandle_ 1 + +// Custom includes +#include "ServerSocketHandle.hh" + +//#include "ProtocolServerSocketHandle.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace satcom { +namespace lib { + + /** \brief + */ + template <class SocketProtocol> + class ProtocolServerSocketHandle + : public ServerSocketHandle<typename SocketProtocol::Policy> + { + public: + /////////////////////////////////////////////////////////////////////////// + // Types + + typedef SocketProtocol Protocol; + + /////////////////////////////////////////////////////////////////////////// + ///\name Structors and default members + ///@{ + + // TODO: Non-default constructors (via argument forwarding + // to the SocketProtocol::init(...) methods + ProtocolServerSocketHandle(); + + ///@} + /////////////////////////////////////////////////////////////////////////// + + Protocol const & protocol(); + + protected: + + private: + + }; + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "ProtocolServerSocketHandle.cci" +//#include "ProtocolServerSocketHandle.ct" +#include "ProtocolServerSocketHandle.cti" +#endif + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: diff --git a/Socket/ProtocolServerSocketHandle.test.cc b/Socket/ProtocolServerSocketHandle.test.cc new file mode 100644 index 0000000000000000000000000000000000000000..c44791200f24978275afa68f666d8811b067bbb5 --- /dev/null +++ b/Socket/ProtocolServerSocketHandle.test.cc @@ -0,0 +1,90 @@ +// $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. + +// Unit tests + +//#include "ProtocolServerSocketHandle.test.hh" +//#include "ProtocolServerSocketHandle.test.ih" + +// Custom includes +#include "ProtocolServerSocketHandle.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +namespace { + namespace sl = satcom::lib; + + struct INetAddressingPolicy : public sl::AddressingPolicyBase {}; + struct UnixAddressingPolicy : public sl::AddressingPolicyBase {}; + + struct StreamFramingPolicy : public sl::FramingPolicyBase {}; + struct DgramFramingPolicy : public sl::FramingPolicyBase {}; + + struct ConnectedCommunicationPolicy : public sl::CommunicationPolicyBase {}; + struct UnconnectedCommunicationPolicy : public sl::CommunicationPolicyBase {}; + + struct ReadablePolicy : public sl::ReadPolicyBase {}; + struct UnreadablePolicy : public sl::ReadPolicyBase {}; + + struct WritablePolicy : public sl::WritePolicyBase {}; + struct UnwritablePolicy : public sl::WritePolicyBase {}; + + struct SocketBufferingPolicy : public sl::BufferingPolicyBase {}; + + typedef sl::MakeSocketPolicy< + INetAddressingPolicy, + StreamFramingPolicy, + ConnectedCommunicationPolicy, + ReadablePolicy, + WritablePolicy, + SocketBufferingPolicy + >::policy MyProtocol_Policy; + + class MyProtocol + : public sl::ConcreteSocketProtocol<MyProtocol_Policy> + { + public: + ~MyProtocol() {} + }; + +} + +BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle) +{ + typedef sl::ProtocolServerSocketHandle<MyProtocol> MySocketHandle; + + MySocketHandle h; + h.protocol(); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: diff --git a/Socket/SocketHandle.cci b/Socket/SocketHandle.cci index 226cfde238a0ddb1861e65b9eef82a007cc34432..d967d1b2d0b899a38948c79c980ffa16eacf5be5 100644 --- a/Socket/SocketHandle.cci +++ b/Socket/SocketHandle.cci @@ -33,6 +33,12 @@ prefix_ satcom::lib::SocketBody::SocketBody(std::auto_ptr<SocketProtocol> protoc : protocol_(protocol) {} +prefix_ satcom::lib::SocketProtocol const & satcom::lib::SocketBody::protocol() + const +{ + return *protocol_; +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Socket/SocketHandle.cti b/Socket/SocketHandle.cti index 88c55c53064c92eb1f031d91394994ebd9bf9ca4..d5c04fe04e81b89dbd425d3e1c7c55750e9314c6 100644 --- a/Socket/SocketHandle.cti +++ b/Socket/SocketHandle.cti @@ -56,6 +56,21 @@ prefix_ satcom::lib::SocketHandle<SocketPolicy>::SocketHandle(FileHandle other, : FileHandle(other) {} +template <class SocketPolicy> +prefix_ satcom::lib::SocketBody & satcom::lib::SocketHandle<SocketPolicy>::body() +{ + BOOST_ASSERT( dynamic_cast<SocketBody *>(&FileHandle::body()) ); + return static_cast<SocketBody &>(FileHandle::body()); +} + +template <class SocketPolicy> +prefix_ satcom::lib::SocketBody const & satcom::lib::SocketHandle<SocketPolicy>::body() + const +{ + BOOST_ASSERT( dynamic_cast<SocketBody const *>(&FileHandle::body()) ); + return static_cast<SocketBody const &>(FileHandle::body()); +} + template <class SocketPolicy> prefix_ void satcom::lib::SocketHandle<SocketPolicy>::assign(FileHandle other) { diff --git a/Socket/SocketHandle.hh b/Socket/SocketHandle.hh index 8e5b1d4fe902666008bedf721510ba27927156e7..7a4b7ec801de74ccc72533c995e9b95095d8059f 100644 --- a/Socket/SocketHandle.hh +++ b/Socket/SocketHandle.hh @@ -75,6 +75,10 @@ namespace lib { protected: explicit SocketHandle(std::auto_ptr<SocketProtocol> protocol); SocketHandle(FileHandle other, bool isChecked); + + SocketBody & body(); + SocketBody const & body() const; + void assign(FileHandle other); private: diff --git a/Socket/SocketHandle.ih b/Socket/SocketHandle.ih index 91798dec52ca6ef746851ef0add37d9648c4a800..afc5967475669c2ed618e5b13d722ec6cb9a457e 100644 --- a/Socket/SocketHandle.ih +++ b/Socket/SocketHandle.ih @@ -55,6 +55,8 @@ namespace lib { ///@} /////////////////////////////////////////////////////////////////////////// + SocketProtocol const & protocol() const; + protected: private: