HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_EventManager.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  * NAME: CH_EventManager.h ( Channel Library, C++)
7  *
8  * COMMENTS:
9  * CH_EventManager
10  * . this is the class that manages channel event handlers
11  * . there is one global channel manager
12  * CH_EventHandler
13  * . objects of this type handle events and do things such as:
14  * . keeping track of added channels
15  * . sending out events on destruction
16  * CH_AutoEventHandler
17  * . this class is provided for convenience
18  * . if constructed with a CH_EventHandler, it will register
19  * it with the event manager; when the AutoEventHandler object
20  * goes out of scope, it will unregerister and destroy the
21  * event handler.
22  */
23 
24 #ifndef __CH_EventManager__
25 #define __CH_EventManager__
26 
27 #include "CH_API.h"
28 #include <UT/UT_Map.h>
29 #include <UT/UT_NonCopyable.h>
30 #include <UT/UT_StringHolder.h>
31 
32 class CH_Channel;
33 
34 /*
35  * the difference between CH_CHANNELS_MAJOR_CHANGE and CH_CHANNEL_CHANGED is that
36  * the former indicates a major change to the segments and will lead to an
37  * OP_PARM_ANIMATED event being sent out in OP_Channels, whereas the latter is
38  * not so major.
39  *
40  * order matters with these events
41  */
42 typedef enum {
43  CH_UNCHANGED, // used to dirty caches without sending extra
44  // events (see PRM_Parm::indirectChange())
45  CH_CHANNELS_DELETED, // one or more fewer channels (data: NULL)
46  CH_CHANNELS_ADDED, // new channel (singular?)
47  CH_CHANNELS_MAJOR_CHANGE, // segment pointers changed/added/removed, etc.
48  CH_CHANNEL_CHANGED, // key values changed, etc.
49  CH_CHANNEL_UICHANGED, // eg. expression mode
50  CH_PARM_ENABLE_CHANGED, // parm enable state changed
51  CH_PARM_VISIBLE_CHANGED, // parm visible state changed
52  CH_PARM_LOCK_CHANGED, // parm lock state changed
53  CH_CHANNELS_MOVED, // time value(s) changed
54  CH_PERMISSION_CHANGED, // permission to this channel changed
55 
56  // These CH_GROUP* events are used by the CH_Manager only
57  CH_GROUP_CREATED, // must be first CH_GROUP item!
63  CH_GROUP_CHANGED, // must be last CH_GROUP item!
64 
70 
73 
76 
77 CH_API extern const char * CHeventNames[CH_CHANGE_TYPE_COUNT];
78 
79 // UTformat support.
80 static inline size_t
81 format(char *buffer, size_t buffer_size, const CH_CHANGE_TYPE &v)
82 {
84  if (!buffer)
85  return s.length();
86  else
87  {
88  size_t len = std::min(size_t(s.length()), buffer_size);
89  ::memcpy(buffer, s.c_str(), len);
90  return len;
91  }
92 }
93 
94 
96 {
97 public:
99  virtual ~CH_EventHandler() {}
100 
102 
103  virtual void event( CH_CHANGE_TYPE, void * );
104 
105  static CH_EventHandler *newHandler()
106  {
107  return new CH_EventHandler;
108  }
109 };
110 
111 typedef CH_EventHandler *(*CH_EventHandlerCreator)();
112 
113 
114 class CH_Collection;
115 
117 {
118 public:
120  ~CH_EventHandlerHash() override;
121 
123 
124  void event( CH_CHANGE_TYPE, void * ) override;
125 
127  {
128  return new CH_EventHandlerHash;
129  }
130 protected:
131  void removeReferencingEvents(void *data);
132 private:
134  bool myScopeChanged;
135  CH_Collection *myRootCollection;
136 };
137 
139 {
140 public:
141  CH_EventManager();
142  virtual ~CH_EventManager();
143 
145 
146  void beginHandlingEvents( CH_EventHandlerCreator creator );
147  void endHandlingEvents();
148 
149  CH_EventHandler *getHandler();
150 
151  bool enabled() const;
152  void setEnabled(bool e);
153 
154 private:
155  CH_EventHandler *myDefaultHandler;
156  CH_EventHandler *myCurrentHandler;
157  int myLevels;
158  bool myEnabled;
159 };
160 
162 
163 // The following functions are provided for convenience:
164 CH_API void CHevent( CH_CHANGE_TYPE, void * );
165 
167 {
168 public:
170  {
172  }
173 
175  {
177  }
178 
180 };
181 
183 {
184 public:
186  : myEnabled(enable)
187  {
188  if( myEnabled )
190  }
191 
193  {
194  if( myEnabled )
196  }
197 
199 
200 private:
201  bool myEnabled;
202 };
203 
204 #endif
const GLdouble * v
Definition: glcorearb.h:837
CH_EventHandler *(* CH_EventHandlerCreator)()
CH_AutoEventHandler(CH_EventHandlerCreator creator)
GLdouble s
Definition: glad.h:3009
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glcorearb.h:2539
CH_AutoEventHandlerEx(CH_EventHandlerCreator creator, bool enable)
struct _cl_event * event
Definition: glcorearb.h:2961
CH_API const char * CHeventNames[CH_CHANGE_TYPE_COUNT]
Definition: core.h:760
CH_CHANGE_TYPE
exint length() const
virtual ~CH_EventHandler()
static CH_EventHandler * newHandler()
void endHandlingEvents()
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
CH_API void CHevent(CH_CHANGE_TYPE, void *)
CH_API CH_EventManager * CHgetEventManager()
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
SYS_FORCE_INLINE const char * c_str() const
#define CH_API
Definition: CH_API.h:10
virtual void event(CH_CHANGE_TYPE, void *)
void beginHandlingEvents(CH_EventHandlerCreator creator)
Definition: format.h:895