[mlir][py] Enable loading only specified dialects during creation. (#121421)
[llvm-project.git] / lldb / source / API / SBBroadcaster.cpp
blob6e34b2f71b8243c0980faee576751caf5b39bf7c
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 //===----------------------------------------------------------------------===//
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"
16 using namespace lldb;
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);
39 if (this != &rhs) {
40 m_opaque_sp = rhs.m_opaque_sp;
41 m_opaque_ptr = rhs.m_opaque_ptr;
43 return *this;
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)
52 return;
54 if (unique)
55 m_opaque_ptr->BroadcastEventIfUnique(event_type);
56 else
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)
64 return;
66 EventSP event_sp = event.GetSP();
67 if (unique)
68 m_opaque_ptr->BroadcastEventIfUnique(event_sp);
69 else
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);
77 if (m_opaque_ptr)
78 m_opaque_ptr->AddInitialEventsToListener(listener.m_opaque_sp,
79 requested_events);
82 uint32_t SBBroadcaster::AddListener(const SBListener &listener,
83 uint32_t event_mask) {
84 LLDB_INSTRUMENT_VA(this, listener, event_mask);
86 if (m_opaque_ptr)
87 return m_opaque_ptr->AddListener(listener.m_opaque_sp, event_mask);
88 return 0;
91 const char *SBBroadcaster::GetName() const {
92 LLDB_INSTRUMENT_VA(this);
94 if (m_opaque_ptr)
95 return ConstString(m_opaque_ptr->GetBroadcasterName()).GetCString();
96 return nullptr;
99 bool SBBroadcaster::EventTypeHasListeners(uint32_t event_type) {
100 LLDB_INSTRUMENT_VA(this, event_type);
102 if (m_opaque_ptr)
103 return m_opaque_ptr->EventTypeHasListeners(event_type);
104 return false;
107 bool SBBroadcaster::RemoveListener(const SBListener &listener,
108 uint32_t event_mask) {
109 LLDB_INSTRUMENT_VA(this, listener, event_mask);
111 if (m_opaque_ptr)
112 return m_opaque_ptr->RemoveListener(listener.m_opaque_sp, event_mask);
113 return false;
116 Broadcaster *SBBroadcaster::get() const { return m_opaque_ptr; }
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;
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);
139 m_opaque_sp.reset();
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;