source: pacpusframework/branches/2.0-beta1/include/extlib/apache-log4cxx/log4cxx/helpers/datagramsocket.h@ 89

Last change on this file since 89 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
19#define _LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
20
21#include <log4cxx/helpers/objectimpl.h>
22#include <log4cxx/helpers/objectptr.h>
23#include <log4cxx/helpers/inetaddress.h>
24#include <log4cxx/helpers/pool.h>
25#include <log4cxx/helpers/datagrampacket.h>
26
27extern "C" { struct apr_socket_t; }
28
29namespace log4cxx
30{
31 namespace helpers
32 {
33 /** This class represents a socket for sending and receiving
34 datagram packets.*/
35 class LOG4CXX_EXPORT DatagramSocket : public helpers::ObjectImpl
36 {
37 public:
38 DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramSocket)
39 BEGIN_LOG4CXX_CAST_MAP()
40 LOG4CXX_CAST_ENTRY(DatagramSocket)
41 END_LOG4CXX_CAST_MAP()
42
43 /** Constructs a datagram socket and binds it to any available port
44 on the local host machine.*/
45 DatagramSocket();
46
47 /** Constructs a datagram socket and binds it to the specified
48 port on the local host machine. */
49 DatagramSocket(int port);
50
51 /** Creates a datagram socket, bound to the specified local
52 address. */
53 DatagramSocket(int port, InetAddressPtr laddr);
54
55 /** ensure the socket is closed. */
56 ~DatagramSocket();
57
58 /** Binds a datagram socket to a local port and address.*/
59 void bind(int lport, InetAddressPtr laddress);
60
61 /** Creates a datagram socket.*/
62 void create();
63
64 /** Closes this datagram socket */
65 void close();
66
67 /** Connects the socket to a remote address for this socket. */
68 void connect(InetAddressPtr address, int port);
69
70 /** Returns the address to which this socket is connected. */
71 inline InetAddressPtr getInetAddress() const
72 { return address; }
73
74 /** Gets the local address to which the socket is bound. */
75 inline InetAddressPtr getLocalAddress() const
76 { return localAddress; }
77
78 /** Returns the port number on the local host to which this
79 socket is bound. */
80 inline int getLocalPort() const
81 { return localPort; }
82
83 /** Returns the port for this socket */
84 inline int getPort() const
85 { return port; }
86
87 /** Returns the binding state of the socket. **/
88 inline bool isBound() const
89 { return localPort != 0; }
90
91 /** Returns wether the socket is closed or not. */
92 inline bool isClosed() const
93 { return socket != 0; }
94
95 /** Returns the connection state of the socket. */
96 inline bool isConnected() const
97 { return port != 0; }
98
99 /** Receives a datagram packet from this socket. */
100 void receive(DatagramPacketPtr& p);
101
102 /** Sends a datagram packet from this socket. */
103 void send(DatagramPacketPtr& p);
104
105 private:
106 DatagramSocket(const DatagramSocket&);
107 DatagramSocket& operator=(const DatagramSocket&);
108 /** The APR socket */
109 apr_socket_t *socket;
110
111 /** The memory pool for the socket */
112 Pool socketPool;
113
114 InetAddressPtr address;
115
116 InetAddressPtr localAddress;
117
118 int port;
119
120 /** The local port number to which this socket is connected. */
121 int localPort;
122
123 };
124 LOG4CXX_PTR_DEF(DatagramSocket);
125 } // namespace helpers
126} // namespace log4cxx
127
128#endif //_LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
Note: See TracBrowser for help on using the repository browser.