Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

ProtocolServerSocketHandle.cti

Go to the documentation of this file.
00001 // $Id: ProtocolServerSocketHandle.cti 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00027 // Definition of inline template functions
00028 
00029 //#include "ProtocolServerSocketHandle.ih"
00030 
00031 // Custom includes
00032 #include <senf/Utils/senfassert.hh>
00033 #include "ProtocolClientSocketHandle.hh"
00034 
00035 #define prefix_ inline
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 template <class SocketProtocol>
00039 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
00040 ProtocolServerSocketHandle(senf::NoInit_t)
00041 {}
00042 
00043 template <class SocketProtocol>
00044 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::ProtocolServerSocketHandle()
00045     : ServerSocketHandle<typename SocketProtocol::Policy>(
00046         std::auto_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(true)))
00047 {}
00048 
00049 #define BOOST_PP_ITERATION_PARAMS_1 \
00050     (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2))
00051 #include BOOST_PP_ITERATE()
00052 
00053 template <class SocketProtocol>
00054 prefix_ SocketProtocol &
00055 senf::ProtocolServerSocketHandle<SocketProtocol>::protocol()
00056 {
00057     SENF_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()),
00058                  "Internal failure: Incompatible protocol class fount it's way into this handle");
00059     // Need dynamic_cast here, since senf::SocketProtocol is a
00060     // virtual base
00061     return dynamic_cast<SocketProtocol &>(this->body().protocol());
00062 }
00063 
00064 template <class SocketProtocol>
00065 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
00066 senf::ProtocolServerSocketHandle<SocketProtocol>::accept()
00067 {
00068     return ProtocolClientSocketHandle<SocketProtocol>(
00069         FileHandle(this->ServerSocketHandle<typename SocketProtocol::Policy>::accept()),true);
00070 }
00071 
00072 template <class SocketProtocol>
00073 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>
00074 senf::ProtocolServerSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
00075 {
00076     return ProtocolServerSocketHandle(handle,true);
00077 }
00078 
00079 template <class SocketProtocol>
00080 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>
00081 senf::ProtocolServerSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
00082 {
00083     ServerSocketHandle<typename SocketProtocol::Policy> h(
00084         ServerSocketHandle<typename SocketProtocol::Policy>::cast_dynamic(handle));
00085     // throw std::bad_cast if the protocol is invalid
00086     dynamic_cast<SocketProtocol const &>(static_cast<SocketBody&>(FileHandle::body(h)).protocol());
00087     return cast_static(handle);
00088 }
00089 
00090 template <class SocketProtocol>
00091 prefix_ void
00092 senf::ProtocolServerSocketHandle<SocketProtocol>::state(SocketStateMap & map,
00093                                                                unsigned lod)
00094 {
00095     map["handle"] = prettyName(typeid(*this));
00096     if (this->valid()) {
00097         map["valid"] << "true";
00098         this->body().state(map,lod);
00099     } else
00100         map["valid"] << "false";
00101 }
00102 
00103 template <class SocketProtocol>
00104 prefix_ std::string
00105 senf::ProtocolServerSocketHandle<SocketProtocol>::dumpState(unsigned lod)
00106 {
00107     SocketStateMap map;
00108     state(map,lod);
00109     return detail::dumpState(map);
00110 }
00111 
00112 template <class SocketProtocol>
00113 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
00114 ProtocolServerSocketHandle(FileHandle other, bool isChecked)
00115     : ServerSocketHandle<typename SocketProtocol::Policy>(other,isChecked)
00116 {}
00117 
00118 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00119 #undef prefix_
00120 
00121 
00122 // Local Variables:
00123 // mode: c++
00124 // fill-column: 100
00125 // c-file-style: "senf"
00126 // indent-tabs-mode: nil
00127 // ispell-local-dictionary: "american"
00128 // compile-command: "scons -u test"
00129 // comment-column: 40
00130 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research