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