LLDB  mainline
SBBroadcaster.cpp
Go to the documentation of this file.
1 //===-- SBBroadcaster.cpp ---------------------------------------*- C++ -*-===//
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(NULL) {
21 }
22 
24  : m_opaque_sp(new Broadcaster(NULL, name)), m_opaque_ptr(NULL) {
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 : NULL), m_opaque_ptr(broadcaster) {
32 }
33 
35  : m_opaque_sp(rhs.m_opaque_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
37 }
38 
41  SBBroadcaster, operator=,(const lldb::SBBroadcaster &),
42  rhs);
43 
44  if (this != &rhs) {
45  m_opaque_sp = rhs.m_opaque_sp;
46  m_opaque_ptr = rhs.m_opaque_ptr;
47  }
48  return LLDB_RECORD_RESULT(*this);
49 }
50 
52 
53 void SBBroadcaster::BroadcastEventByType(uint32_t event_type, bool unique) {
55  (uint32_t, bool), event_type, unique);
56 
57  if (m_opaque_ptr == NULL)
58  return;
59 
60  if (unique)
61  m_opaque_ptr->BroadcastEventIfUnique(event_type);
62  else
63  m_opaque_ptr->BroadcastEvent(event_type);
64 }
65 
66 void SBBroadcaster::BroadcastEvent(const SBEvent &event, bool unique) {
68  (const lldb::SBEvent &, bool), event, unique);
69 
70  if (m_opaque_ptr == NULL)
71  return;
72 
73  EventSP event_sp = event.GetSP();
74  if (unique)
75  m_opaque_ptr->BroadcastEventIfUnique(event_sp);
76  else
77  m_opaque_ptr->BroadcastEvent(event_sp);
78 }
79 
81  uint32_t requested_events) {
83  (const lldb::SBListener &, uint32_t), listener,
84  requested_events);
85 
86  if (m_opaque_ptr)
87  m_opaque_ptr->AddInitialEventsToListener(listener.m_opaque_sp,
88  requested_events);
89 }
90 
92  uint32_t event_mask) {
94  (const lldb::SBListener &, uint32_t), listener,
95  event_mask);
96 
97  if (m_opaque_ptr)
98  return m_opaque_ptr->AddListener(listener.m_opaque_sp, event_mask);
99  return 0;
100 }
101 
102 const char *SBBroadcaster::GetName() const {
104 
105  if (m_opaque_ptr)
106  return m_opaque_ptr->GetBroadcasterName().GetCString();
107  return NULL;
108 }
109 
112  event_type);
113 
114  if (m_opaque_ptr)
115  return m_opaque_ptr->EventTypeHasListeners(event_type);
116  return false;
117 }
118 
120  uint32_t event_mask) {
122  (const lldb::SBListener &, uint32_t), listener,
123  event_mask);
124 
125  if (m_opaque_ptr)
126  return m_opaque_ptr->RemoveListener(listener.m_opaque_sp, event_mask);
127  return false;
128 }
129 
130 Broadcaster *SBBroadcaster::get() const { return m_opaque_ptr; }
131 
132 void SBBroadcaster::reset(Broadcaster *broadcaster, bool owns) {
133  if (owns)
134  m_opaque_sp.reset(broadcaster);
135  else
136  m_opaque_sp.reset();
137  m_opaque_ptr = broadcaster;
138 }
139 
142  return this->operator bool();
143 }
144 SBBroadcaster::operator bool() const {
145  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBroadcaster, operator bool);
146 
147  return m_opaque_ptr != NULL;
148 }
149 
152 
153  m_opaque_sp.reset();
154  m_opaque_ptr = NULL;
155 }
156 
157 bool SBBroadcaster::operator==(const SBBroadcaster &rhs) const {
159  bool, SBBroadcaster, operator==,(const lldb::SBBroadcaster &), rhs);
160 
161  return m_opaque_ptr == rhs.m_opaque_ptr;
162 }
163 
164 bool SBBroadcaster::operator!=(const SBBroadcaster &rhs) const {
166  bool, SBBroadcaster, operator!=,(const lldb::SBBroadcaster &), rhs);
167 
168  return m_opaque_ptr != rhs.m_opaque_ptr;
169 }
170 
171 bool SBBroadcaster::operator<(const SBBroadcaster &rhs) const {
173  bool, SBBroadcaster, operator<,(const lldb::SBBroadcaster &), rhs);
174 
175  return m_opaque_ptr < rhs.m_opaque_ptr;
176 }
177 
178 namespace lldb_private {
179 namespace repro {
180 
181 template <>
184  LLDB_REGISTER_CONSTRUCTOR(SBBroadcaster, (const char *));
187  const lldb::SBBroadcaster &,
188  SBBroadcaster, operator=,(const lldb::SBBroadcaster &));
190  (uint32_t, bool));
192  (const lldb::SBEvent &, bool));
194  (const lldb::SBListener &, uint32_t));
196  (const lldb::SBListener &, uint32_t));
199  (uint32_t));
201  (const lldb::SBListener &, uint32_t));
203  LLDB_REGISTER_METHOD_CONST(bool, SBBroadcaster, operator bool, ());
206  bool, SBBroadcaster, operator==,(const lldb::SBBroadcaster &));
208  bool, SBBroadcaster, operator!=,(const lldb::SBBroadcaster &));
210  bool, SBBroadcaster, operator<,(const lldb::SBBroadcaster &));
211 }
212 
213 }
214 }
const SBBroadcaster & operator=(const SBBroadcaster &rhs)
bool operator==(const lldb::SBBroadcaster &rhs) const
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
lldb_private::Broadcaster * get() const
An event broadcasting class.
Definition: Broadcaster.h:250
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:283
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:329
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
void BroadcastEventIfUnique(lldb::EventSP &event_sp)
Definition: Broadcaster.h:287
#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:338
bool EventTypeHasListeners(uint32_t event_type)
Definition: Broadcaster.h:369
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:389
bool EventTypeHasListeners(uint32_t event_type)
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
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)