5ad2b99243d81c48eb505e7492a2422bba8066cd
[senf.git] / Socket / SocketHandle.ih
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef IH_SocketHandle_
24 #define IH_SocketHandle_ 1
25
26 // Custom includes
27 #include <map>
28 #include <string>
29 #include <boost/scoped_ptr.hpp>
30 #include "FileHandle.hh"
31
32 ///////////////////////////////ih.p////////////////////////////////////////
33
34 namespace senf {
35
36
37     class SocketProtocol;
38
39     namespace detail {
40
41         class ConvertibleString : public std::string
42         {
43         public:
44             ConvertibleString();
45             ConvertibleString(bool v);
46             template <class T>
47             ConvertibleString(T const & other);
48             template <class T>
49             ConvertibleString & operator+= (ConvertibleString const & other);
50         };
51         
52         struct StateMapOrdering
53             : public std::binary_function<std::string,std::string,bool>
54         {
55             bool operator()(std::string a1, std::string a2) const;
56         };
57         
58     }
59
60     typedef std::map< std::string, detail::ConvertibleString, detail::StateMapOrdering > SocketStateMap;
61
62     namespace detail {
63         std::string dumpState(SocketStateMap const & map);
64     }
65
66     class SocketBody
67         : public FileBody
68     {
69     public:
70         ///////////////////////////////////////////////////////////////////////////
71         // Types
72         
73         typedef boost::intrusive_ptr<SocketBody> ptr;
74
75         ///////////////////////////////////////////////////////////////////////////
76         ///\name Structors and default members
77         ///@{
78
79         explicit SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer);
80         SocketBody(std::auto_ptr<SocketProtocol> protocol, bool isServer, int fd);
81
82         // no copy
83         // no conversion constructors
84
85         ///@}
86         ///////////////////////////////////////////////////////////////////////////
87
88         SocketProtocol const & protocol() const;
89         bool isServer();
90         
91         void state(SocketStateMap & map, unsigned lod);
92
93     private:
94         virtual void v_close();
95         virtual void v_terminate();
96         virtual bool v_eof() const;
97
98         boost::scoped_ptr<SocketProtocol> protocol_;
99         bool isServer_;
100     };
101
102 }
103
104 ///////////////////////////////ih.e////////////////////////////////////////
105 #endif
106
107 \f
108 // Local Variables:
109 // mode: c++
110 // c-file-style: "senf"
111 // End: