Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBEvent.cpp ---------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame^] | 10 | #include "lldb/API/SBEvent.h" |
| 11 | #include "lldb/API/SBBroadcaster.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | |
| 13 | #include "lldb/Core/Event.h" |
| 14 | #include "lldb/Core/Stream.h" |
| 15 | #include "lldb/Core/StreamFile.h" |
| 16 | #include "lldb/Core/ConstString.h" |
| 17 | #include "lldb/Target/Process.h" |
| 18 | #include "lldb/Breakpoint/Breakpoint.h" |
| 19 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | |
| 25 | SBEvent::SBEvent () : |
| 26 | m_event_sp (), |
| 27 | m_lldb_object (NULL) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | SBEvent::SBEvent (uint32_t event_type, const char *cstr, uint32_t cstr_len) : |
| 32 | m_event_sp (new Event (event_type, new EventDataBytes (cstr, cstr_len))), |
| 33 | m_lldb_object (m_event_sp.get()) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | SBEvent::SBEvent (EventSP &event_sp) : |
| 38 | m_event_sp (event_sp), |
| 39 | m_lldb_object (event_sp.get()) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | SBEvent::~SBEvent() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | SBEvent::Dump (FILE *f) const |
| 49 | { |
| 50 | const Event *lldb_event = GetLLDBObjectPtr(); |
| 51 | if (lldb_event) |
| 52 | { |
| 53 | StreamFile str(f); |
| 54 | lldb_event->Dump ((Stream *) &str); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | const char * |
| 59 | SBEvent::GetDataFlavor () |
| 60 | { |
| 61 | Event *lldb_event = SBEvent::GetLLDBObjectPtr(); |
| 62 | if (lldb_event) |
| 63 | return lldb_event->GetData()->GetFlavor().AsCString(); |
| 64 | return NULL; |
| 65 | } |
| 66 | |
| 67 | uint32_t |
| 68 | SBEvent::GetType () const |
| 69 | { |
| 70 | const Event *lldb_event = SBEvent::GetLLDBObjectPtr(); |
| 71 | if (lldb_event) |
| 72 | return lldb_event->GetType(); |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | SBBroadcaster |
| 77 | SBEvent::GetBroadcaster () const |
| 78 | { |
| 79 | SBBroadcaster broadcaster; |
| 80 | const Event *lldb_event = SBEvent::GetLLDBObjectPtr(); |
| 81 | if (lldb_event) |
| 82 | broadcaster.SetLLDBObjectPtr (lldb_event->GetBroadcaster(), false); |
| 83 | return broadcaster; |
| 84 | } |
| 85 | |
| 86 | bool |
| 87 | SBEvent::BroadcasterMatchesPtr (const SBBroadcaster *broadcaster) |
| 88 | { |
| 89 | if (broadcaster) |
| 90 | { |
| 91 | Event *lldb_event = SBEvent::GetLLDBObjectPtr(); |
| 92 | if (lldb_event) |
| 93 | return lldb_event->BroadcasterIs (broadcaster->GetLLDBObjectPtr ()); |
| 94 | } |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool |
| 99 | SBEvent::BroadcasterMatchesRef (const SBBroadcaster &broadcaster) |
| 100 | { |
| 101 | Event *lldb_event = SBEvent::GetLLDBObjectPtr(); |
| 102 | if (lldb_event) |
| 103 | return lldb_event->BroadcasterIs (broadcaster.GetLLDBObjectPtr ()); |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | SBEvent::Clear() |
| 109 | { |
| 110 | Event *lldb_event = SBEvent::GetLLDBObjectPtr(); |
| 111 | if (lldb_event) |
| 112 | lldb_event->Clear(); |
| 113 | } |
| 114 | |
| 115 | EventSP & |
| 116 | SBEvent::GetSharedPtr () const |
| 117 | { |
| 118 | return m_event_sp; |
| 119 | } |
| 120 | |
| 121 | Event * |
| 122 | SBEvent::GetLLDBObjectPtr () |
| 123 | { |
| 124 | // There is a dangerous accessor call GetSharedPtr which can be used, so if |
| 125 | // we have anything valid in m_event_sp, we must use that since if it gets |
| 126 | // used by a function that puts something in there, then it won't update |
| 127 | // m_lldb_object... |
| 128 | if (m_event_sp) |
| 129 | m_lldb_object = m_event_sp.get(); |
| 130 | |
| 131 | return m_lldb_object; |
| 132 | } |
| 133 | |
| 134 | const Event * |
| 135 | SBEvent::GetLLDBObjectPtr () const |
| 136 | { |
| 137 | // There is a dangerous accessor call GetSharedPtr which can be used, so if |
| 138 | // we have anything valid in m_event_sp, we must use that since if it gets |
| 139 | // used by a function that puts something in there, then it won't update |
| 140 | // m_lldb_object... |
| 141 | if (m_event_sp) |
| 142 | m_lldb_object = m_event_sp.get(); |
| 143 | |
| 144 | return m_lldb_object; |
| 145 | } |
| 146 | |
| 147 | void |
| 148 | SBEvent::SetEventSP (EventSP &event_sp) |
| 149 | { |
| 150 | m_event_sp = event_sp; |
| 151 | m_lldb_object = m_event_sp.get(); |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | SBEvent::SetLLDBObjectPtr (Event* event_ptr) |
| 156 | { |
| 157 | m_lldb_object = event_ptr; |
| 158 | m_event_sp.reset(); |
| 159 | } |
| 160 | |
| 161 | bool |
| 162 | SBEvent::IsValid() const |
| 163 | { |
| 164 | // Do NOT use m_lldb_object directly!!! Must use the SBEvent::GetLLDBObjectPtr() |
| 165 | // accessor. See comments in SBEvent::GetLLDBObjectPtr().... |
| 166 | return SBEvent::GetLLDBObjectPtr() != NULL; |
| 167 | |
| 168 | } |
| 169 | |
| 170 | const char * |
| 171 | SBEvent::GetCStringFromEvent (const SBEvent &event) |
| 172 | { |
| 173 | return reinterpret_cast<const char *>(EventDataBytes::GetBytesFromEvent (event.GetLLDBObjectPtr())); |
| 174 | } |
| 175 | |
| 176 | |