[89] | 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_PACKET
|
---|
| 19 | #define _LOG4CXX_HELPERS_DATAGRAM_PACKET
|
---|
| 20 |
|
---|
| 21 | #include <log4cxx/helpers/objectimpl.h>
|
---|
| 22 | #include <log4cxx/helpers/objectptr.h>
|
---|
| 23 | #include <log4cxx/helpers/inetaddress.h>
|
---|
| 24 |
|
---|
| 25 | namespace log4cxx
|
---|
| 26 | {
|
---|
| 27 | namespace helpers
|
---|
| 28 | {
|
---|
| 29 |
|
---|
| 30 | /** This class represents a datagram packet.
|
---|
| 31 | <p>Datagram packets are used to implement a connectionless packet
|
---|
| 32 | delivery service. Each message is routed from one machine to another
|
---|
| 33 | based solely on information contained within that packet. Multiple
|
---|
| 34 | packets sent from one machine to another might be routed differently,
|
---|
| 35 | and might arrive in any order.
|
---|
| 36 | */
|
---|
| 37 | class LOG4CXX_EXPORT DatagramPacket : public helpers::ObjectImpl
|
---|
| 38 | {
|
---|
| 39 | protected:
|
---|
| 40 | /** the data for this packet. */
|
---|
| 41 | void * buf;
|
---|
| 42 |
|
---|
| 43 | /** The offset of the data for this packet. */
|
---|
| 44 | int offset;
|
---|
| 45 |
|
---|
| 46 | /** The length of the data for this packet. */
|
---|
| 47 | int length;
|
---|
| 48 |
|
---|
| 49 | /** The IP address for this packet. */
|
---|
| 50 | InetAddressPtr address;
|
---|
| 51 |
|
---|
| 52 | /** The UDP port number of the remote host. */
|
---|
| 53 | int port;
|
---|
| 54 |
|
---|
| 55 | public:
|
---|
| 56 | DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramPacket)
|
---|
| 57 | BEGIN_LOG4CXX_CAST_MAP()
|
---|
| 58 | LOG4CXX_CAST_ENTRY(DatagramPacket)
|
---|
| 59 | END_LOG4CXX_CAST_MAP()
|
---|
| 60 |
|
---|
| 61 | /** Constructs a DatagramPacket for receiving packets of length
|
---|
| 62 | <code>length</code>. */
|
---|
| 63 | DatagramPacket(void * buf, int length);
|
---|
| 64 |
|
---|
| 65 | /** Constructs a datagram packet for sending packets of length
|
---|
| 66 | <code>length</code> to the specified port number on the specified
|
---|
| 67 | host. */
|
---|
| 68 | DatagramPacket(void * buf, int length, InetAddressPtr address, int port);
|
---|
| 69 |
|
---|
| 70 | /** Constructs a DatagramPacket for receiving packets of length
|
---|
| 71 | <code>length</code>, specifying an offset into the buffer. */
|
---|
| 72 | DatagramPacket(void * buf, int offset, int length);
|
---|
| 73 |
|
---|
| 74 | /** Constructs a datagram packet for sending packets of length
|
---|
| 75 | <code>length</code> with offset <code>offset</code> to the
|
---|
| 76 | specified port number on the specified host. */
|
---|
| 77 | DatagramPacket(void * buf, int offset, int length, InetAddressPtr address,
|
---|
| 78 | int port);
|
---|
| 79 |
|
---|
| 80 | ~DatagramPacket();
|
---|
| 81 |
|
---|
| 82 | /** Returns the IP address of the machine to which this datagram
|
---|
| 83 | is being sent or from which the datagram was received. */
|
---|
| 84 | inline InetAddressPtr getAddress() const
|
---|
| 85 | { return address; }
|
---|
| 86 |
|
---|
| 87 | /** Returns the data received or the data to be sent. */
|
---|
| 88 | inline void * getData() const
|
---|
| 89 | { return buf; }
|
---|
| 90 |
|
---|
| 91 | /** Returns the length of the data to be sent or the length of the
|
---|
| 92 | data received. */
|
---|
| 93 | inline int getLength() const
|
---|
| 94 | { return length; }
|
---|
| 95 |
|
---|
| 96 | /** Returns the offset of the data to be sent or the offset of the
|
---|
| 97 | data received. */
|
---|
| 98 | inline int getOffset() const
|
---|
| 99 | { return offset; }
|
---|
| 100 |
|
---|
| 101 | /** Returns the port number on the remote host to which this
|
---|
| 102 | datagram is being sent or from which the datagram was received. */
|
---|
| 103 | inline int getPort() const
|
---|
| 104 | { return port; }
|
---|
| 105 |
|
---|
| 106 | inline void setAddress(InetAddressPtr address1)
|
---|
| 107 | { this->address = address1; }
|
---|
| 108 |
|
---|
| 109 | /** Set the data buffer for this packet. */
|
---|
| 110 | inline void setData(void * buf1)
|
---|
| 111 | { this->buf = buf1; }
|
---|
| 112 |
|
---|
| 113 | /** Set the data buffer for this packet. */
|
---|
| 114 | inline void setData(void * buf1, int offset1, int length1)
|
---|
| 115 | { this->buf = buf1; this->offset = offset1; this->length = length1; }
|
---|
| 116 |
|
---|
| 117 | /** Set the length for this packet. */
|
---|
| 118 | inline void setLength(int length1)
|
---|
| 119 | { this->length = length1; }
|
---|
| 120 |
|
---|
| 121 | inline void setPort(int port1)
|
---|
| 122 | { this->port = port1; }
|
---|
| 123 |
|
---|
| 124 | private:
|
---|
| 125 | //
|
---|
| 126 | // prevent copy and assignment statements
|
---|
| 127 | DatagramPacket(const DatagramPacket&);
|
---|
| 128 | DatagramPacket& operator=(const DatagramPacket&);
|
---|
| 129 |
|
---|
| 130 | }; // class DatagramPacket
|
---|
| 131 | LOG4CXX_PTR_DEF(DatagramPacket);
|
---|
| 132 | } // namespace helpers
|
---|
| 133 | } // namespace log4cxx
|
---|
| 134 |
|
---|
| 135 | #endif // _LOG4CXX_HELPERS_DATAGRAM_PACKET
|
---|