]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Core/Event.h
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / include / lldb / Core / Event.h
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 <memory>
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 #include "lldb/Core/Broadcaster.h"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 // lldb::EventData
29 //----------------------------------------------------------------------
30 class EventData
31 {
32     friend class Event;
33
34 public:
35     EventData ();
36
37     virtual
38     ~EventData();
39
40     virtual const ConstString &
41     GetFlavor () const = 0;
42
43     virtual void
44     Dump (Stream *s) const;
45
46 private:
47     virtual void
48     DoOnRemoval (Event *event_ptr)
49     {
50     }
51
52     DISALLOW_COPY_AND_ASSIGN (EventData);
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     ~EventDataBytes() override;
71
72     //------------------------------------------------------------------
73     // Member functions
74     //------------------------------------------------------------------
75     const ConstString &
76     GetFlavor () const override;
77
78     void
79     Dump (Stream *s) const override;
80
81     const void *
82     GetBytes() const;
83
84     size_t
85     GetByteSize() const;
86
87     void
88     SetBytes (const void *src, size_t src_len);
89     
90     void
91     SwapBytes (std::string &new_bytes);
92
93     void
94     SetBytesFromCString (const char *cstr);
95
96     //------------------------------------------------------------------
97     // Static functions
98     //------------------------------------------------------------------
99     static const EventDataBytes *
100     GetEventDataFromEvent (const Event *event_ptr);
101
102     static const void *
103     GetBytesFromEvent (const Event *event_ptr);
104
105     static size_t
106     GetByteSizeFromEvent (const Event *event_ptr);
107
108     static const ConstString &
109     GetFlavorString ();
110
111 private:
112     std::string m_bytes;
113
114     DISALLOW_COPY_AND_ASSIGN (EventDataBytes);
115 };
116
117 class EventDataReceipt : public EventData
118 {
119 public:
120     EventDataReceipt() :
121         EventData(),
122         m_predicate(false)
123     {
124     }
125
126     ~EventDataReceipt() override
127     {
128     }
129
130     static const ConstString &
131     GetFlavorString ()
132     {
133         static ConstString g_flavor("Process::ProcessEventData");
134         return g_flavor;
135     }
136
137     const ConstString &
138     GetFlavor () const override
139     {
140         return GetFlavorString();
141     }
142
143     bool
144     WaitForEventReceived (const TimeValue *abstime = nullptr, bool *timed_out = nullptr)
145     {
146         return m_predicate.WaitForValueEqualTo(true, abstime, timed_out);
147     }
148
149 private:
150     Predicate<bool> m_predicate;
151     
152     void
153     DoOnRemoval (Event *event_ptr)  override
154     {
155         m_predicate.SetValue(true, eBroadcastAlways);
156     }
157 };
158
159 //----------------------------------------------------------------------
160 // lldb::Event
161 //----------------------------------------------------------------------
162 class Event
163 {
164     friend class Listener;
165     friend class EventData;
166     friend class Broadcaster::BroadcasterImpl;
167
168 public:
169     Event(Broadcaster *broadcaster, uint32_t event_type, EventData *data = nullptr);
170
171     Event(Broadcaster *broadcaster, uint32_t event_type, const lldb::EventDataSP &event_data_sp);
172
173     Event(uint32_t event_type, EventData *data = nullptr);
174
175     Event(uint32_t event_type, const lldb::EventDataSP &event_data_sp);
176
177     ~Event ();
178
179     void
180     Dump (Stream *s) const;
181
182     EventData *
183     GetData ()
184     {
185         return m_data_sp.get();
186     }
187
188     const EventData *
189     GetData () const
190     {
191         return m_data_sp.get();
192     }
193     
194     void
195     SetData (EventData *new_data)
196     {
197         m_data_sp.reset (new_data);
198     }
199
200     uint32_t
201     GetType () const
202     {
203         return m_type;
204     }
205     
206     void
207     SetType (uint32_t new_type)
208     {
209         m_type = new_type;
210     }
211
212     Broadcaster *
213     GetBroadcaster () const
214     {
215         Broadcaster::BroadcasterImplSP broadcaster_impl_sp = m_broadcaster_wp.lock();
216         if (broadcaster_impl_sp)
217             return broadcaster_impl_sp->GetBroadcaster();
218         else
219             return nullptr;
220     }
221     
222     bool
223     BroadcasterIs (Broadcaster *broadcaster)
224     {
225         Broadcaster::BroadcasterImplSP broadcaster_impl_sp = m_broadcaster_wp.lock();
226         if (broadcaster_impl_sp)
227             return broadcaster_impl_sp->GetBroadcaster() == broadcaster;
228         else
229             return false;
230     }
231
232     void
233     Clear()
234     {
235         m_data_sp.reset();
236     }
237
238 private:
239     // This is only called by Listener when it pops an event off the queue for
240     // the listener.  It calls the Event Data's DoOnRemoval() method, which is
241     // virtual and can be overridden by the specific data classes.
242
243     void
244     DoOnRemoval ();
245
246     // Called by Broadcaster::BroadcastEvent prior to letting all the listeners
247     // know about it update the contained broadcaster so that events can be
248     // popped off one queue and re-broadcast to others.
249     void
250     SetBroadcaster (Broadcaster *broadcaster)
251     {
252         m_broadcaster_wp = broadcaster->GetBroadcasterImpl();
253     }
254
255     Broadcaster::BroadcasterImplWP m_broadcaster_wp; // The broadcaster that sent this event
256     uint32_t m_type; // The bit describing this event
257     lldb::EventDataSP m_data_sp; // User specific data for this event
258
259
260     DISALLOW_COPY_AND_ASSIGN (Event);
261     Event();    // Disallow default constructor
262 };
263
264 } // namespace lldb_private
265
266 #endif // liblldb_Event_h_