00001 // $Id: SocketProtocol.hh 1772 2011-03-10 12:45:21Z tho $ 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 // The private inheritance idea should indeed work very well: We just need to change the 00028 // implementations of body() and protocol() and that of the ProtocolClient/ServerSocketHandle 00029 // constructors and the SocketBody constructor. The body and the protocol would still be visible 00030 // like several instances because of the private inheritance but we would save the backwards 00031 // pointer. 00032 00080 #ifndef HH_SENF_Socket_SocketProtocol_ 00081 #define HH_SENF_Socket_SocketProtocol_ 1 00082 00083 // Custom includes 00084 #include <boost/utility.hpp> 00085 // Hrmpf ... I have tried very hard, but I just can't find a nice, generic way to clean 00086 // up this include 00087 #include "SocketHandle.ih" 00088 00089 //#include "SocketProtocol.mpp" 00090 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00091 00092 namespace senf { 00093 00095 //\{ 00096 00097 class SocketPolicyBase; 00098 00106 class SocketProtocol 00107 : boost::noncopyable 00108 { 00109 public: 00110 //-//////////////////////////////////////////////////////////////////////// 00111 // Types 00112 00113 //-//////////////////////////////////////////////////////////////////////// 00115 //\{ 00116 00117 SocketProtocol(); 00118 virtual ~SocketProtocol() = 0; 00119 00120 // default default constructor 00121 // no copy 00122 // no conversion constructors 00123 00124 //\} 00125 //-//////////////////////////////////////////////////////////////////////// 00126 00127 virtual SocketPolicyBase const & policy() const = 0; 00129 00130 //-//////////////////////////////////////////////////////////////////////// 00131 // Virtual interface 00132 00133 virtual unsigned available() const = 0; 00136 00152 virtual bool eof() const = 0; 00153 00159 virtual void close(); 00160 00165 virtual void terminate() const; 00166 00174 virtual void state(SocketStateMap & map, unsigned lod) const; 00176 00213 protected: 00214 FileHandle fh() const; 00215 00221 int fd() const; 00222 00226 void fd(int) const; 00227 00233 private: 00234 virtual std::auto_ptr<SocketBody> clone(bool isServer) const = 0; 00235 virtual std::auto_ptr<SocketBody> clone(int fd, bool isServer) const = 0; 00236 virtual SocketBody & body() const = 0; 00237 00238 friend class SocketBody; 00239 }; 00240 00241 template <class SPolicy> class ClientSocketHandle; 00242 template <class SPolicy> class ServerSocketHandle; 00243 00262 template <class SocketPolicy, class Self> 00263 class ConcreteSocketProtocol 00264 : public virtual SocketProtocol 00265 { 00266 public: 00267 //-//////////////////////////////////////////////////////////////////////// 00268 // Types 00269 00270 typedef SocketPolicy Policy; 00271 00272 //-//////////////////////////////////////////////////////////////////////// 00274 //\{ 00275 00276 ~ConcreteSocketProtocol() = 0; 00277 00278 // no default constructor 00279 // no copy 00280 // no conversion constructors 00281 00282 //\} 00283 //-//////////////////////////////////////////////////////////////////////// 00284 00285 Policy const & policy() const; 00286 00287 protected: 00288 ClientSocketHandle<Policy> clientHandle() const; 00290 00292 ServerSocketHandle<Policy> serverHandle() const; 00294 00297 private: 00298 virtual std::auto_ptr<SocketBody> clone(bool isServer) const; 00299 virtual std::auto_ptr<SocketBody> clone(int fd, bool isServer) const; 00300 virtual SocketBody & body() const; 00301 00302 Policy policy_; 00303 }; 00304 00305 //\} 00306 } 00307 00308 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00309 #include "SocketProtocol.cci" 00310 //#include "SocketProtocol.ct" 00311 #include "SocketProtocol.cti" 00312 #endif 00313 00314 00315 // Local Variables: 00316 // mode: c++ 00317 // fill-column: 100 00318 // c-file-style: "senf" 00319 // indent-tabs-mode: nil 00320 // ispell-local-dictionary: "american" 00321 // compile-command: "scons -u test" 00322 // comment-column: 40 00323 // End: