git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[senf.git] / Socket / ClientSocketHandle.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 "ClientSocketHandle.ih"
26
27 // Custom includes
28 #include <typeinfo>
29
30 #define prefix_ inline
31 ///////////////////////////////cti.p///////////////////////////////////////
32
33 template <class Policy>
34 template <class OtherPolicy>
35 prefix_ satcom::lib::ClientSocketHandle<Policy>::
36 ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
37                    typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type *)
38     : SocketHandle<Policy>(other,true)
39 {}
40
41 template <class Policy>
42 prefix_ satcom::lib::ClientSocketHandle<Policy>::ClientSocketHandle(FileHandle other,
43                                                                     bool isChecked)
44     : SocketHandle<Policy>(other, isChecked)
45 {}
46
47 template <class Policy>
48 prefix_  satcom::lib::ClientSocketHandle<Policy>::
49 ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol, int fd)
50     : SocketHandle<Policy>(protocol,false)
51 {
52     this->body().fd(fd);
53 }
54
55 template <class Policy>
56 template <class OtherPolicy>
57 prefix_ typename satcom::lib::SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
58 satcom::lib::ClientSocketHandle<Policy>::operator=(ClientSocketHandle<OtherPolicy> other)
59 {
60     assign(other);
61     return *this;
62 }
63
64 ///////////////////////////////////////////////////////////////////////////
65
66 ///////////////////////////////////////////////////////////////////////////
67 // reading and writing
68
69 template <class Policy>
70 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::read(char * buffer,
71                                                                      unsigned size)
72 {
73     return Policy::ReadPolicy::read(*this, buffer, size);
74 }
75
76 template <class Policy>
77 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::
78 readfrom(char * buffer, unsigned size, typename Policy::AddressingPolicy::Address & from)
79 {
80     return Policy::ReadPolicy::readfrom(*this, buffer, size, from);
81 }
82
83 template <class Policy>
84 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::write(char const * buffer,
85                                                                 unsigned size)
86 {
87     return Policy::WritePolicy::write(*this, buffer, size);
88 }
89
90 template <class Policy>
91 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::
92 writeto(typename boost::call_traits<typename Policy::AddressingPolicy::Address>::param_type addr,
93         std::string const & data)
94 {
95     return this->writeto(addr, data.data(), data.size());
96 }
97
98 template <class Policy>
99 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::
100 writeto(typename boost::call_traits<typename Policy::AddressingPolicy::Address>::param_type addr,
101         char const * buffer, unsigned size)
102 {
103     return Policy::WritePolicy::writeto(*this, addr, buffer, size);
104 }
105
106 ///////////////////////////////////////////////////////////////////////////
107 // addressing
108
109 template <class Policy>
110 prefix_ typename Policy::AddressingPolicy::Address
111 satcom::lib::ClientSocketHandle<Policy>::peer()
112 {
113     typename Policy::AddressingPolicy::Address addr;
114     this->peer(addr);
115     return addr;
116 }
117
118 template <class Policy>
119 prefix_ void satcom::lib::ClientSocketHandle<Policy>::
120 peer(typename Policy::AddressingPolicy::Address & addr)
121 {
122     Policy::AddressingPolicy::peer(*this,addr);
123 }
124
125 template <class Policy>
126 prefix_ typename Policy::AddressingPolicy::Address
127 satcom::lib::ClientSocketHandle<Policy>::local()
128 {
129     typename Policy::AddressingPolicy::Address addr;
130     this->local(addr);
131     return addr;
132 }
133
134 template <class Policy>
135 prefix_ void satcom::lib::ClientSocketHandle<Policy>::
136 local(typename Policy::AddressingPolicy::Address & addr)
137 {
138     Policy::AddressingPolicy::local(*this,addr);
139 }
140
141 template <class Policy>
142 prefix_ void satcom::lib::ClientSocketHandle<Policy>::connect(AddressParam addr)
143 {
144     Policy::AddressingPolicy::connect(*this,addr);
145 }
146
147 template <class Policy>
148 prefix_ void satcom::lib::ClientSocketHandle<Policy>::
149 bind(typename boost::call_traits<typename Policy::AddressingPolicy::Address>::param_type addr)
150 {
151     Policy::AddressingPolicy::bind(*this,addr);
152 }
153
154 ///////////////////////////////////////////////////////////////////////////
155 // Buffering
156
157 template <class Policy>
158 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::rcvbuf()
159 {
160     return Policy::BufferingPolicy::rcvbuf(*this);
161 }
162
163 template <class Policy>
164 prefix_ void satcom::lib::ClientSocketHandle<Policy>::rcvbuf(unsigned size)
165 {
166     Policy::BufferingPolicy::rcvbuf(*this,size);
167 }
168
169 template <class Policy>
170 prefix_ unsigned satcom::lib::ClientSocketHandle<Policy>::sndbuf()
171 {
172     return Policy::BufferingPolicy::sndbuf(*this);
173 }
174
175 template <class Policy>
176 prefix_ void satcom::lib::ClientSocketHandle<Policy>::sndbuf(unsigned size)
177 {
178     Policy::BufferingPolicy::sndbuf(*this,size);
179 }
180
181 ///////////////////////////////////////////////////////////////////////////
182
183 template <class Policy>
184 prefix_ satcom::lib::ClientSocketHandle<Policy>
185 satcom::lib::ClientSocketHandle<Policy>::cast_static(FileHandle handle)
186 {
187     return ClientSocketHandle(handle, true);
188 }
189
190 template <class Policy>
191 prefix_ satcom::lib::ClientSocketHandle<Policy>
192 satcom::lib::ClientSocketHandle<Policy>::cast_dynamic(FileHandle handle)
193 {
194     SocketHandle<Policy> h (SocketHandle<Policy>::cast_dynamic(handle));
195     if (static_cast<SocketBody&>(FileHandle::body(h)).isServer())
196         throw std::bad_cast();
197     return cast_static(handle);
198 }
199
200 template <class Policy>
201 prefix_ void satcom::lib::ClientSocketHandle<Policy>::state(SocketStateMap & map, unsigned lod)
202 {
203     map["handle"] = prettyName(typeid(*this));
204     this->body().state(map,lod);
205 }
206
207 template <class Policy>
208 prefix_ std::string satcom::lib::ClientSocketHandle<Policy>::dumpState(unsigned lod)
209 {
210     SocketStateMap map;
211     state(map,lod);
212     return detail::dumpState(map);
213 }
214
215 ///////////////////////////////cti.e///////////////////////////////////////
216 #undef prefix_
217
218 \f
219 // Local Variables:
220 // mode: c++
221 // c-file-style: "satcom"
222 // End: