37bbe4486c034c0aed9ab78cb1d308143194891d
[senf.git] / Socket / ServerSocketHandle.cti
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 // Definition of inline template functions
24
25 //#include "ServerSocketHandle.ih"
26
27 // Custom includes
28 #include <typeinfo>
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 template <class SocketPolicy>
34 template <class OtherPolicy>
35 prefix_ senf::ServerSocketHandle<SocketPolicy>::
36 ServerSocketHandle(ServerSocketHandle<OtherPolicy> other,
37                    typename SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type *)
38     : SocketHandle<SocketPolicy>(other,true)
39 {}
40
41 template <class SocketPolicy>
42 prefix_  senf::ServerSocketHandle<SocketPolicy>::
43 ServerSocketHandle(std::auto_ptr<SocketProtocol> protocol)
44     : SocketHandle<SocketPolicy>(protocol,true)
45 {}
46
47 template <class SocketPolicy>
48 template <class OtherPolicy>
49 prefix_ typename senf::SocketHandle<SocketPolicy>::template IsCompatible<OtherPolicy>::type const &
50 senf::ServerSocketHandle<SocketPolicy>::operator=(ServerSocketHandle<OtherPolicy> other)
51 {
52     assign(other);
53     return *this;
54 }
55
56 ///////////////////////////////////////////////////////////////////////////
57 // Server socket interface
58
59 template <class Policy>
60 prefix_ void senf::ServerSocketHandle<Policy>::bind(AddressParam addr)
61 {
62     Policy::AddressingPolicy::bind(*this,addr);
63 }
64
65 template <class Policy>
66 prefix_ void senf::ServerSocketHandle<Policy>::listen(unsigned backlog)
67 {
68     Policy::CommunicationPolicy::listen(*this,backlog);
69 }
70
71 template <class Policy>
72 prefix_ typename senf::ServerSocketHandle<Policy>::Address
73 senf::ServerSocketHandle<Policy>::local()
74 {
75     typename Policy::AddressingPolicy::Address addr;
76     this->local(addr);
77     return addr;
78 }
79
80 template <class Policy>
81 prefix_ void senf::ServerSocketHandle<Policy>::local(Address & addr)
82 {
83     Policy::AddressingPolicy::local(*this,addr);
84 }
85
86 template <class Policy>
87 prefix_ typename senf::ServerSocketHandle<Policy>::ClientSocketHandle
88 senf::ServerSocketHandle<Policy>::accept()
89 {
90     Address address;
91     return acceptfrom(address);
92 }
93
94 template <class Policy>
95 prefix_ std::pair<typename senf::ServerSocketHandle<Policy>::ClientSocketHandle,
96                   typename senf::ServerSocketHandle<Policy>::Address>
97 senf::ServerSocketHandle<Policy>::acceptfrom()
98 {
99
100     Address address;
101     ClientSocketHandle handle = accept(address);
102     return std::make_pair(handle,address);
103 }
104
105 template <class Policy>
106 prefix_ typename senf::ServerSocketHandle<Policy>::ClientSocketHandle
107 senf::ServerSocketHandle<Policy>::acceptfrom(Address & addr)
108 {
109     return ClientSocketHandle(this->protocol().clone(), 
110                               Policy::CommunicationPolicy::accept(*this,addr));
111 }
112
113 ///////////////////////////////////////////////////////////////////////////
114
115 template <class Policy>
116 prefix_ senf::ServerSocketHandle<Policy>::ServerSocketHandle(FileHandle other,
117                                                                     bool isChecked)
118     : SocketHandle<Policy>(other, isChecked)
119 {}
120
121 template <class Policy>
122 prefix_ senf::ServerSocketHandle<Policy>
123 senf::ServerSocketHandle<Policy>::cast_static(FileHandle handle)
124 {
125     return ServerSocketHandle(handle,true);
126 }
127
128 template <class Policy>
129 prefix_ senf::ServerSocketHandle<Policy>
130 senf::ServerSocketHandle<Policy>::cast_dynamic(FileHandle handle)
131 {
132     SocketHandle<Policy> h (SocketHandle<Policy>::cast_dynamic(handle));
133     if (! static_cast<SocketBody&>(FileHandle::body(handle)).isServer())
134         throw std::bad_cast();
135     return cast_static(handle);
136 }
137
138 template <class Policy>
139 prefix_ void senf::ServerSocketHandle<Policy>::state(SocketStateMap & map, unsigned lod)
140 {
141     map["handle"] = prettyName(typeid(*this));
142     this->body().state(map,lod);
143 }
144
145 template <class Policy>
146 prefix_ std::string senf::ServerSocketHandle<Policy>::dumpState(unsigned lod)
147 {
148     SocketStateMap map;
149     state(map,lod);
150     return detail::dumpState(map);
151 }
152
153 ///////////////////////////////cti.e///////////////////////////////////////
154 #undef prefix_
155
156 \f
157 // Local Variables:
158 // mode: c++
159 // c-file-style: "senf"
160 // End: