1 //===-- SBBroadcaster.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 10 #include "lldb/Core/Broadcaster.h" 11 #include "lldb/Core/Log.h" 12 13 #include "lldb/API/SBBroadcaster.h" 14 #include "lldb/API/SBListener.h" 15 #include "lldb/API/SBEvent.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 21 SBBroadcaster::SBBroadcaster () : 22 m_opaque_sp (), 23 m_opaque_ptr (NULL) 24 { 25 } 26 27 SBBroadcaster::SBBroadcaster (const char *name) : 28 m_opaque_sp (new Broadcaster (NULL, name)), 29 m_opaque_ptr (NULL) 30 { 31 m_opaque_ptr = m_opaque_sp.get(); 32 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE)); 33 34 if (log) 35 log->Printf ("SBBroadcaster::SBBroadcaster (name=\"%s\") => SBBroadcaster(%p)", 36 name, m_opaque_ptr); 37 } 38 39 SBBroadcaster::SBBroadcaster (lldb_private::Broadcaster *broadcaster, bool owns) : 40 m_opaque_sp (owns ? broadcaster : NULL), 41 m_opaque_ptr (broadcaster) 42 { 43 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE)); 44 45 if (log) 46 log->Printf ("SBBroadcaster::SBBroadcaster (broadcaster=%p, bool owns=%i) => SBBroadcaster(%p)", 47 broadcaster, owns, m_opaque_ptr); 48 } 49 50 SBBroadcaster::SBBroadcaster (const SBBroadcaster &rhs) : 51 m_opaque_sp (rhs.m_opaque_sp), 52 m_opaque_ptr (rhs.m_opaque_ptr) 53 { 54 } 55 56 const SBBroadcaster & 57 SBBroadcaster::operator = (const SBBroadcaster &rhs) 58 { 59 if (this != &rhs) 60 { 61 m_opaque_sp = rhs.m_opaque_sp; 62 m_opaque_ptr = rhs.m_opaque_ptr; 63 } 64 return *this; 65 } 66 67 SBBroadcaster::~SBBroadcaster() 68 { 69 reset (NULL, false); 70 } 71 72 void 73 SBBroadcaster::BroadcastEventByType (uint32_t event_type, bool unique) 74 { 75 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 76 77 if (log) 78 log->Printf ("SBBroadcaster(%p)::BroadcastEventByType (event_type=0x%8.8x, unique=%i)", m_opaque_ptr, event_type, unique); 79 80 if (m_opaque_ptr == NULL) 81 return; 82 83 if (unique) 84 m_opaque_ptr->BroadcastEventIfUnique (event_type); 85 else 86 m_opaque_ptr->BroadcastEvent (event_type); 87 } 88 89 void 90 SBBroadcaster::BroadcastEvent (const SBEvent &event, bool unique) 91 { 92 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 93 94 if (log) 95 log->Printf ("SBBroadcaster(%p)::BroadcastEventByType (SBEvent(%p), unique=%i)", m_opaque_ptr, event.get(), unique); 96 97 if (m_opaque_ptr == NULL) 98 return; 99 100 EventSP event_sp = event.GetSP (); 101 if (unique) 102 m_opaque_ptr->BroadcastEventIfUnique (event_sp); 103 else 104 m_opaque_ptr->BroadcastEvent (event_sp); 105 } 106 107 void 108 SBBroadcaster::AddInitialEventsToListener (const SBListener &listener, uint32_t requested_events) 109 { 110 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 111 if (log) 112 log->Printf ("SBBroadcaster(%p)::AddInitialEventsToListener (SBListener(%p), event_mask=0x%8.8x)", m_opaque_ptr, listener.get(), requested_events); 113 if (m_opaque_ptr) 114 m_opaque_ptr->AddInitialEventsToListener (listener.get(), requested_events); 115 } 116 117 uint32_t 118 SBBroadcaster::AddListener (const SBListener &listener, uint32_t event_mask) 119 { 120 if (m_opaque_ptr) 121 return m_opaque_ptr->AddListener (listener.get(), event_mask); 122 return 0; 123 } 124 125 const char * 126 SBBroadcaster::GetName () const 127 { 128 if (m_opaque_ptr) 129 return m_opaque_ptr->GetBroadcasterName().GetCString(); 130 return NULL; 131 } 132 133 bool 134 SBBroadcaster::EventTypeHasListeners (uint32_t event_type) 135 { 136 if (m_opaque_ptr) 137 return m_opaque_ptr->EventTypeHasListeners (event_type); 138 return false; 139 } 140 141 bool 142 SBBroadcaster::RemoveListener (const SBListener &listener, uint32_t event_mask) 143 { 144 if (m_opaque_ptr) 145 return m_opaque_ptr->RemoveListener (listener.get(), event_mask); 146 return false; 147 } 148 149 Broadcaster * 150 SBBroadcaster::get () const 151 { 152 return m_opaque_ptr; 153 } 154 155 void 156 SBBroadcaster::reset (Broadcaster *broadcaster, bool owns) 157 { 158 if (owns) 159 m_opaque_sp.reset (broadcaster); 160 else 161 m_opaque_sp.reset (); 162 m_opaque_ptr = broadcaster; 163 } 164 165 166 bool 167 SBBroadcaster::IsValid () const 168 { 169 return m_opaque_ptr != NULL; 170 } 171 172 void 173 SBBroadcaster::Clear () 174 { 175 m_opaque_sp.reset(); 176 m_opaque_ptr = NULL; 177 } 178 179 bool 180 SBBroadcaster::operator == (const SBBroadcaster &rhs) const 181 { 182 return m_opaque_ptr == rhs.m_opaque_ptr; 183 184 } 185 186 bool 187 SBBroadcaster::operator != (const SBBroadcaster &rhs) const 188 { 189 return m_opaque_ptr != rhs.m_opaque_ptr; 190 } 191 192 bool 193 SBBroadcaster::operator < (const SBBroadcaster &rhs) const 194 { 195 return m_opaque_ptr < rhs.m_opaque_ptr; 196 } 197