1 //===-- Event.h -------------------------------------------------*- 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 #ifndef liblldb_Event_h_
11 #define liblldb_Event_h_
18 // Other libraries and framework includes
20 #include "lldb/lldb-private.h"
21 #include "lldb/Core/ConstString.h"
22 #include "lldb/Host/Predicate.h"
24 namespace lldb_private {
26 //----------------------------------------------------------------------
28 //----------------------------------------------------------------------
39 virtual const ConstString &
40 GetFlavor () const = 0;
43 Dump (Stream *s) const;
47 DoOnRemoval (Event *event_ptr)
51 DISALLOW_COPY_AND_ASSIGN (EventData);
54 //----------------------------------------------------------------------
55 // lldb::EventDataBytes
56 //----------------------------------------------------------------------
57 class EventDataBytes : public EventData
60 //------------------------------------------------------------------
62 //------------------------------------------------------------------
65 EventDataBytes (const char *cstr);
67 EventDataBytes (const void *src, size_t src_len);
69 ~EventDataBytes() override;
71 //------------------------------------------------------------------
73 //------------------------------------------------------------------
75 GetFlavor () const override;
78 Dump (Stream *s) const override;
87 SetBytes (const void *src, size_t src_len);
90 SwapBytes (std::string &new_bytes);
93 SetBytesFromCString (const char *cstr);
95 //------------------------------------------------------------------
97 //------------------------------------------------------------------
98 static const EventDataBytes *
99 GetEventDataFromEvent (const Event *event_ptr);
102 GetBytesFromEvent (const Event *event_ptr);
105 GetByteSizeFromEvent (const Event *event_ptr);
107 static const ConstString &
113 DISALLOW_COPY_AND_ASSIGN (EventDataBytes);
116 //----------------------------------------------------------------------
118 //----------------------------------------------------------------------
121 friend class Broadcaster;
122 friend class Listener;
123 friend class EventData;
126 Event(Broadcaster *broadcaster, uint32_t event_type, EventData *data = nullptr);
128 Event(uint32_t event_type, EventData *data = nullptr);
133 Dump (Stream *s) const;
138 return m_data_ap.get();
144 return m_data_ap.get();
148 SetData (EventData *new_data)
150 m_data_ap.reset (new_data);
160 SetType (uint32_t new_type)
166 GetBroadcaster () const
168 return m_broadcaster;
172 BroadcasterIs (Broadcaster *broadcaster)
174 return broadcaster == m_broadcaster;
184 // This is only called by Listener when it pops an event off the queue for
185 // the listener. It calls the Event Data's DoOnRemoval() method, which is
186 // virtual and can be overridden by the specific data classes.
191 // Called by Broadcaster::BroadcastEvent prior to letting all the listeners
192 // know about it update the contained broadcaster so that events can be
193 // popped off one queue and re-broadcast to others.
195 SetBroadcaster (Broadcaster *broadcaster)
197 m_broadcaster = broadcaster;
200 Broadcaster * m_broadcaster; // The broadcaster that sent this event
201 uint32_t m_type; // The bit describing this event
202 std::unique_ptr<EventData> m_data_ap; // User specific data for this event
205 DISALLOW_COPY_AND_ASSIGN (Event);
206 Event(); // Disallow default constructor
209 } // namespace lldb_private
211 #endif // liblldb_Event_h_