1 //===-- Event.h -------------------------------------------------*- 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 #ifndef liblldb_Event_h_ 11 #define liblldb_Event_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <list> 16 #include <string> 17 18 // Other libraries and framework includes 19 // Project includes 20 #include "lldb/lldb-private.h" 21 #include "lldb/Core/ConstString.h" 22 #include "lldb/Host/Predicate.h" 23 24 namespace lldb_private { 25 26 //---------------------------------------------------------------------- 27 // lldb::EventData 28 //---------------------------------------------------------------------- 29 class EventData 30 { 31 friend class Event; 32 33 public: 34 EventData (); 35 36 virtual 37 ~EventData(); 38 39 virtual const ConstString & 40 GetFlavor () const = 0; 41 42 virtual void 43 Dump (Stream *s) const; 44 45 private: 46 virtual void DoOnRemoval(Event * event_ptr)47 DoOnRemoval (Event *event_ptr) 48 { 49 } 50 51 DISALLOW_COPY_AND_ASSIGN (EventData); 52 53 }; 54 55 //---------------------------------------------------------------------- 56 // lldb::EventDataBytes 57 //---------------------------------------------------------------------- 58 class EventDataBytes : public EventData 59 { 60 public: 61 //------------------------------------------------------------------ 62 // Constructors 63 //------------------------------------------------------------------ 64 EventDataBytes (); 65 66 EventDataBytes (const char *cstr); 67 68 EventDataBytes (const void *src, size_t src_len); 69 70 virtual 71 ~EventDataBytes(); 72 73 //------------------------------------------------------------------ 74 // Member functions 75 //------------------------------------------------------------------ 76 virtual const ConstString & 77 GetFlavor () const; 78 79 virtual void 80 Dump (Stream *s) const; 81 82 const void * 83 GetBytes() const; 84 85 size_t 86 GetByteSize() const; 87 88 void 89 SetBytes (const void *src, size_t src_len); 90 91 void 92 SwapBytes (std::string &new_bytes); 93 94 void 95 SetBytesFromCString (const char *cstr); 96 97 //------------------------------------------------------------------ 98 // Static functions 99 //------------------------------------------------------------------ 100 static const EventDataBytes * 101 GetEventDataFromEvent (const Event *event_ptr); 102 103 static const void * 104 GetBytesFromEvent (const Event *event_ptr); 105 106 static size_t 107 GetByteSizeFromEvent (const Event *event_ptr); 108 109 static const ConstString & 110 GetFlavorString (); 111 112 private: 113 std::string m_bytes; 114 115 DISALLOW_COPY_AND_ASSIGN (EventDataBytes); 116 117 }; 118 119 //---------------------------------------------------------------------- 120 // lldb::Event 121 //---------------------------------------------------------------------- 122 class Event 123 { 124 friend class Broadcaster; 125 friend class Listener; 126 friend class EventData; 127 128 public: 129 130 Event (Broadcaster *broadcaster, uint32_t event_type, EventData *data = NULL); 131 132 Event (uint32_t event_type, EventData *data = NULL); 133 134 ~Event (); 135 136 void 137 Dump (Stream *s) const; 138 139 EventData * GetData()140 GetData () 141 { 142 return m_data_ap.get(); 143 } 144 145 const EventData * GetData()146 GetData () const 147 { 148 return m_data_ap.get(); 149 } 150 151 void SetData(EventData * new_data)152 SetData (EventData *new_data) 153 { 154 m_data_ap.reset (new_data); 155 } 156 157 uint32_t GetType()158 GetType () const 159 { 160 return m_type; 161 } 162 163 void SetType(uint32_t new_type)164 SetType (uint32_t new_type) 165 { 166 m_type = new_type; 167 } 168 169 Broadcaster * GetBroadcaster()170 GetBroadcaster () const 171 { 172 return m_broadcaster; 173 } 174 175 bool BroadcasterIs(Broadcaster * broadcaster)176 BroadcasterIs (Broadcaster *broadcaster) 177 { 178 return broadcaster == m_broadcaster; 179 } 180 181 void Clear()182 Clear() 183 { 184 m_data_ap.reset(); 185 } 186 187 188 private: 189 // This is only called by Listener when it pops an event off the queue for 190 // the listener. It calls the Event Data's DoOnRemoval() method, which is 191 // virtual and can be overridden by the specific data classes. 192 193 void 194 DoOnRemoval (); 195 196 // Called by Broadcaster::BroadcastEvent prior to letting all the listeners 197 // know about it update the contained broadcaster so that events can be 198 // popped off one queue and re-broadcast to others. 199 void SetBroadcaster(Broadcaster * broadcaster)200 SetBroadcaster (Broadcaster *broadcaster) 201 { 202 m_broadcaster = broadcaster; 203 } 204 205 206 Broadcaster * m_broadcaster; // The broadcaster that sent this event 207 uint32_t m_type; // The bit describing this event 208 std::unique_ptr<EventData> m_data_ap; // User specific data for this event 209 210 211 DISALLOW_COPY_AND_ASSIGN (Event); 212 Event(); // Disallow default constructor 213 }; 214 215 } // namespace lldb_private 216 217 #endif // liblldb_Event_h_ 218