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_
15 #include "llvm/Support/ErrorHandling.h"
17 #include "lldb/Core/Error.h"
18 #include "lldb/Host/IOObject.h"
20 namespace lldb_private {
22 // The purpose of this class is to enable multiplexed processing of data from different sources
23 // without resorting to multi-threading. Clients can register IOObjects, which will be monitored
24 // for readability, and when they become ready, the specified callback will be invoked.
25 // Monitoring for writability is not supported, but can be easily added if needed.
27 // The RegisterReadObject function return a handle, which controls the duration of the monitoring. When
28 // this handle is destroyed, the callback is deregistered.
30 // This class simply defines the interface common for all platforms, actual implementations are
39 virtual ~MainLoopBase() { }
41 typedef std::unique_ptr<ReadHandle> ReadHandleUP;
43 typedef std::function<void(MainLoopBase &)> Callback;
46 RegisterReadObject(const lldb::IOObjectSP &object_sp, const Callback &callback, Error &error)
47 { llvm_unreachable("Not implemented"); }
49 // Waits for registered events and invoke the proper callbacks. Returns when all callbacks
50 // deregister themselves or when someone requests termination.
53 { llvm_unreachable("Not implemented"); }
55 // Requests the exit of the Run() function.
58 { llvm_unreachable("Not implemented"); }
62 CreateReadHandle(const lldb::IOObjectSP &object_sp)
63 { return ReadHandleUP(new ReadHandle(*this, object_sp->GetWaitableHandle())); }
66 UnregisterReadObject(IOObject::WaitableHandle handle)
67 { llvm_unreachable("Not implemented"); }
73 ~ReadHandle() { m_mainloop.UnregisterReadObject(m_handle); }
76 ReadHandle(MainLoopBase &mainloop, IOObject::WaitableHandle handle)
77 : 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
94 #endif // lldb_Host_posix_MainLoopBase_h_