HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_EventEmitter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef __PDG_EVENT_EMITTER_H__
10 #define __PDG_EVENT_EMITTER_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_EventTypes.h"
15 
16 #include <UT/UT_NonCopyable.h>
17 
18 class PDG_EventHandler;
19 class PDG_Event;
20 class PDG_EventQueue;
21 
23 {
24 public:
26  PDG_EventQueue* event_queue,
27  bool block_destruction);
28  virtual ~PDG_EventEmitter();
29 
31 
32  /// Returns the list of supported event types for this emitter
33  virtual const PDG_EventFilter&
34  supportedEventTypes() const = 0;
35 
36  /// Returns memory usage for this event emitter instance
37  int64 getMemoryUsage(bool inclusive) const;
38 
39  /// Adds an event handlers that listens for all types of events
40  bool addEventHandler(PDG_EventHandler* handler);
41 
42  /// Adds an event handlers that listens for a specific event
43  bool addEventHandler(
44  PDG_EventHandler* handler,
46 
47  /// Adds an event handler with a filter, so that it only listens for
48  /// events in the specified list
49  bool addEventHandler(
50  PDG_EventHandler* handler,
51  const PDG_EventFilter& filter);
52 
53  /// Removes an event handler from this emitter
54  void removeEventHandler(PDG_EventHandler* handler);
55 
56  /// Removes all event handlers from this emitter. If user_handler_only
57  /// is true, only user-added event handlers are removed.
58  void removeAllEventHandlers(
59  bool user_handler_only = false);
60 
61  /// Emit an event to all handlers
62  void emitEvent(
63  const PDG_Event& event,
64  bool immediate=false) const;
65 
66  /// Safely makes a copy of the list of handlers. If this emitter is
67  /// currently being destroyed, the resulting array is empty
68  void eventHandlers(
69  PDG_EventHandlerArray& handlers) const;
70 
71  /// Sets the event queue associated with this event emitter. This method
72  /// will also register the emitter with the queue, and unregister it with
73  /// the old queue. If the queue is being destroyed then the clearEventQueue
74  /// method should be called instead
75  void setEventQueue(PDG_EventQueue* event_queue);
76 
77  /// Clears the emitter's event queue without running any registration or
78  /// deregistration logic
79  void clearEventQueue();
80 
81  /// Returns true if the emitter should handle the specified event, and
82  /// false if no handler is assigned for it
83  bool shouldEmit(const PDG_Event& event) const;
84 
85 private:
86  friend class PDG_EventQueue;
87 
88  /// Returns a reference to the underlying filter map, which the event
89  /// queue is allowed to modify
90  PDG_EventFilterMap& filterMap()
91  { return myFilterMap; }
92 
93 private:
94  static PDG_EventFilter theAllFilter;
95  static PDG_EventFilter theLogFilter;
96 
97  PDG_EventQueue* myEventQueue;
98  PDG_EventFilterMap myFilterMap;
99 
100  bool myHasHandlers;
101  bool myWaitEventsWhenDestroyed;
102 };
103 
104 #endif
#define PDG_API
Definition: PDG_API.h:23
struct _cl_event * event
Definition: glcorearb.h:2961
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
PDG_EventType
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297