1 //===-- SBEvent.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBEvent.h"
11 #include "lldb/API/SBBroadcaster.h"
12 #include "lldb/API/SBStream.h"
14 #include "lldb/Breakpoint/Breakpoint.h"
15 #include "lldb/Core/Event.h"
16 #include "lldb/Core/StreamFile.h"
17 #include "lldb/Interpreter/CommandInterpreter.h"
18 #include "lldb/Target/Process.h"
19 #include "lldb/Utility/ConstString.h"
20 #include "lldb/Utility/Stream.h"
23 using namespace lldb_private;
25 SBEvent::SBEvent() : m_event_sp(), m_opaque_ptr(NULL) {}
27 SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
28 : m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
29 m_opaque_ptr(m_event_sp.get()) {}
31 SBEvent::SBEvent(EventSP &event_sp)
32 : m_event_sp(event_sp), m_opaque_ptr(event_sp.get()) {}
34 SBEvent::SBEvent(Event *event_ptr) : m_event_sp(), m_opaque_ptr(event_ptr) {}
36 SBEvent::SBEvent(const SBEvent &rhs)
37 : m_event_sp(rhs.m_event_sp), m_opaque_ptr(rhs.m_opaque_ptr) {}
39 const SBEvent &SBEvent::operator=(const SBEvent &rhs) {
41 m_event_sp = rhs.m_event_sp;
42 m_opaque_ptr = rhs.m_opaque_ptr;
47 SBEvent::~SBEvent() {}
49 const char *SBEvent::GetDataFlavor() {
50 Event *lldb_event = get();
52 EventData *event_data = lldb_event->GetData();
54 return lldb_event->GetData()->GetFlavor().AsCString();
59 uint32_t SBEvent::GetType() const {
60 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
62 const Event *lldb_event = get();
63 uint32_t event_type = 0;
65 event_type = lldb_event->GetType();
69 if (lldb_event && lldb_event->GetBroadcaster() &&
70 lldb_event->GetBroadcaster()->GetEventNames(sstr, event_type, true))
71 log->Printf("SBEvent(%p)::GetType () => 0x%8.8x (%s)",
72 static_cast<void *>(get()), event_type, sstr.GetData());
74 log->Printf("SBEvent(%p)::GetType () => 0x%8.8x",
75 static_cast<void *>(get()), event_type);
81 SBBroadcaster SBEvent::GetBroadcaster() const {
82 SBBroadcaster broadcaster;
83 const Event *lldb_event = get();
85 broadcaster.reset(lldb_event->GetBroadcaster(), false);
89 const char *SBEvent::GetBroadcasterClass() const {
90 const Event *lldb_event = get();
92 return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
94 return "unknown class";
97 bool SBEvent::BroadcasterMatchesPtr(const SBBroadcaster *broadcaster) {
99 return BroadcasterMatchesRef(*broadcaster);
103 bool SBEvent::BroadcasterMatchesRef(const SBBroadcaster &broadcaster) {
105 Event *lldb_event = get();
106 bool success = false;
108 success = lldb_event->BroadcasterIs(broadcaster.get());
110 // For logging, this gets a little chatty so only enable this when verbose
112 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
113 LLDB_LOGV(log, "({0}) (SBBroadcaster({1}): {2}) => {3}", get(),
114 broadcaster.get(), broadcaster.GetName(), success);
119 void SBEvent::Clear() {
120 Event *lldb_event = get();
125 EventSP &SBEvent::GetSP() const { return m_event_sp; }
127 Event *SBEvent::get() const {
128 // There is a dangerous accessor call GetSharedPtr which can be used, so if
129 // we have anything valid in m_event_sp, we must use that since if it gets
130 // used by a function that puts something in there, then it won't update
133 m_opaque_ptr = m_event_sp.get();
138 void SBEvent::reset(EventSP &event_sp) {
139 m_event_sp = event_sp;
140 m_opaque_ptr = m_event_sp.get();
143 void SBEvent::reset(Event *event_ptr) {
144 m_opaque_ptr = event_ptr;
148 bool SBEvent::IsValid() const {
149 // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get()
150 // accessor. See comments in SBEvent::get()....
151 return SBEvent::get() != NULL;
154 const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
155 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
158 log->Printf("SBEvent(%p)::GetCStringFromEvent () => \"%s\"",
159 static_cast<void *>(event.get()),
160 reinterpret_cast<const char *>(
161 EventDataBytes::GetBytesFromEvent(event.get())));
163 return reinterpret_cast<const char *>(
164 EventDataBytes::GetBytesFromEvent(event.get()));
167 bool SBEvent::GetDescription(SBStream &description) {
168 Stream &strm = description.ref();
171 m_opaque_ptr->Dump(&strm);
173 strm.PutCString("No value");
178 bool SBEvent::GetDescription(SBStream &description) const {
179 Stream &strm = description.ref();
182 m_opaque_ptr->Dump(&strm);
184 strm.PutCString("No value");