~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to src/xmlrpcpp/XmlRpcDispatch.h

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-06-07 11:28:52 UTC
  • Revision ID: package-import@ubuntu.com-20140607112852-v4d5tb1m3h3vi0dl
Tags: upstream-1.3.15
ImportĀ upstreamĀ versionĀ 1.3.15

Show diffs side-by-side

added added

removed removed

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