Renamed namespaces satcom::lib and satcom::pkf to senf
[senf.git] / Socket / ReadWritePolicy.hh
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 HH_ReadWritePolicy_
24 #define HH_ReadWritePolicy_ 1
25
26 // Custom includes
27 #include "SocketPolicy.hh"
28 #include "ClientSocketHandle.hh"
29 #include "CommunicationPolicy.hh" 
30
31 //#include "ReadWritePolicy.mpp"
32 ///////////////////////////////hh.p////////////////////////////////////////
33
34 // TODO: ReadWritePolicy.test.cc ...
35
36 struct sockaddr;
37
38 namespace senf {
39
40
41     struct ReadablePolicy : public ReadPolicyBase
42     {
43         static unsigned read(FileHandle handle, char * buffer, unsigned size);
44         template <class Policy>
45         static unsigned readfrom(ClientSocketHandle<Policy> handle, char * buffer, unsigned size,
46                                  typename Policy::AddressingPolicy::Address & address,
47                                  typename IfCommunicationPolicyIs<Policy,UnconnectedCommunicationPolicy>::type * = 0);
48
49     private:
50         static unsigned do_readfrom(FileHandle handle, char * buffer, unsigned size,
51                                     struct ::sockaddr * addr, socklen_t len);
52     };
53
54     struct NotReadablePolicy : public ReadPolicyBase
55     {};
56
57     struct WriteablePolicy : public WritePolicyBase
58     {
59         template <class Policy>
60         static unsigned write(ClientSocketHandle<Policy> handle, char const * buffer, unsigned size,
61                               typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
62         template <class Policy>
63         static unsigned writeto(ClientSocketHandle<Policy> handle, 
64                                 typename boost::call_traits<typename Policy::AddressingPolicy::Address>::param_type addr,
65                                 char const * buffer, unsigned size,
66                                 typename IfCommunicationPolicyIs<Policy,UnconnectedCommunicationPolicy>::type * = 0);
67
68     private:
69         static unsigned do_write(FileHandle handle, char const * buffer, unsigned size);
70         static unsigned do_writeto(FileHandle handle, char const * buffer, unsigned size,
71                                    struct sockaddr * addr, socklen_t len);
72     };
73     
74     struct NotWriteablePolicy : public WritePolicyBase
75     {};
76
77 }
78
79
80 ///////////////////////////////hh.e////////////////////////////////////////
81 //#include "ReadWritePolicy.cci"
82 //#include "ReadWritePolicy.ct"
83 #include "ReadWritePolicy.cti"
84 #endif
85
86 \f
87 // Local Variables:
88 // mode: c++
89 // c-file-style: "senf"
90 // End: