]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/Event.h
Update clang to trunk r256945.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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
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
47     DoOnRemoval (Event *event_ptr)
48     {
49     }
50
51     DISALLOW_COPY_AND_ASSIGN (EventData);
52 };
53
54 //----------------------------------------------------------------------
55 // lldb::EventDataBytes
56 //----------------------------------------------------------------------
57 class EventDataBytes : public EventData
58 {
59 public:
60     //------------------------------------------------------------------
61     // Constructors
62     //------------------------------------------------------------------
63     EventDataBytes ();
64
65     EventDataBytes (const char *cstr);
66
67     EventDataBytes (const void *src, size_t src_len);
68
69     ~EventDataBytes() override;
70
71     //------------------------------------------------------------------
72     // Member functions
73     //------------------------------------------------------------------
74     const ConstString &
75     GetFlavor () const override;
76
77     void
78     Dump (Stream *s) const override;
79
80     const void *
81     GetBytes() const;
82
83     size_t
84     GetByteSize() const;
85
86     void
87     SetBytes (const void *src, size_t src_len);
88     
89     void
90     SwapBytes (std::string &new_bytes);
91
92     void
93     SetBytesFromCString (const char *cstr);
94
95     //------------------------------------------------------------------
96     // Static functions
97     //------------------------------------------------------------------
98     static const EventDataBytes *
99     GetEventDataFromEvent (const Event *event_ptr);
100
101     static const void *
102     GetBytesFromEvent (const Event *event_ptr);
103
104     static size_t
105     GetByteSizeFromEvent (const Event *event_ptr);
106
107     static const ConstString &
108     GetFlavorString ();
109
110 private:
111     std::string m_bytes;
112
113     DISALLOW_COPY_AND_ASSIGN (EventDataBytes);
114 };
115
116 //----------------------------------------------------------------------
117 // lldb::Event
118 //----------------------------------------------------------------------
119 class Event
120 {
121     friend class Broadcaster;
122     friend class Listener;
123     friend class EventData;
124
125 public:
126     Event(Broadcaster *broadcaster, uint32_t event_type, EventData *data = nullptr);
127
128     Event(uint32_t event_type, EventData *data = nullptr);
129
130     ~Event ();
131
132     void
133     Dump (Stream *s) const;
134
135     EventData *
136     GetData ()
137     {
138         return m_data_ap.get();
139     }
140
141     const EventData *
142     GetData () const
143     {
144         return m_data_ap.get();
145     }
146     
147     void
148     SetData (EventData *new_data)
149     {
150         m_data_ap.reset (new_data);
151     }
152
153     uint32_t
154     GetType () const
155     {
156         return m_type;
157     }
158     
159     void
160     SetType (uint32_t new_type)
161     {
162         m_type = new_type;
163     }
164
165     Broadcaster *
166     GetBroadcaster () const
167     {
168         return m_broadcaster;
169     }
170     
171     bool
172     BroadcasterIs (Broadcaster *broadcaster)
173     {
174         return broadcaster == m_broadcaster;
175     }
176
177     void
178     Clear()
179     {
180         m_data_ap.reset();
181     }
182
183 private:
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.
187
188     void
189     DoOnRemoval ();
190
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.
194     void
195     SetBroadcaster (Broadcaster *broadcaster)
196     {
197         m_broadcaster = broadcaster;
198     }
199
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
203
204
205     DISALLOW_COPY_AND_ASSIGN (Event);
206     Event();    // Disallow default constructor
207 };
208
209 } // namespace lldb_private
210
211 #endif // liblldb_Event_h_