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/Core/Event.h"
15 #include "lldb/Core/Stream.h"
16 #include "lldb/Core/StreamFile.h"
17 #include "lldb/Core/ConstString.h"
18 #include "lldb/Target/Process.h"
19 #include "lldb/Breakpoint/Breakpoint.h"
20 #include "lldb/Interpreter/CommandInterpreter.h"
23 using namespace lldb_private;
32 SBEvent::SBEvent (uint32_t event_type, const char *cstr, uint32_t cstr_len) :
33 m_event_sp (new Event (event_type, new EventDataBytes (cstr, cstr_len))),
34 m_opaque_ptr (m_event_sp.get())
38 SBEvent::SBEvent (EventSP &event_sp) :
39 m_event_sp (event_sp),
40 m_opaque_ptr (event_sp.get())
44 SBEvent::SBEvent (Event *event_ptr) :
46 m_opaque_ptr (event_ptr)
50 SBEvent::SBEvent (const SBEvent &rhs) :
51 m_event_sp (rhs.m_event_sp),
52 m_opaque_ptr (rhs.m_opaque_ptr)
58 SBEvent::operator = (const SBEvent &rhs)
62 m_event_sp = rhs.m_event_sp;
63 m_opaque_ptr = rhs.m_opaque_ptr;
73 SBEvent::GetDataFlavor ()
75 Event *lldb_event = get();
78 EventData *event_data = lldb_event->GetData();
80 return lldb_event->GetData()->GetFlavor().AsCString();
86 SBEvent::GetType () const
88 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
90 const Event *lldb_event = get();
91 uint32_t event_type = 0;
93 event_type = lldb_event->GetType();
98 if (lldb_event && lldb_event->GetBroadcaster() && lldb_event->GetBroadcaster()->GetEventNames(sstr, event_type, true))
99 log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x (%s)",
100 static_cast<void*>(get()), event_type, sstr.GetData());
102 log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x",
103 static_cast<void*>(get()), event_type);
111 SBEvent::GetBroadcaster () const
113 SBBroadcaster broadcaster;
114 const Event *lldb_event = get();
116 broadcaster.reset (lldb_event->GetBroadcaster(), false);
121 SBEvent::GetBroadcasterClass () const
123 const Event *lldb_event = get();
125 return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
127 return "unknown class";
131 SBEvent::BroadcasterMatchesPtr (const SBBroadcaster *broadcaster)
134 return BroadcasterMatchesRef (*broadcaster);
139 SBEvent::BroadcasterMatchesRef (const SBBroadcaster &broadcaster)
142 Event *lldb_event = get();
143 bool success = false;
145 success = lldb_event->BroadcasterIs (broadcaster.get());
147 // For logging, this gets a little chatty so only enable this when verbose logging is on
148 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE));
150 log->Printf ("SBEvent(%p)::BroadcasterMatchesRef (SBBroadcaster(%p): %s) => %i",
151 static_cast<void*>(get()),
152 static_cast<void*>(broadcaster.get()),
153 broadcaster.GetName(), success);
161 Event *lldb_event = get();
167 SBEvent::GetSP () const
175 // There is a dangerous accessor call GetSharedPtr which can be used, so if
176 // we have anything valid in m_event_sp, we must use that since if it gets
177 // used by a function that puts something in there, then it won't update
180 m_opaque_ptr = m_event_sp.get();
186 SBEvent::reset (EventSP &event_sp)
188 m_event_sp = event_sp;
189 m_opaque_ptr = m_event_sp.get();
193 SBEvent::reset (Event* event_ptr)
195 m_opaque_ptr = event_ptr;
200 SBEvent::IsValid() const
202 // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get()
203 // accessor. See comments in SBEvent::get()....
204 return SBEvent::get() != NULL;
209 SBEvent::GetCStringFromEvent (const SBEvent &event)
211 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
214 log->Printf ("SBEvent(%p)::GetCStringFromEvent () => \"%s\"",
215 static_cast<void*>(event.get()),
216 reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.get())));
218 return reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.get()));
223 SBEvent::GetDescription (SBStream &description)
225 Stream &strm = description.ref();
229 m_opaque_ptr->Dump (&strm);
232 strm.PutCString ("No value");
238 SBEvent::GetDescription (SBStream &description) const
240 Stream &strm = description.ref();
244 m_opaque_ptr->Dump (&strm);
247 strm.PutCString ("No value");