1 //===-- SBBroadcaster.cpp -------------------------------------------------===//
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 "lldb/Utility/Broadcaster.h"
10 #include "lldb/Utility/Instrumentation.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() { LLDB_INSTRUMENT_VA(this); }
21 SBBroadcaster::SBBroadcaster(const char *name
)
22 : m_opaque_sp(new Broadcaster(nullptr, name
)) {
23 LLDB_INSTRUMENT_VA(this, name
);
25 m_opaque_ptr
= m_opaque_sp
.get();
28 SBBroadcaster::SBBroadcaster(lldb_private::Broadcaster
*broadcaster
, bool owns
)
29 : m_opaque_sp(owns
? broadcaster
: nullptr), m_opaque_ptr(broadcaster
) {}
31 SBBroadcaster::SBBroadcaster(const SBBroadcaster
&rhs
)
32 : m_opaque_sp(rhs
.m_opaque_sp
), m_opaque_ptr(rhs
.m_opaque_ptr
) {
33 LLDB_INSTRUMENT_VA(this, rhs
);
36 const SBBroadcaster
&SBBroadcaster::operator=(const SBBroadcaster
&rhs
) {
37 LLDB_INSTRUMENT_VA(this, rhs
);
40 m_opaque_sp
= rhs
.m_opaque_sp
;
41 m_opaque_ptr
= rhs
.m_opaque_ptr
;
46 SBBroadcaster::~SBBroadcaster() { reset(nullptr, false); }
48 void SBBroadcaster::BroadcastEventByType(uint32_t event_type
, bool unique
) {
49 LLDB_INSTRUMENT_VA(this, event_type
, unique
);
51 if (m_opaque_ptr
== nullptr)
55 m_opaque_ptr
->BroadcastEventIfUnique(event_type
);
57 m_opaque_ptr
->BroadcastEvent(event_type
);
60 void SBBroadcaster::BroadcastEvent(const SBEvent
&event
, bool unique
) {
61 LLDB_INSTRUMENT_VA(this, event
, unique
);
63 if (m_opaque_ptr
== nullptr)
66 EventSP event_sp
= event
.GetSP();
68 m_opaque_ptr
->BroadcastEventIfUnique(event_sp
);
70 m_opaque_ptr
->BroadcastEvent(event_sp
);
73 void SBBroadcaster::AddInitialEventsToListener(const SBListener
&listener
,
74 uint32_t requested_events
) {
75 LLDB_INSTRUMENT_VA(this, listener
, requested_events
);
78 m_opaque_ptr
->AddInitialEventsToListener(listener
.m_opaque_sp
,
82 uint32_t SBBroadcaster::AddListener(const SBListener
&listener
,
83 uint32_t event_mask
) {
84 LLDB_INSTRUMENT_VA(this, listener
, event_mask
);
87 return m_opaque_ptr
->AddListener(listener
.m_opaque_sp
, event_mask
);
91 const char *SBBroadcaster::GetName() const {
92 LLDB_INSTRUMENT_VA(this);
95 return ConstString(m_opaque_ptr
->GetBroadcasterName()).GetCString();
99 bool SBBroadcaster::EventTypeHasListeners(uint32_t event_type
) {
100 LLDB_INSTRUMENT_VA(this, event_type
);
103 return m_opaque_ptr
->EventTypeHasListeners(event_type
);
107 bool SBBroadcaster::RemoveListener(const SBListener
&listener
,
108 uint32_t event_mask
) {
109 LLDB_INSTRUMENT_VA(this, listener
, event_mask
);
112 return m_opaque_ptr
->RemoveListener(listener
.m_opaque_sp
, event_mask
);
116 Broadcaster
*SBBroadcaster::get() const { return m_opaque_ptr
; }
118 void SBBroadcaster::reset(Broadcaster
*broadcaster
, bool owns
) {
120 m_opaque_sp
.reset(broadcaster
);
123 m_opaque_ptr
= broadcaster
;
126 bool SBBroadcaster::IsValid() const {
127 LLDB_INSTRUMENT_VA(this);
128 return this->operator bool();
130 SBBroadcaster::operator bool() const {
131 LLDB_INSTRUMENT_VA(this);
133 return m_opaque_ptr
!= nullptr;
136 void SBBroadcaster::Clear() {
137 LLDB_INSTRUMENT_VA(this);
140 m_opaque_ptr
= nullptr;
143 bool SBBroadcaster::operator==(const SBBroadcaster
&rhs
) const {
144 LLDB_INSTRUMENT_VA(this, rhs
);
146 return m_opaque_ptr
== rhs
.m_opaque_ptr
;
149 bool SBBroadcaster::operator!=(const SBBroadcaster
&rhs
) const {
150 LLDB_INSTRUMENT_VA(this, rhs
);
152 return m_opaque_ptr
!= rhs
.m_opaque_ptr
;
155 bool SBBroadcaster::operator<(const SBBroadcaster
&rhs
) const {
156 LLDB_INSTRUMENT_VA(this, rhs
);
158 return m_opaque_ptr
< rhs
.m_opaque_ptr
;