9#ifndef LLDB_UTILITY_BROADCASTER_H
10#define LLDB_UTILITY_BROADCASTER_H
16#include "llvm/ADT/SmallVector.h"
75 :
public std::enable_shared_from_this<BroadcasterManager> {
110 typedef std::map<BroadcastEventSpec, lldb::ListenerSP>
collection;
192 uint32_t requested_events);
214 uint32_t event_mask) {
233 bool prefix_with_broadcaster_name)
const {
235 prefix_with_broadcaster_name);
359 uint32_t event_mask);
368 bool prefix_with_broadcaster_name)
const;
377 return pos->second.c_str();
403 typedef llvm::SmallVector<std::pair<lldb::ListenerWP, uint32_t>, 4>
407 llvm::SmallVector<std::pair<lldb::ListenerSP, uint32_t &>, 4>
bool operator<(const BroadcastEventSpec &rhs) const
BroadcastEventSpec(llvm::StringRef broadcaster_class, uint32_t event_bits)
uint32_t GetEventBits() const
const std::string & GetBroadcasterClass() const
~BroadcastEventSpec()=default
bool IsContainedIn(const BroadcastEventSpec &in_spec) const
Tell whether this BroadcastEventSpec is contained in in_spec.
std::string m_broadcaster_class
listener_collection m_listeners
uint32_t RegisterListenerForEventsNoLock(const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec)
static lldb::BroadcasterManagerSP MakeBroadcasterManager()
Listeners hold onto weak pointers to their broadcaster managers.
std::mutex m_manager_mutex
bool UnregisterListenerForEventsNoLock(const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec)
void RemoveListener(const lldb::ListenerSP &listener_sp)
void SignUpListenersForBroadcaster(Broadcaster &broadcaster)
std::set< lldb::ListenerSP > listener_collection
std::pair< BroadcastEventSpec, lldb::ListenerSP > event_listener_key
~BroadcasterManager()=default
lldb::ListenerSP GetListenerForEventSpec(const BroadcastEventSpec &event_spec) const
std::map< BroadcastEventSpec, lldb::ListenerSP > collection
BroadcasterImpl contains the actual Broadcaster implementation.
bool IsHijackedForEvent(uint32_t event_mask)
const char * GetHijackingListenerName()
BroadcasterImpl(const BroadcasterImpl &)=delete
void BroadcastEvent(lldb::EventSP &event_sp)
void SetPrimaryListener(lldb::ListenerSP listener_sp)
void PrivateBroadcastEvent(lldb::EventSP &event_sp, bool unique)
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Broadcaster & m_broadcaster
The broadcaster that this implements.
void RestoreBroadcaster()
bool EventTypeHasListeners(uint32_t event_type)
llvm::SmallVector< std::pair< lldb::ListenerSP, uint32_t & >, 4 > GetListeners(uint32_t event_mask=UINT32_MAX, bool include_primary=true)
~BroadcasterImpl()=default
const char * GetEventName(uint32_t event_mask) const
std::vector< uint32_t > m_hijacking_masks
At some point we may want to have a stack or Listener collections, but for now this is just for priva...
uint32_t m_primary_listener_mask
bool RemoveListener(lldb_private::Listener *listener, uint32_t event_mask=UINT32_MAX)
bool HasListeners(uint32_t event_mask)
bool GetEventNames(Stream &s, const uint32_t event_mask, bool prefix_with_broadcaster_name) const
std::mutex m_listeners_mutex
A mutex that protects m_listeners.
std::vector< lldb::ListenerSP > m_hijacking_listeners
A simple mechanism to intercept events from a broadcaster.
collection m_listeners
A Broadcaster can have zero, one or many listeners.
Broadcaster * GetBroadcaster()
bool HijackBroadcaster(const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
llvm::SmallVector< std::pair< lldb::ListenerWP, uint32_t >, 4 > collection
lldb::ListenerSP m_primary_listener_sp
See the discussion of Broadcasters and Listeners above.
void SetEventName(uint32_t event_mask, const char *name)
event_names_map m_event_names
Optionally define event names for readability and logging for each event bit.
std::map< uint32_t, std::string > event_names_map
const std::string & GetBroadcasterName() const
const BroadcasterImpl & operator=(const BroadcasterImpl &)=delete
An event broadcasting class.
lldb::BroadcasterManagerSP GetManager()
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Listen for any events specified by event_mask.
bool EventTypeHasListeners(uint32_t event_type)
const std::string m_broadcaster_name
The name of this broadcaster object.
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 ...
lldb::ListenerSP GetPrimaryListener()
void RestoreBroadcaster()
Restore the state of the Broadcaster from a previous hijack attempt.
void SetEventName(uint32_t event_mask, const char *name)
Set the name for an event bit.
virtual void AddInitialEventsToListener(const lldb::ListenerSP &listener_sp, uint32_t requested_events)
std::weak_ptr< BroadcasterImpl > BroadcasterImplWP
void BroadcastEvent(uint32_t event_type, const lldb::EventDataSP &event_data_sp)
bool HijackBroadcaster(const lldb::ListenerSP &listener_sp, uint32_t event_mask=UINT32_MAX)
Provides a simple mechanism to temporarily redirect events from broadcaster.
const std::string & GetBroadcasterName()
Get this broadcaster's name.
BroadcasterImplSP GetBroadcasterImpl()
lldb::BroadcasterManagerSP m_manager_sp
virtual llvm::StringRef GetBroadcasterClass() const
This needs to be filled in if you are going to register the broadcaster with the broadcaster manager ...
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
void SetPrimaryListener(lldb::ListenerSP listener_sp)
const Broadcaster & operator=(const Broadcaster &)=delete
const char * GetHijackingListenerName()
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
std::shared_ptr< BroadcasterImpl > BroadcasterImplSP
BroadcasterImplSP m_broadcaster_sp
void BroadcastEvent(uint32_t event_type)
bool IsHijackedForEvent(uint32_t event_mask)
Broadcaster(const Broadcaster &)=delete
const char * GetEventName(uint32_t event_mask) const
bool GetEventNames(Stream &s, const uint32_t event_mask, bool prefix_with_broadcaster_name) const
Get the event name(s) for one or more event bits.
void CheckInWithManager()
void BroadcastEventIfUnique(uint32_t event_type)
virtual ~Broadcaster()
Destructor.
A stream class that can stream formatted output to a file.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::BroadcasterManager > BroadcasterManagerSP
std::shared_ptr< lldb_private::Event > EventSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::EventData > EventDataSP