HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_EventHandler.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_HANDLER_H__
10 #define __PDG_EVENT_HANDLER_H__
11 
12 #include "PDG_API.h"
13 
14 #include "PDG_EventTypes.h"
15 #include "PDG_RegisteredType.h"
16 
17 #include <UT/UT_TBBSpinLock.h>
18 
19 class PDG_Event;
20 class PDG_EventEmitter;
21 
22 /*
23  * Base class for an event handler that can be assigned to receive events from
24  * a PDG_EventEmitter. Handlers are registered with the event queue associated
25  * with the emitter.
26  */
28 {
29 public:
30  /// Constructs a new event handler. The handler keeps track of whether it
31  /// was created by user code or internally by Houdini/TOPs/PDG, to make
32  /// it possible for user to remove all "user created" handlers without
33  /// accidentally removing ones created internally.
36  bool user_handler=false);
37 
38  /// Destroys the handler and removes it from all active emitters, in case
39  /// the emitter has outlived the life time of the handler
40  virtual ~PDG_EventHandler();
41 
42 
43  /// Removes the handler from all emitters current in its emitter set
44  void removeFromAllEmitters();
45 
46  /// Returns the set of event emitters that this handler is currently
47  /// attached to
48  void emitters(PDG_EventEmitterSet& emitters) const;
49 
50 
51  /// Returns the language that event handler is implemented in. Mostly used
52  /// to distinguish between C++ event handler subclasses and ones created
53  /// using the PDG Python API.
55  { return myLanguage; }
56 
57  /// Returns true if this handler was created in user code
58  bool isUserHandler() const
59  { return myIsUserHandler; }
60 
61 protected:
62  /// The main event handling hook, invoked by the event queue each time an
63  /// event for this handler is dispatched. This method must be implemented
64  /// by subclasses.
65  virtual void handlePDGEvent(const PDG_Event &) = 0;
66 
67  /// Invoke to indicate to subclasses that an emitter is no longer, an has
68  /// been removed from the emitter set.
70  {};
71 
72 private:
73  friend class PDG_EventQueue;
74 
75  void registerEventEmitter(PDG_EventEmitter *emitter);
76  void unregisterEventEmitter(
77  PDG_EventEmitter *emitter,
78  bool notify);
79 
80 private:
81  mutable UT_TBBSpinLock myEmittersLock;
82  PDG_EventEmitterSet myEmitters;
83  PDG_BaseType::Language myLanguage;
84  bool myIsUserHandler;
85 };
86 
87 #endif
#define PDG_API
Definition: PDG_API.h:23
virtual void eventEmitterNotAvailable(PDG_EventEmitter *emitter)
bool isUserHandler() const
Returns true if this handler was created in user code.
PDG_BaseType::Language language() const