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/lldb-python.h"
12 #include "lldb/API/SBEvent.h"
13 #include "lldb/API/SBBroadcaster.h"
14 #include "lldb/API/SBStream.h"
16 #include "lldb/Core/Event.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Core/ConstString.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Breakpoint/Breakpoint.h"
22 #include "lldb/Interpreter/CommandInterpreter.h"
25 using namespace lldb_private;
34 SBEvent::SBEvent (uint32_t event_type, const char *cstr, uint32_t cstr_len) :
35 m_event_sp (new Event (event_type, new EventDataBytes (cstr, cstr_len))),
36 m_opaque_ptr (m_event_sp.get())
40 SBEvent::SBEvent (EventSP &event_sp) :
41 m_event_sp (event_sp),
42 m_opaque_ptr (event_sp.get())
46 SBEvent::SBEvent (const SBEvent &rhs) :
47 m_event_sp (rhs.m_event_sp),
48 m_opaque_ptr (rhs.m_opaque_ptr)
54 SBEvent::operator = (const SBEvent &rhs)
58 m_event_sp = rhs.m_event_sp;
59 m_opaque_ptr = rhs.m_opaque_ptr;
69 SBEvent::GetDataFlavor ()
71 Event *lldb_event = get();
74 EventData *event_data = lldb_event->GetData();
76 return lldb_event->GetData()->GetFlavor().AsCString();
82 SBEvent::GetType () const
84 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
86 const Event *lldb_event = get();
87 uint32_t event_type = 0;
89 event_type = lldb_event->GetType();
94 if (lldb_event && lldb_event->GetBroadcaster() && lldb_event->GetBroadcaster()->GetEventNames(sstr, event_type, true))
95 log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x (%s)", get(), event_type, sstr.GetData());
97 log->Printf ("SBEvent(%p)::GetType () => 0x%8.8x", get(), event_type);
105 SBEvent::GetBroadcaster () const
107 SBBroadcaster broadcaster;
108 const Event *lldb_event = get();
110 broadcaster.reset (lldb_event->GetBroadcaster(), false);
115 SBEvent::GetBroadcasterClass () const
117 const Event *lldb_event = get();
119 return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
121 return "unknown class";
125 SBEvent::BroadcasterMatchesPtr (const SBBroadcaster *broadcaster)
128 return BroadcasterMatchesRef (*broadcaster);
133 SBEvent::BroadcasterMatchesRef (const SBBroadcaster &broadcaster)
136 Event *lldb_event = get();
137 bool success = false;
139 success = lldb_event->BroadcasterIs (broadcaster.get());
141 // For logging, this gets a little chatty so only enable this when verbose logging is on
142 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE));
144 log->Printf ("SBEvent(%p)::BroadcasterMatchesRef (SBBroadcaster(%p): %s) => %i",
147 broadcaster.GetName(),
156 Event *lldb_event = get();
162 SBEvent::GetSP () const
170 // There is a dangerous accessor call GetSharedPtr which can be used, so if
171 // we have anything valid in m_event_sp, we must use that since if it gets
172 // used by a function that puts something in there, then it won't update
175 m_opaque_ptr = m_event_sp.get();
181 SBEvent::reset (EventSP &event_sp)
183 m_event_sp = event_sp;
184 m_opaque_ptr = m_event_sp.get();
188 SBEvent::reset (Event* event_ptr)
190 m_opaque_ptr = event_ptr;
195 SBEvent::IsValid() const
197 // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get()
198 // accessor. See comments in SBEvent::get()....
199 return SBEvent::get() != NULL;
204 SBEvent::GetCStringFromEvent (const SBEvent &event)
206 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
209 log->Printf ("SBEvent(%p)::GetCStringFromEvent () => \"%s\"",
211 reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.get())));
213 return reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.get()));
218 SBEvent::GetDescription (SBStream &description)
220 Stream &strm = description.ref();
224 m_opaque_ptr->Dump (&strm);
227 strm.PutCString ("No value");
233 SBEvent::GetDescription (SBStream &description) const
235 Stream &strm = description.ref();
239 m_opaque_ptr->Dump (&strm);
242 strm.PutCString ("No value");