source: XMLIO_V2/external/include/Poco/Net/ICMPEventArgs.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1//
2// ICMPEventArgs.h
3//
4// $Id: //poco/1.3/Net/include/Poco/Net/ICMPEventArgs.h#2 $
5//
6// Library: Net
7// Package: ICMP
8// Module:  ICMPEventArgs
9//
10// Definition of ICMPEventArgs.
11//
12// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Net_ICMPEventArgs_INCLUDED
40#define Net_ICMPEventArgs_INCLUDED
41
42
43#include "Poco/Net/Net.h"
44#include "Poco/Net/SocketAddress.h"
45#include <vector>
46#include <algorithm>
47
48
49namespace Poco {
50namespace Net {
51
52
53class Net_API ICMPEventArgs
54        /// The purpose of the ICMPEventArgs class is to be used as template parameter
55        /// to instantiate event members in ICMPClient class.
56        /// When clients register for an event notification, the reference to the class is
57        ///     passed to the handler function to provide information about the event.
58{
59public:
60        ICMPEventArgs(const SocketAddress& address, int repetitions, int dataSize, int ttl);
61                /// Creates ICMPEventArgs.
62
63        virtual ~ICMPEventArgs();
64                /// Destroys ICMPEventArgs.
65
66        std::string hostName() const;
67                /// Tries to resolve the target IP address into host name.
68                /// If unsuccessful, all exceptions are silently ignored and
69                ///     the IP address is returned.
70
71        std::string hostAddress() const;
72                /// Returns the target IP address.
73
74        int repetitions() const;
75                /// Returns the number of repetitions for the ping operation.
76
77        int dataSize() const;
78                /// Returns the packet data size in bytes.
79
80        int ttl() const;
81                /// Returns time to live.
82
83        int sent() const;
84                /// Returns the number of packets sent.
85
86        int received() const;
87                /// Returns the number of packets received.
88
89        int replyTime(int index = -1) const;
90                /// Returns the reply time for the request specified with index.
91                /// If index == -1 (default), returns the most recent reply time.
92
93        const std::string& error(int index = -1) const;
94                /// Returns the error string for the request specified with index.
95                /// If index == -1 (default), returns the most recent error string.
96
97        int minRTT() const;
98                /// Returns the minimum round trip time for a sequence of requests.
99
100        int maxRTT() const;
101                /// Returns the maximum round trip time for a sequence of requests.
102
103        int avgRTT() const;
104                /// Returns the average round trip time for a sequence of requests.
105
106        float percent() const;
107                /// Returns the success percentage for a sequence of requests.
108
109private:
110        ICMPEventArgs();
111
112        void setRepetitions(int repetitions);
113        void setDataSize(int dataSize);
114        void setTTL(int ttl);
115        void setReplyTime(int index, int time);
116        void setError(int index, const std::string& text);
117        ICMPEventArgs& operator ++ ();
118        ICMPEventArgs operator ++ (int);
119
120        SocketAddress _address;
121        int _sent;
122        int _dataSize;
123        int _ttl;
124        std::vector<int> _rtt;
125        std::vector<std::string> _errors;
126
127        friend class ICMPClient;
128};
129
130
131//
132// inlines
133//
134inline int ICMPEventArgs::repetitions() const
135{
136        return (int) _rtt.size();
137}
138
139
140inline void ICMPEventArgs::setDataSize(int dataSize)
141{
142        _dataSize = dataSize;
143}
144
145
146inline int ICMPEventArgs::dataSize() const
147{
148        return _dataSize;
149}
150
151
152inline void ICMPEventArgs::setTTL(int ttl)
153{
154        _ttl = ttl;
155}
156
157
158inline int ICMPEventArgs::ttl() const
159{
160        return _ttl;
161}
162
163
164inline int ICMPEventArgs::sent() const
165{
166        return _sent;
167}
168
169
170inline int ICMPEventArgs::minRTT() const
171{
172        return *std::min_element(_rtt.begin(), _rtt.end());
173}
174
175
176inline int ICMPEventArgs::maxRTT() const
177{
178        return *std::max_element(_rtt.begin(), _rtt.end());
179}
180
181
182} } // namespace Poco::Net
183
184
185#endif
Note: See TracBrowser for help on using the repository browser.