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 
9 #include "SBReproducerPrivate.h"
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 
19 SBBroadcaster::SBBroadcaster() : m_opaque_sp(), m_opaque_ptr(nullptr) {
21 }
22 
24  : m_opaque_sp(new Broadcaster(nullptr, name)), m_opaque_ptr(nullptr) {
25  LLDB_RECORD_CONSTRUCTOR(SBBroadcaster, (const char *), name);
26 
27  m_opaque_ptr = m_opaque_sp.get();
28 }
29 
31  : m_opaque_sp(owns ? broadcaster : nullptr), m_opaque_ptr(broadcaster) {}
32 
36 }
37 
40  SBBroadcaster, operator=,(const lldb::SBBroadcaster &),
41  rhs);
42 
43  if (this != &rhs) {
46  }
47  return LLDB_RECORD_RESULT(*this);
48 }
49 
50 SBBroadcaster::~SBBroadcaster() { reset(nullptr, false); }
51 
52 void SBBroadcaster::BroadcastEventByType(uint32_t event_type, bool unique) {
54  (uint32_t, bool), event_type, unique);
55 
56  if (m_opaque_ptr == nullptr)
57  return;
58 
59  if (unique)
61  else
62  m_opaque_ptr->BroadcastEvent(event_type);
63 }
64 
65 void SBBroadcaster::BroadcastEvent(const SBEvent &event, bool unique) {
67  (const lldb::SBEvent &, bool), event, unique);
68 
69  if (m_opaque_ptr == nullptr)
70  return;
71 
72  EventSP event_sp = event.GetSP();
73  if (unique)
75  else
76  m_opaque_ptr->BroadcastEvent(event_sp);
77 }
78 
80  uint32_t requested_events) {
82  (const lldb::SBListener &, uint32_t), listener,
83  requested_events);
84 
85  if (m_opaque_ptr)
87  requested_events);
88 }
89 
91  uint32_t event_mask) {
93  (const lldb::SBListener &, uint32_t), listener,
94  event_mask);
95 
96  if (m_opaque_ptr)
97  return m_opaque_ptr->AddListener(listener.m_opaque_sp, event_mask);
98  return 0;
99 }
100 
101 const char *SBBroadcaster::GetName() const {
103 
104  if (m_opaque_ptr)
106  return nullptr;
107 }
108 
111  event_type);
112 
113  if (m_opaque_ptr)
114  return m_opaque_ptr->EventTypeHasListeners(event_type);
115  return false;
116 }
117 
119  uint32_t event_mask) {
121  (const lldb::SBListener &, uint32_t), listener,
122  event_mask);
123 
124  if (m_opaque_ptr)
125  return m_opaque_ptr->RemoveListener(listener.m_opaque_sp, event_mask);
126  return false;
127 }
128 
130 
131 void SBBroadcaster::reset(Broadcaster *broadcaster, bool owns) {
132  if (owns)
133  m_opaque_sp.reset(broadcaster);
134  else
135  m_opaque_sp.reset();
136  m_opaque_ptr = broadcaster;
137 }
138 
141  return this->operator bool();
142 }
143 SBBroadcaster::operator bool() const {
144  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBroadcaster, operator bool);
145 
146  return m_opaque_ptr != nullptr;
147 }
148 
151 
152  m_opaque_sp.reset();
153  m_opaque_ptr = nullptr;
154 }
155 
156 bool SBBroadcaster::operator==(const SBBroadcaster &rhs) const {
158  bool, SBBroadcaster, operator==,(const lldb::SBBroadcaster &), rhs);
159 
160  return m_opaque_ptr == rhs.m_opaque_ptr;
161 }
162 
163 bool SBBroadcaster::operator!=(const SBBroadcaster &rhs) const {
165  bool, SBBroadcaster, operator!=,(const lldb::SBBroadcaster &), rhs);
166 
167  return m_opaque_ptr != rhs.m_opaque_ptr;
168 }
169 
170 bool SBBroadcaster::operator<(const SBBroadcaster &rhs) const {
172  bool, SBBroadcaster, operator<,(const lldb::SBBroadcaster &), rhs);
173 
174  return m_opaque_ptr < rhs.m_opaque_ptr;
175 }
176 
177 namespace lldb_private {
178 namespace repro {
179 
180 template <>
183  LLDB_REGISTER_CONSTRUCTOR(SBBroadcaster, (const char *));
186  const lldb::SBBroadcaster &,
187  SBBroadcaster, operator=,(const lldb::SBBroadcaster &));
189  (uint32_t, bool));
191  (const lldb::SBEvent &, bool));
193  (const lldb::SBListener &, uint32_t));
195  (const lldb::SBListener &, uint32_t));
198  (uint32_t));
200  (const lldb::SBListener &, uint32_t));
202  LLDB_REGISTER_METHOD_CONST(bool, SBBroadcaster, operator bool, ());
205  bool, SBBroadcaster, operator==,(const lldb::SBBroadcaster &));
207  bool, SBBroadcaster, operator!=,(const lldb::SBBroadcaster &));
209  bool, SBBroadcaster, operator<,(const lldb::SBBroadcaster &));
210 }
211 
212 }
213 }
const SBBroadcaster & operator=(const SBBroadcaster &rhs)
bool operator==(const lldb::SBBroadcaster &rhs) const
The registry contains a unique mapping between functions and their ID.
A class that represents a running process on the host machine.
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
lldb::BroadcasterSP m_opaque_sp
Definition: SBBroadcaster.h:78
lldb_private::Broadcaster * get() const
lldb::ListenerSP m_opaque_sp
Definition: SBListener.h:102
lldb_private::Broadcaster * m_opaque_ptr
Definition: SBBroadcaster.h:79
An event broadcasting class.
Definition: Broadcaster.h:242
void BroadcastEvent(const lldb::SBEvent &event, bool unique=false)
void AddInitialEventsToListener(const lldb::SBListener &listener, uint32_t requested_events)
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
Definition: Broadcaster.h:262
uint32_t AddListener(const lldb::SBListener &listener, uint32_t event_mask)
uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask)
Listen for any events specified by event_mask.
Definition: Broadcaster.h:308
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
Definition: Broadcaster.h:266
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
bool operator!=(const lldb::SBBroadcaster &rhs) const
void reset(lldb_private::Broadcaster *broadcaster, bool owns)
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
const char * GetName() const
ConstString GetBroadcasterName()
Get the NULL terminated C string name of this Broadcaster object.
Definition: Broadcaster.h:317
bool EventTypeHasListeners(uint32_t event_type)
Definition: Broadcaster.h:345
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
bool EventTypeHasListeners(uint32_t event_type)
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:246
bool operator<(const lldb::SBBroadcaster &rhs) const
bool RemoveListener(const lldb::SBListener &listener, uint32_t event_mask=UINT32_MAX)
Definition: SBAddress.h:15
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
virtual void AddInitialEventsToListener(const lldb::ListenerSP &listener_sp, uint32_t requested_events)
#define LLDB_RECORD_RESULT(Result)
void RegisterMethods< SBBroadcaster >(Registry &R)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
void BroadcastEventByType(uint32_t event_type, bool unique=false)