1 //===-- SBBroadcaster.cpp ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SBReproducerPrivate.h"
10 #include "lldb/Utility/Broadcaster.h"
12 #include "lldb/API/SBBroadcaster.h"
13 #include "lldb/API/SBEvent.h"
14 #include "lldb/API/SBListener.h"
17 using namespace lldb_private
;
19 SBBroadcaster::SBBroadcaster() : m_opaque_sp(), m_opaque_ptr(nullptr) {
20 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBBroadcaster
);
23 SBBroadcaster::SBBroadcaster(const char *name
)
24 : m_opaque_sp(new Broadcaster(nullptr, name
)), m_opaque_ptr(nullptr) {
25 LLDB_RECORD_CONSTRUCTOR(SBBroadcaster
, (const char *), name
);
27 m_opaque_ptr
= m_opaque_sp
.get();
30 SBBroadcaster::SBBroadcaster(lldb_private::Broadcaster
*broadcaster
, bool owns
)
31 : m_opaque_sp(owns
? broadcaster
: nullptr), m_opaque_ptr(broadcaster
) {}
33 SBBroadcaster::SBBroadcaster(const SBBroadcaster
&rhs
)
34 : m_opaque_sp(rhs
.m_opaque_sp
), m_opaque_ptr(rhs
.m_opaque_ptr
) {
35 LLDB_RECORD_CONSTRUCTOR(SBBroadcaster
, (const lldb::SBBroadcaster
&), rhs
);
38 const SBBroadcaster
&SBBroadcaster::operator=(const SBBroadcaster
&rhs
) {
39 LLDB_RECORD_METHOD(const lldb::SBBroadcaster
&,
40 SBBroadcaster
, operator=,(const lldb::SBBroadcaster
&),
44 m_opaque_sp
= rhs
.m_opaque_sp
;
45 m_opaque_ptr
= rhs
.m_opaque_ptr
;
47 return LLDB_RECORD_RESULT(*this);
50 SBBroadcaster::~SBBroadcaster() { reset(nullptr, false); }
52 void SBBroadcaster::BroadcastEventByType(uint32_t event_type
, bool unique
) {
53 LLDB_RECORD_METHOD(void, SBBroadcaster
, BroadcastEventByType
,
54 (uint32_t, bool), event_type
, unique
);
56 if (m_opaque_ptr
== nullptr)
60 m_opaque_ptr
->BroadcastEventIfUnique(event_type
);
62 m_opaque_ptr
->BroadcastEvent(event_type
);
65 void SBBroadcaster::BroadcastEvent(const SBEvent
&event
, bool unique
) {
66 LLDB_RECORD_METHOD(void, SBBroadcaster
, BroadcastEvent
,
67 (const lldb::SBEvent
&, bool), event
, unique
);
69 if (m_opaque_ptr
== nullptr)
72 EventSP event_sp
= event
.GetSP();
74 m_opaque_ptr
->BroadcastEventIfUnique(event_sp
);
76 m_opaque_ptr
->BroadcastEvent(event_sp
);
79 void SBBroadcaster::AddInitialEventsToListener(const SBListener
&listener
,
80 uint32_t requested_events
) {
81 LLDB_RECORD_METHOD(void, SBBroadcaster
, AddInitialEventsToListener
,
82 (const lldb::SBListener
&, uint32_t), listener
,
86 m_opaque_ptr
->AddInitialEventsToListener(listener
.m_opaque_sp
,
90 uint32_t SBBroadcaster::AddListener(const SBListener
&listener
,
91 uint32_t event_mask
) {
92 LLDB_RECORD_METHOD(uint32_t, SBBroadcaster
, AddListener
,
93 (const lldb::SBListener
&, uint32_t), listener
,
97 return m_opaque_ptr
->AddListener(listener
.m_opaque_sp
, event_mask
);
101 const char *SBBroadcaster::GetName() const {
102 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBBroadcaster
, GetName
);
105 return m_opaque_ptr
->GetBroadcasterName().GetCString();
109 bool SBBroadcaster::EventTypeHasListeners(uint32_t event_type
) {
110 LLDB_RECORD_METHOD(bool, SBBroadcaster
, EventTypeHasListeners
, (uint32_t),
114 return m_opaque_ptr
->EventTypeHasListeners(event_type
);
118 bool SBBroadcaster::RemoveListener(const SBListener
&listener
,
119 uint32_t event_mask
) {
120 LLDB_RECORD_METHOD(bool, SBBroadcaster
, RemoveListener
,
121 (const lldb::SBListener
&, uint32_t), listener
,
125 return m_opaque_ptr
->RemoveListener(listener
.m_opaque_sp
, event_mask
);
129 Broadcaster
*SBBroadcaster::get() const { return m_opaque_ptr
; }
131 void SBBroadcaster::reset(Broadcaster
*broadcaster
, bool owns
) {
133 m_opaque_sp
.reset(broadcaster
);
136 m_opaque_ptr
= broadcaster
;
139 bool SBBroadcaster::IsValid() const {
140 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBroadcaster
, IsValid
);
141 return this->operator bool();
143 SBBroadcaster::operator bool() const {
144 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBBroadcaster
, operator bool);
146 return m_opaque_ptr
!= nullptr;
149 void SBBroadcaster::Clear() {
150 LLDB_RECORD_METHOD_NO_ARGS(void, SBBroadcaster
, Clear
);
153 m_opaque_ptr
= nullptr;
156 bool SBBroadcaster::operator==(const SBBroadcaster
&rhs
) const {
157 LLDB_RECORD_METHOD_CONST(
158 bool, SBBroadcaster
, operator==,(const lldb::SBBroadcaster
&), rhs
);
160 return m_opaque_ptr
== rhs
.m_opaque_ptr
;
163 bool SBBroadcaster::operator!=(const SBBroadcaster
&rhs
) const {
164 LLDB_RECORD_METHOD_CONST(
165 bool, SBBroadcaster
, operator!=,(const lldb::SBBroadcaster
&), rhs
);
167 return m_opaque_ptr
!= rhs
.m_opaque_ptr
;
170 bool SBBroadcaster::operator<(const SBBroadcaster
&rhs
) const {
171 LLDB_RECORD_METHOD_CONST(
172 bool, SBBroadcaster
, operator<,(const lldb::SBBroadcaster
&), rhs
);
174 return m_opaque_ptr
< rhs
.m_opaque_ptr
;
177 namespace lldb_private
{
181 void RegisterMethods
<SBBroadcaster
>(Registry
&R
) {
182 LLDB_REGISTER_CONSTRUCTOR(SBBroadcaster
, ());
183 LLDB_REGISTER_CONSTRUCTOR(SBBroadcaster
, (const char *));
184 LLDB_REGISTER_CONSTRUCTOR(SBBroadcaster
, (const lldb::SBBroadcaster
&));
185 LLDB_REGISTER_METHOD(
186 const lldb::SBBroadcaster
&,
187 SBBroadcaster
, operator=,(const lldb::SBBroadcaster
&));
188 LLDB_REGISTER_METHOD(void, SBBroadcaster
, BroadcastEventByType
,
190 LLDB_REGISTER_METHOD(void, SBBroadcaster
, BroadcastEvent
,
191 (const lldb::SBEvent
&, bool));
192 LLDB_REGISTER_METHOD(void, SBBroadcaster
, AddInitialEventsToListener
,
193 (const lldb::SBListener
&, uint32_t));
194 LLDB_REGISTER_METHOD(uint32_t, SBBroadcaster
, AddListener
,
195 (const lldb::SBListener
&, uint32_t));
196 LLDB_REGISTER_METHOD_CONST(const char *, SBBroadcaster
, GetName
, ());
197 LLDB_REGISTER_METHOD(bool, SBBroadcaster
, EventTypeHasListeners
,
199 LLDB_REGISTER_METHOD(bool, SBBroadcaster
, RemoveListener
,
200 (const lldb::SBListener
&, uint32_t));
201 LLDB_REGISTER_METHOD_CONST(bool, SBBroadcaster
, IsValid
, ());
202 LLDB_REGISTER_METHOD_CONST(bool, SBBroadcaster
, operator bool, ());
203 LLDB_REGISTER_METHOD(void, SBBroadcaster
, Clear
, ());
204 LLDB_REGISTER_METHOD_CONST(
205 bool, SBBroadcaster
, operator==,(const lldb::SBBroadcaster
&));
206 LLDB_REGISTER_METHOD_CONST(
207 bool, SBBroadcaster
, operator!=,(const lldb::SBBroadcaster
&));
208 LLDB_REGISTER_METHOD_CONST(
209 bool, SBBroadcaster
, operator<,(const lldb::SBBroadcaster
&));