LLDB  mainline
SBBroadcaster.cpp
Go to the documentation of this file.
1 //===-- SBBroadcaster.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
11 
12 #include "lldb/API/SBBroadcaster.h"
13 #include "lldb/API/SBEvent.h"
14 #include "lldb/API/SBListener.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
20 
22  : m_opaque_sp(new Broadcaster(nullptr, name)) {
23  LLDB_INSTRUMENT_VA(this, name);
24 
25  m_opaque_ptr = m_opaque_sp.get();
26 }
27 
29  : m_opaque_sp(owns ? broadcaster : nullptr), m_opaque_ptr(broadcaster) {}
30 
32  : m_opaque_sp(rhs.m_opaque_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
33  LLDB_INSTRUMENT_VA(this, rhs);
34 }
35 
37  LLDB_INSTRUMENT_VA(this, rhs);
38 
39  if (this != &rhs) {
42  }
43  return *this;
44 }
45 
46 SBBroadcaster::~SBBroadcaster() { reset(nullptr, false); }
47 
48 void SBBroadcaster::BroadcastEventByType(uint32_t event_type, bool unique) {
49  LLDB_INSTRUMENT_VA(this, event_type, unique);
50 
51  if (m_opaque_ptr == nullptr)
52  return;
53 
54  if (unique)
56  else
57  m_opaque_ptr->BroadcastEvent(event_type);
58 }
59 
60 void SBBroadcaster::BroadcastEvent(const SBEvent &event, bool unique) {
61  LLDB_INSTRUMENT_VA(this, event, unique);
62 
63  if (m_opaque_ptr == nullptr)
64  return;
65 
66  EventSP event_sp = event.GetSP();
67  if (unique)
69  else
70  m_opaque_ptr->BroadcastEvent(event_sp);
71 }
72 
74  uint32_t requested_events) {
75  LLDB_INSTRUMENT_VA(this, listener, requested_events);
76 
77  if (m_opaque_ptr)
79  requested_events);
80 }
81 
83  uint32_t event_mask) {
84  LLDB_INSTRUMENT_VA(this, listener, event_mask);
85 
86  if (m_opaque_ptr)
87  return m_opaque_ptr->AddListener(listener.m_opaque_sp, event_mask);
88  return 0;
89 }
90 
91 const char *SBBroadcaster::GetName() const {
92  LLDB_INSTRUMENT_VA(this);
93 
94  if (m_opaque_ptr)
96  return nullptr;
97 }
98 
100  LLDB_INSTRUMENT_VA(this, event_type);
101 
102  if (m_opaque_ptr)
103  return m_opaque_ptr->EventTypeHasListeners(event_type);
104  return false;
105 }
106 
108  uint32_t event_mask) {
109  LLDB_INSTRUMENT_VA(this, listener, event_mask);
110 
111  if (m_opaque_ptr)
112  return m_opaque_ptr->RemoveListener(listener.m_opaque_sp, event_mask);
113  return false;
114 }
115 
117 
118 void SBBroadcaster::reset(Broadcaster *broadcaster, bool owns) {
119  if (owns)
120  m_opaque_sp.reset(broadcaster);
121  else
122  m_opaque_sp.reset();
123  m_opaque_ptr = broadcaster;
124 }
125 
127  LLDB_INSTRUMENT_VA(this);
128  return this->operator bool();
129 }
130 SBBroadcaster::operator bool() const {
131  LLDB_INSTRUMENT_VA(this);
132 
133  return m_opaque_ptr != nullptr;
134 }
135 
137  LLDB_INSTRUMENT_VA(this);
138 
139  m_opaque_sp.reset();
140  m_opaque_ptr = nullptr;
141 }
142 
143 bool SBBroadcaster::operator==(const SBBroadcaster &rhs) const {
144  LLDB_INSTRUMENT_VA(this, rhs);
145 
146  return m_opaque_ptr == rhs.m_opaque_ptr;
147 }
148 
149 bool SBBroadcaster::operator!=(const SBBroadcaster &rhs) const {
150  LLDB_INSTRUMENT_VA(this, rhs);
151 
152  return m_opaque_ptr != rhs.m_opaque_ptr;
153 }
154 
155 bool SBBroadcaster::operator<(const SBBroadcaster &rhs) const {
156  LLDB_INSTRUMENT_VA(this, rhs);
157 
158  return m_opaque_ptr < rhs.m_opaque_ptr;
159 }
Instrumentation.h
lldb::SBBroadcaster::operator=
const SBBroadcaster & operator=(const SBBroadcaster &rhs)
Definition: SBBroadcaster.cpp:36
lldb::SBBroadcaster::BroadcastEventByType
void BroadcastEventByType(uint32_t event_type, bool unique=false)
Definition: SBBroadcaster.cpp:48
lldb_private::Broadcaster::AddInitialEventsToListener
virtual void AddInitialEventsToListener(const lldb::ListenerSP &listener_sp, uint32_t requested_events)
Definition: Broadcaster.cpp:110
lldb::SBBroadcaster::m_opaque_ptr
lldb_private::Broadcaster * m_opaque_ptr
Definition: SBBroadcaster.h:80
lldb::SBBroadcaster::AddListener
uint32_t AddListener(const lldb::SBListener &listener, uint32_t event_mask)
Definition: SBBroadcaster.cpp:82
lldb::SBEvent
Definition: SBEvent.h:21
lldb::SBBroadcaster::Clear
void Clear()
Definition: SBBroadcaster.cpp:136
lldb::SBBroadcaster::EventTypeHasListeners
bool EventTypeHasListeners(uint32_t event_type)
Definition: SBBroadcaster.cpp:99
SBListener.h
lldb::SBBroadcaster::AddInitialEventsToListener
void AddInitialEventsToListener(const lldb::SBListener &listener, uint32_t requested_events)
Definition: SBBroadcaster.cpp:73
Broadcaster.h
lldb::SBListener::m_opaque_sp
lldb::ListenerSP m_opaque_sp
Definition: SBListener.h:102
lldb::SBBroadcaster::RemoveListener
bool RemoveListener(const lldb::SBListener &listener, uint32_t event_mask=UINT32_MAX)
Definition: SBBroadcaster.cpp:107
lldb::SBBroadcaster::reset
void reset(lldb_private::Broadcaster *broadcaster, bool owns)
Definition: SBBroadcaster.cpp:118
lldb_private::Broadcaster::BroadcastEventIfUnique
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
Definition: Broadcaster.h:266
SBBroadcaster.h
lldb::SBBroadcaster::m_opaque_sp
lldb::BroadcasterSP m_opaque_sp
Definition: SBBroadcaster.h:79
lldb_private::Broadcaster::AddListener
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Listen for any events specified by event_mask.
Definition: Broadcaster.h:308
lldb_private::Broadcaster::EventTypeHasListeners
bool EventTypeHasListeners(uint32_t event_type)
Definition: Broadcaster.h:345
lldb_private::Broadcaster::RemoveListener
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 ...
Definition: Broadcaster.h:365
lldb_private::Broadcaster::BroadcastEvent
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
Definition: Broadcaster.h:262
lldb::SBBroadcaster::GetName
const char * GetName() const
Definition: SBBroadcaster.cpp:91
lldb::SBListener
Definition: SBListener.h:16
uint32_t
lldb::SBBroadcaster::get
lldb_private::Broadcaster * get() const
Definition: SBBroadcaster.cpp:116
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
SBEvent.h
lldb::SBBroadcaster::SBBroadcaster
SBBroadcaster()
Definition: SBBroadcaster.cpp:19
lldb_private::Broadcaster::GetBroadcasterName
ConstString GetBroadcasterName()
Get the NULL terminated C string name of this Broadcaster object.
Definition: Broadcaster.h:317
lldb::SBBroadcaster::operator==
bool operator==(const lldb::SBBroadcaster &rhs) const
Definition: SBBroadcaster.cpp:143
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBBroadcaster
Definition: SBBroadcaster.h:16
lldb::SBBroadcaster::operator!=
bool operator!=(const lldb::SBBroadcaster &rhs) const
Definition: SBBroadcaster.cpp:149
lldb::SBBroadcaster::IsValid
bool IsValid() const
Definition: SBBroadcaster.cpp:126
lldb::SBBroadcaster::BroadcastEvent
void BroadcastEvent(const lldb::SBEvent &event, bool unique=false)
Definition: SBBroadcaster.cpp:60
lldb::SBBroadcaster::~SBBroadcaster
~SBBroadcaster()
Definition: SBBroadcaster.cpp:46
lldb_private::Broadcaster
Definition: Broadcaster.h:242
lldb::SBBroadcaster::operator<
bool operator<(const lldb::SBBroadcaster &rhs) const
Definition: SBBroadcaster.cpp:155
lldb
Definition: SBAddress.h:15