]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Host/MainLoopBase.h
Upgrade Unbound to 1.7.3. More to follow.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Host / MainLoopBase.h
1 //===-- MainLoopBase.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_Host_posix_MainLoopBase_h_
11 #define lldb_Host_posix_MainLoopBase_h_
12
13 #include "lldb/Utility/IOObject.h"
14 #include "lldb/Utility/Status.h"
15 #include "llvm/Support/ErrorHandling.h"
16 #include <functional>
17
18 namespace lldb_private {
19
20 // The purpose of this class is to enable multiplexed processing of data from
21 // different sources
22 // without resorting to multi-threading. Clients can register IOObjects, which
23 // will be monitored
24 // for readability, and when they become ready, the specified callback will be
25 // invoked.
26 // Monitoring for writability is not supported, but can be easily added if
27 // needed.
28 //
29 // The RegisterReadObject function return a handle, which controls the duration
30 // of the monitoring. When
31 // this handle is destroyed, the callback is deregistered.
32 //
33 // This class simply defines the interface common for all platforms, actual
34 // implementations are
35 // platform-specific.
36 class MainLoopBase {
37 private:
38   class ReadHandle;
39
40 public:
41   MainLoopBase() {}
42   virtual ~MainLoopBase() {}
43
44   typedef std::unique_ptr<ReadHandle> ReadHandleUP;
45
46   typedef std::function<void(MainLoopBase &)> Callback;
47
48   virtual ReadHandleUP RegisterReadObject(const lldb::IOObjectSP &object_sp,
49                                           const Callback &callback,
50                                           Status &error) {
51     llvm_unreachable("Not implemented");
52   }
53
54   // Waits for registered events and invoke the proper callbacks. Returns when
55   // all callbacks
56   // deregister themselves or when someone requests termination.
57   virtual Status Run() { llvm_unreachable("Not implemented"); }
58
59   // Requests the exit of the Run() function.
60   virtual void RequestTermination() { llvm_unreachable("Not implemented"); }
61
62 protected:
63   ReadHandleUP CreateReadHandle(const lldb::IOObjectSP &object_sp) {
64     return ReadHandleUP(new ReadHandle(*this, object_sp->GetWaitableHandle()));
65   }
66
67   virtual void UnregisterReadObject(IOObject::WaitableHandle handle) {
68     llvm_unreachable("Not implemented");
69   }
70
71 private:
72   class ReadHandle {
73   public:
74     ~ReadHandle() { m_mainloop.UnregisterReadObject(m_handle); }
75
76   private:
77     ReadHandle(MainLoopBase &mainloop, IOObject::WaitableHandle handle)
78         : m_mainloop(mainloop), m_handle(handle) {}
79
80     MainLoopBase &m_mainloop;
81     IOObject::WaitableHandle m_handle;
82
83     friend class MainLoopBase;
84     DISALLOW_COPY_AND_ASSIGN(ReadHandle);
85   };
86
87 private:
88   DISALLOW_COPY_AND_ASSIGN(MainLoopBase);
89 };
90
91 } // namespace lldb_private
92
93 #endif // lldb_Host_posix_MainLoopBase_h_