Debian Codegraph @

src/xmlrpcpp/XmlRpcDispatch.h

raw
1 // ----------------------------------------------------------------------------
2 //
3 // flxmlrpc Copyright (c) 2015 by W1HKJ, Dave Freese <[email protected]>
4 //
5 // XmlRpc++ Copyright (c) 2002-2008 by Chris Morley
6 //
7 // This file is part of fldigi
8 //
9 // flxmlrpc is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ----------------------------------------------------------------------------
17
18 #ifndef _XMLRPCDISPATCH_H_
19 #define _XMLRPCDISPATCH_H_
20
21 #if defined(_MSC_VER)
22 # pragma warning(disable:4786) // identifier was truncated in debug info
23 #endif
24
25 #include <vector>
26
27 namespace XmlRpc {
28
29 // An RPC source represents a file descriptor to monitor
30 class XmlRpcSource;
31
32 //! An object which monitors file descriptors for events and performs
33 //! callbacks when interesting events happen.
34 class XmlRpcDispatch {
35 public:
36 //! Constructor
37 XmlRpcDispatch();
38 ~XmlRpcDispatch();
39
40 //! Values indicating the type of events a source is interested in
41 enum EventType {
42 ReadableEvent = 1, //!< data available to read
43 WritableEvent = 2, //!< connected/data can be written without blocking
44 Exception = 4 //!< uh oh
45 };
46
47 //! Monitor this source for the event types specified by the event mask
48 //! and call its event handler when any of the events occur.
49 //! @param source The source to monitor
50 //! @param eventMask Which event types to watch for. \see EventType
51 void addSource(XmlRpcSource* source, unsigned eventMask);
52
53 //! Stop monitoring this source.
54 //! @param source The source to stop monitoring
55 //! The source socket is not closed.
56 void removeSource(XmlRpcSource* source);
57
58 //! Modify the types of events to watch for on this source
59 void setSourceEvents(XmlRpcSource* source, unsigned eventMask);
60
61
62 //! Watch current set of sources and process events for the specified
63 //! duration (in seconds, -1 implies wait forever, or until exit is called)
64 void work(double timeSeconds);
65
66 //! Exit from work routine
67 void exit();
68
69 //! Clear all sources from the monitored sources list. Sources are closed.
70 void clear();
71
72 protected:
73
74 //! Wait for I/O on any source, timeout, or interrupt signal.
75 bool waitForAndProcessEvents(double timeoutSeconds);
76
77
78 //! Returns current time in seconds since something
79 double getTime();
80
81 // A source to monitor and what to monitor it for
82 struct MonitoredSource
83 {
84 MonitoredSource(XmlRpcSource* src, unsigned mask) : _src(src), _mask(mask) {}
85 XmlRpcSource* getSource() const { return _src; }
86 unsigned& getMask() { return _mask; }
87 XmlRpcSource* _src;
88 unsigned _mask;
89 };
90
91 // A list of sources to monitor
92 typedef std::vector< MonitoredSource > SourceList;
93
94 // Sources being monitored
95 SourceList _sources;
96
97 // When work should stop (-1 implies wait forever, or until exit is called)
98 double _endTime;
99
100 bool _doClear;
101 bool _inWork;
102
103 };
104 } // namespace XmlRpc
105
106 #endif // _XMLRPCDISPATCH_H_