• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef _XMLRPCDISPATCH_H_
3 #define _XMLRPCDISPATCH_H_
4 //
5 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
6 //
7 #if defined(_MSC_VER)
8 # pragma warning(disable:4786)    // identifier was truncated in debug info
9 #endif
10 
11 #ifndef MAKEDEPEND
12 # include <list>
13 #endif
14 
15 namespace XmlRpc {
16 
17   // An RPC source represents a file descriptor to monitor
18   class XmlRpcSource;
19 
20   //! An object which monitors file descriptors for events and performs
21   //! callbacks when interesting events happen.
22   class XmlRpcDispatch {
23   public:
24     //! Constructor
25     XmlRpcDispatch();
26     ~XmlRpcDispatch();
27 
28     //! Values indicating the type of events a source is interested in
29     enum EventType {
30       ReadableEvent = 1,    //!< data available to read
31       WritableEvent = 2,    //!< connected/data can be written without blocking
32       Exception     = 4     //!< uh oh
33     };
34 
35     //! Monitor this source for the event types specified by the event mask
36     //! and call its event handler when any of the events occur.
37     //!  @param source The source to monitor
38     //!  @param eventMask Which event types to watch for. \see EventType
39     void addSource(XmlRpcSource* source, unsigned eventMask);
40 
41     //! Stop monitoring this source.
42     //!  @param source The source to stop monitoring
43     void removeSource(XmlRpcSource* source);
44 
45     //! Modify the types of events to watch for on this source
46     void setSourceEvents(XmlRpcSource* source, unsigned eventMask);
47 
48 
49     //! Watch current set of sources and process events for the specified
50     //! duration (in ms, -1 implies wait forever, or until exit is called)
51     void work(double msTime);
52 
53     //! Exit from work routine
54     void exit();
55 
56     //! Clear all sources from the monitored sources list. Sources are closed.
57     void clear();
58 
59   protected:
60 
61     // helper
62     double getTime();
63 
64     // A source to monitor and what to monitor it for
65     struct MonitoredSource {
MonitoredSourceMonitoredSource66       MonitoredSource(XmlRpcSource* src, unsigned mask) : _src(src), _mask(mask) {}
getSourceMonitoredSource67       XmlRpcSource* getSource() const { return _src; }
getMaskMonitoredSource68       unsigned& getMask() { return _mask; }
69       XmlRpcSource* _src;
70       unsigned _mask;
71     };
72 
73     // A list of sources to monitor
74     typedef std::list< MonitoredSource > SourceList;
75 
76     // Sources being monitored
77     SourceList _sources;
78 
79     // When work should stop (-1 implies wait forever, or until exit is called)
80     double _endTime;
81 
82     bool _doClear;
83     bool _inWork;
84 
85   };
86 } // namespace XmlRpc
87 
88 #endif  // _XMLRPCDISPATCH_H_
89