1 //===-- MainLoopBase.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_Host_posix_MainLoopBase_h_
11 #define lldb_Host_posix_MainLoopBase_h_
13 #include "lldb/Utility/IOObject.h"
14 #include "lldb/Utility/Status.h"
15 #include "llvm/Support/ErrorHandling.h"
18 namespace lldb_private {
20 // The purpose of this class is to enable multiplexed processing of data from
22 // without resorting to multi-threading. Clients can register IOObjects, which
24 // for readability, and when they become ready, the specified callback will be
26 // Monitoring for writability is not supported, but can be easily added if
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.
33 // This class simply defines the interface common for all platforms, actual
34 // implementations are
42 virtual ~MainLoopBase() {}
44 typedef std::unique_ptr<ReadHandle> ReadHandleUP;
46 typedef std::function<void(MainLoopBase &)> Callback;
48 virtual ReadHandleUP RegisterReadObject(const lldb::IOObjectSP &object_sp,
49 const Callback &callback,
51 llvm_unreachable("Not implemented");
54 // Waits for registered events and invoke the proper callbacks. Returns when
56 // deregister themselves or when someone requests termination.
57 virtual Status Run() { llvm_unreachable("Not implemented"); }
59 // Requests the exit of the Run() function.
60 virtual void RequestTermination() { llvm_unreachable("Not implemented"); }
63 ReadHandleUP CreateReadHandle(const lldb::IOObjectSP &object_sp) {
64 return ReadHandleUP(new ReadHandle(*this, object_sp->GetWaitableHandle()));
67 virtual void UnregisterReadObject(IOObject::WaitableHandle handle) {
68 llvm_unreachable("Not implemented");
74 ~ReadHandle() { m_mainloop.UnregisterReadObject(m_handle); }
77 ReadHandle(MainLoopBase &mainloop, IOObject::WaitableHandle handle)
78 : m_mainloop(mainloop), m_handle(handle) {}
80 MainLoopBase &m_mainloop;
81 IOObject::WaitableHandle m_handle;
83 friend class MainLoopBase;
84 DISALLOW_COPY_AND_ASSIGN(ReadHandle);
88 DISALLOW_COPY_AND_ASSIGN(MainLoopBase);
91 } // namespace lldb_private
93 #endif // lldb_Host_posix_MainLoopBase_h_