23 static_cast<void *
>(
this),
m_name.c_str());
30 static_cast<void *
>(
this), __FUNCTION__,
m_name.c_str());
40 broadcaster_sp->RemoveListener(
this, pos->second.event_mask);
48 for (
size_t i = 0; i < num_managers; i++) {
51 manager_sp->RemoveListener(
this);
54 LLDB_LOGF(log,
"%p Listener::%s('%s')",
static_cast<void *
>(
this),
55 __FUNCTION__,
m_name.c_str());
59 uint32_t event_mask) {
70 uint32_t acquired_mask =
71 broadcaster->
AddListener(this->shared_from_this(), event_mask);
76 "%p Listener::StartListeningForEvents (broadcaster = %p, "
77 "mask = 0x%8.8x) acquired_mask = 0x%8.8x for %s",
78 static_cast<void *
>(
this),
static_cast<void *
>(broadcaster),
79 event_mask, acquired_mask,
m_name.c_str());
88 HandleBroadcastCallback callback,
89 void *callback_user_data) {
100 uint32_t acquired_mask =
101 broadcaster->
AddListener(this->shared_from_this(), event_mask);
104 if (log !=
nullptr) {
105 void **pointer =
reinterpret_cast<void **
>(&callback);
107 "%p Listener::StartListeningForEvents (broadcaster = %p, "
108 "mask = 0x%8.8x, callback = %p, user_data = %p) "
109 "acquired_mask = 0x%8.8x for %s",
110 static_cast<void *
>(
this),
static_cast<void *
>(broadcaster),
111 event_mask, *pointer,
static_cast<void *
>(callback_user_data),
112 acquired_mask,
m_name.c_str());
115 return acquired_mask;
121 uint32_t event_mask) {
129 return broadcaster->
RemoveListener(this->shared_from_this(), event_mask);
148 event_collection::iterator pos =
m_events.begin();
150 if ((*pos)->GetBroadcaster() == broadcaster)
159 const auto manager_matcher =
162 return (input_sp && input_sp == manager_sp);
170 LLDB_LOGF(log,
"%p Listener('%s')::AddEvent (event_sp = {%p})",
171 static_cast<void *
>(
this),
m_name.c_str(),
172 static_cast<void *
>(event_sp.get()));
180 std::unique_lock<std::mutex> &lock,
182 uint32_t event_type_mask,
EventSP &event_sp,
bool remove) {
192 const auto event_matcher =
193 [broadcaster, event_type_mask](
const EventSP &event_sp) ->
bool {
194 if (broadcaster && !event_sp->BroadcasterIs(broadcaster))
196 return event_type_mask == 0 || event_type_mask & event_sp->GetType();
198 Listener::event_collection::iterator pos =
m_events.end();
200 if (broadcaster ==
nullptr && event_type_mask == 0)
203 pos = llvm::find_if(
m_events, event_matcher);
210 "%p '%s' Listener::FindNextEventInternal(broadcaster=%p, "
211 "event_type_mask=0x%8.8x, "
212 "remove=%i) event %p",
213 static_cast<void *
>(
this),
GetName(),
214 static_cast<void *
>(broadcaster), event_type_mask, remove,
215 static_cast<void *
>(event_sp.get()));
223 event_sp->DoOnRemoval();
236 return event_sp.get();
244 return event_sp.get();
250 uint32_t event_type_mask) {
255 return event_sp.get();
262 uint32_t event_type_mask,
EventSP &event_sp) {
264 LLDB_LOG(log,
"this = {0}, timeout = {1} for {2}",
this, timeout,
m_name);
273 std::cv_status result = std::cv_status::no_timeout;
279 if (result == std::cv_status::timeout) {
281 LLDB_LOGF(log,
"%p Listener::GetEventInternal() timed out for %s",
282 static_cast<void *
>(
this),
m_name.c_str());
284 }
else if (result != std::cv_status::no_timeout) {
286 LLDB_LOGF(log,
"%p Listener::GetEventInternal() unknown error for %s",
287 static_cast<void *
>(
this),
m_name.c_str());
313 size_t num_handled = 0;
315 Broadcaster *broadcaster = event_sp->GetBroadcaster();
318 broadcaster_collection::iterator pos;
323 pos != end && pos->first.lock() == broadcaster_impl_sp; ++pos) {
341 const auto manager_matcher =
344 return (input_sp && input_sp == manager_sp);
348 std::lock_guard<std::mutex> manager_guard(manager_sp->m_manager_mutex);
351 uint32_t bits_acquired = manager_sp->RegisterListenerForEventsNoLock(
352 this->shared_from_this(), event_spec);
360 return bits_acquired;
370 std::lock_guard<std::mutex> manager_guard(manager_sp->m_manager_mutex);
372 return manager_sp->UnregisterListenerForEventsNoLock(this->shared_from_this(),
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
An event broadcasting class.
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Listen for any events specified by event_mask.
bool RemoveListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
Removes a Listener from this broadcasters list and frees the event bits specified by event_mask that ...
std::weak_ptr< BroadcasterImpl > BroadcasterImplWP
BroadcasterImplSP GetBroadcasterImpl()
std::shared_ptr< BroadcasterImpl > BroadcasterImplSP
size_t HandleBroadcastEvent(lldb::EventSP &event_sp)
static lldb::ListenerSP MakeListener(const char *name)
event_collection m_events
Event * PeekAtNextEventForBroadcaster(Broadcaster *broadcaster)
Event * PeekAtNextEvent()
uint32_t StartListeningForEvents(Broadcaster *broadcaster, uint32_t event_mask)
std::condition_variable m_events_condition
uint32_t StartListeningForEventSpec(const lldb::BroadcasterManagerSP &manager_sp, const BroadcastEventSpec &event_spec)
bool StopListeningForEventSpec(const lldb::BroadcasterManagerSP &manager_sp, const BroadcastEventSpec &event_spec)
std::mutex m_broadcasters_mutex
broadcaster_manager_collection m_broadcaster_managers
bool GetEventForBroadcaster(Broadcaster *broadcaster, lldb::EventSP &event_sp, const Timeout< std::micro > &timeout)
bool FindNextEventInternal(std::unique_lock< std::mutex > &lock, Broadcaster *broadcaster, uint32_t event_type_mask, lldb::EventSP &event_sp, bool remove)
Event * PeekAtNextEventForBroadcasterWithType(Broadcaster *broadcaster, uint32_t event_type_mask)
bool StopListeningForEvents(Broadcaster *broadcaster, uint32_t event_mask)
bool GetEventForBroadcasterWithType(Broadcaster *broadcaster, uint32_t event_type_mask, lldb::EventSP &event_sp, const Timeout< std::micro > &timeout)
Listener(const char *name)
void BroadcasterWillDestruct(Broadcaster *)
void BroadcasterManagerWillDestruct(lldb::BroadcasterManagerSP manager_sp)
broadcaster_collection m_broadcasters
bool GetEventInternal(const Timeout< std::micro > &timeout, Broadcaster *broadcaster, uint32_t event_type_mask, lldb::EventSP &event_sp)
std::mutex m_events_mutex
void AddEvent(lldb::EventSP &event)
bool GetEvent(lldb::EventSP &event_sp, const Timeout< std::micro > &timeout)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::BroadcasterManager > BroadcasterManagerSP
std::shared_ptr< lldb_private::Event > EventSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::weak_ptr< lldb_private::BroadcasterManager > BroadcasterManagerWP
void * callback_user_data
HandleBroadcastCallback callback