csutil/eventhandlers.h
Go to the documentation of this file.00001 /* 00002 Crystal Space 3D engine: Event and module naming interface 00003 (C) 2005 by Adam D. Bradley <artdodge@cs.bu.edu> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSUTIL_EVENTHANDLERS_H__ 00021 #define __CS_CSUTIL_EVENTHANDLERS_H__ 00022 00023 #include "cssysdef.h" 00024 #include "csextern.h" 00025 #include "iutil/eventnames.h" 00026 #include "iutil/eventhandlers.h" 00027 #include "iutil/eventh.h" 00028 #include "csutil/csstring.h" 00029 #include "csutil/eventnames.h" 00030 #include "csutil/frameeventsignpost.h" 00031 #include "csutil/scf_implementation.h" 00032 #include "csutil/threading/rwmutex.h" 00033 #include "csutil/hash.h" 00034 #include "csutil/strset.h" 00035 #include "csutil/ref.h" 00036 00037 struct iObjectRegistry; 00038 00046 struct iEventHandler; 00047 00053 class CS_CRYSTALSPACE_EXPORT csEventHandlerRegistry : 00054 public scfImplementation1<csEventHandlerRegistry, iEventHandlerRegistry> 00055 { 00056 public: 00057 csEventHandlerRegistry(iObjectRegistry*); 00058 ~csEventHandlerRegistry(); 00064 csHandlerID GetGenericID (const char*); 00065 static csHandlerID GetGenericID (iObjectRegistry *reg, 00066 const char* name) 00067 { 00068 return GetRegistry (reg)->GetGenericID (name); 00069 } 00070 csHandlerID GetGenericPreBoundID (csHandlerID); 00071 static csHandlerID GetGenericPreBoundID ( 00072 iObjectRegistry *reg, csHandlerID id) 00073 { 00074 return GetRegistry (reg)->GetGenericPreBoundID (id); 00075 } 00076 csHandlerID GetGenericPostBoundID (csHandlerID); 00077 static csHandlerID GetGenericPostBoundID ( 00078 iObjectRegistry *reg, csHandlerID id) 00079 { 00080 return GetRegistry (reg)->GetGenericPostBoundID (id); 00081 } 00082 00087 csHandlerID GetID (iEventHandler *); 00088 static csHandlerID GetID (iObjectRegistry *reg, 00089 iEventHandler *h) 00090 { 00091 return GetRegistry (reg)->GetID (h); 00092 } 00093 00094 csHandlerID RegisterID (iEventHandler *); 00095 static csHandlerID RegisterID (iObjectRegistry *reg, 00096 iEventHandler *h) 00097 { 00098 return GetRegistry (reg)->RegisterID (h); 00099 } 00100 00107 csHandlerID GetID (const char*); 00108 static csHandlerID GetID (iObjectRegistry *reg, 00109 const char* name) 00110 { 00111 return GetRegistry (reg)->GetID (name); 00112 } 00113 00117 void ReleaseID (csHandlerID id); 00118 static void ReleaseID (iObjectRegistry *reg, 00119 csHandlerID id) 00120 { 00121 GetRegistry (reg)->ReleaseID (id); 00122 } 00126 void ReleaseID (iEventHandler *); 00127 static void ReleaseID (iObjectRegistry *reg, 00128 iEventHandler *h) 00129 { 00130 GetRegistry (reg)->ReleaseID (h); 00131 } 00137 iEventHandler* GetHandler (csHandlerID id); 00138 static inline iEventHandler* GetHandler ( 00139 iObjectRegistry *reg, csHandlerID id) 00140 { 00141 return GetRegistry (reg)->GetHandler (id); 00142 }; 00143 00149 bool IsInstanceOf (csHandlerID instanceid, 00150 csHandlerID genericid); 00151 static inline bool IsInstanceOf (iObjectRegistry *reg, 00152 csHandlerID instanceid, csHandlerID genericid) 00153 { 00154 return GetRegistry (reg)->IsInstanceOf (instanceid, genericid); 00155 }; 00156 00160 bool IsInstance (csHandlerID id); 00161 static inline bool IsInstance (iObjectRegistry *reg, 00162 csHandlerID id) 00163 { 00164 return GetRegistry (reg)->IsInstance (id); 00165 }; 00166 00170 csHandlerID const GetGeneric (csHandlerID id); 00171 static inline csHandlerID GetGeneric (iObjectRegistry *reg, 00172 csHandlerID id) 00173 { 00174 return GetRegistry (reg)->GetGeneric (id); 00175 }; 00176 00180 const char* GetString (csHandlerID id); 00181 static inline const char* GetString ( 00182 iObjectRegistry *reg, csHandlerID id) 00183 { 00184 return GetRegistry (reg)->GetString (id); 00185 }; 00186 00187 static csRef<iEventHandlerRegistry> GetRegistry ( 00188 iObjectRegistry *object_reg); 00189 00190 private: 00191 iObjectRegistry *object_reg; 00192 csStringSet names; 00193 csHash<csHandlerID, csHandlerID> instantiation; 00194 struct KnownEventHandler 00195 { 00196 iEventHandler* handler; 00197 int refcount; 00198 00199 KnownEventHandler (iEventHandler* handler) : handler (handler), 00200 refcount (1) {} 00201 }; 00202 csHash<KnownEventHandler, csHandlerID> idToHandler; 00203 csHash<csHandlerID, csPtrKey<iEventHandler> > handlerToID; 00204 csHash<csHandlerID, csHandlerID> handlerPres; 00205 csHash<csHandlerID, csHandlerID> handlerPosts; 00206 uint32 instanceCounter; 00207 CS::Threading::ReadWriteMutex mutex; 00208 }; 00209 00210 /* @} */ 00211 00212 00213 00214 class FrameSignpost_Logic3D 00215 : public scfImplementation2<FrameSignpost_Logic3D, 00216 iFrameEventSignpost, 00217 scfFakeInterface<iEventHandler> > 00218 { 00219 private: 00220 FrameSignpost_Logic3D () : scfImplementationType (this) { } 00221 public: 00222 CS_EVENTHANDLER_NAMES("crystalspace.signpost.logic3d") 00223 virtual const csHandlerID * GenericPrec 00224 (csRef<iEventHandlerRegistry> &, 00225 csRef<iEventNameRegistry> &, 00226 csEventID) const; 00227 virtual const csHandlerID * GenericSucc 00228 (csRef<iEventHandlerRegistry> &r1, 00229 csRef<iEventNameRegistry> &r2, 00230 csEventID e) const; 00231 }; 00232 00233 class FrameSignpost_3D2D 00234 : public scfImplementation2<FrameSignpost_3D2D, 00235 iFrameEventSignpost, 00236 scfFakeInterface<iEventHandler> > 00237 { 00238 private: 00239 FrameSignpost_3D2D () : scfImplementationType (this) { } 00240 public: 00241 CS_EVENTHANDLER_NAMES("crystalspace.signpost.3d2d") 00242 virtual const csHandlerID * GenericPrec 00243 (csRef<iEventHandlerRegistry> &, 00244 csRef<iEventNameRegistry> &, 00245 csEventID) const; 00246 virtual const csHandlerID * GenericSucc 00247 (csRef<iEventHandlerRegistry> &r1, 00248 csRef<iEventNameRegistry> &r2, 00249 csEventID e) const; 00250 }; 00251 00252 class FrameSignpost_2DConsole 00253 : public scfImplementation2<FrameSignpost_2DConsole, 00254 iFrameEventSignpost, 00255 scfFakeInterface<iEventHandler> > 00256 { 00257 private: 00258 FrameSignpost_2DConsole () : scfImplementationType (this) { } 00259 public: 00260 CS_EVENTHANDLER_NAMES("crystalspace.signpost.2dconsole") 00261 virtual const csHandlerID * GenericPrec 00262 (csRef<iEventHandlerRegistry> &, 00263 csRef<iEventNameRegistry> &, 00264 csEventID) const; 00265 virtual const csHandlerID * GenericSucc 00266 (csRef<iEventHandlerRegistry> &r1, 00267 csRef<iEventNameRegistry> &r2, 00268 csEventID e) const; 00269 }; 00270 00271 class FrameSignpost_ConsoleDebug 00272 : public scfImplementation2<FrameSignpost_ConsoleDebug, 00273 iFrameEventSignpost, 00274 scfFakeInterface<iEventHandler> > 00275 { 00276 private: 00277 FrameSignpost_ConsoleDebug () : scfImplementationType (this) { } 00278 public: 00279 CS_EVENTHANDLER_NAMES("crystalspace.signpost.consoledebug") 00280 virtual const csHandlerID * GenericPrec 00281 (csRef<iEventHandlerRegistry> &, 00282 csRef<iEventNameRegistry> &, 00283 csEventID) const; 00284 virtual const csHandlerID * GenericSucc 00285 (csRef<iEventHandlerRegistry> &r1, 00286 csRef<iEventNameRegistry> &r2, 00287 csEventID e) const; 00288 }; 00289 00290 class FrameSignpost_DebugFrame 00291 : public scfImplementation2<FrameSignpost_DebugFrame, 00292 iFrameEventSignpost, 00293 scfFakeInterface<iEventHandler> > 00294 { 00295 private: 00296 FrameSignpost_DebugFrame () : scfImplementationType (this) { } 00297 public: 00298 CS_EVENTHANDLER_NAMES("crystalspace.signpost.debugframe") 00299 virtual const csHandlerID * GenericPrec 00300 (csRef<iEventHandlerRegistry> &, 00301 csRef<iEventNameRegistry> &, 00302 csEventID) const; 00303 virtual const csHandlerID * GenericSucc 00304 (csRef<iEventHandlerRegistry> &r1, 00305 csRef<iEventNameRegistry> &r2, 00306 csEventID e) const; 00307 }; 00308 00309 00315 #define CS_EVENTHANDLER_PHASE_LOGIC(x) \ 00316 CS_EVENTHANDLER_NAMES(x) \ 00317 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00318 virtual const csHandlerID * GenericPrec \ 00319 (csRef<iEventHandlerRegistry> &, csRef<iEventNameRegistry> &, \ 00320 csEventID) const { \ 00321 return 0; \ 00322 } \ 00323 virtual const csHandlerID * GenericSucc \ 00324 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00325 csEventID event) const { \ 00326 if (event != csevFrame(r2)) \ 00327 return 0; \ 00328 static csHandlerID succConstraint[6] = { \ 00329 FrameSignpost_Logic3D::StaticID(r1), \ 00330 FrameSignpost_3D2D::StaticID(r1), \ 00331 FrameSignpost_2DConsole::StaticID(r1), \ 00332 FrameSignpost_ConsoleDebug::StaticID(r1), \ 00333 FrameSignpost_DebugFrame::StaticID(r1), \ 00334 CS_HANDLERLIST_END \ 00335 }; \ 00336 return succConstraint; \ 00337 } 00338 00345 #define CS_EVENTHANDLER_PHASE_3D(x) \ 00346 CS_EVENTHANDLER_NAMES(x) \ 00347 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00348 virtual const csHandlerID * GenericPrec \ 00349 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00350 csEventID event) const { \ 00351 if (event != csevFrame(r2)) \ 00352 return 0; \ 00353 static csHandlerID precConstraint[2] = { \ 00354 FrameSignpost_Logic3D::StaticID(r1), \ 00355 CS_HANDLERLIST_END \ 00356 }; \ 00357 return precConstraint; \ 00358 } \ 00359 virtual const csHandlerID * GenericSucc \ 00360 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00361 csEventID event) const { \ 00362 if (event != csevFrame(r2)) \ 00363 return 0; \ 00364 static csHandlerID succConstraint[5] = { \ 00365 FrameSignpost_3D2D::StaticID(r1), \ 00366 FrameSignpost_2DConsole::StaticID(r1), \ 00367 FrameSignpost_ConsoleDebug::StaticID(r1), \ 00368 FrameSignpost_DebugFrame::StaticID(r1), \ 00369 CS_HANDLERLIST_END \ 00370 }; \ 00371 return succConstraint; \ 00372 } 00373 00380 #define CS_EVENTHANDLER_PHASE_2D(x) \ 00381 CS_EVENTHANDLER_NAMES(x) \ 00382 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00383 virtual const csHandlerID * GenericPrec \ 00384 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00385 csEventID event) const { \ 00386 if (event != csevFrame(r2)) \ 00387 return 0; \ 00388 static csHandlerID precConstraint[3] = { \ 00389 FrameSignpost_Logic3D::StaticID(r1), \ 00390 FrameSignpost_3D2D::StaticID(r1), \ 00391 CS_HANDLERLIST_END \ 00392 }; \ 00393 return precConstraint; \ 00394 } \ 00395 virtual const csHandlerID * GenericSucc \ 00396 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00397 csEventID event) const { \ 00398 if (event != csevFrame(r2)) \ 00399 return 0; \ 00400 static csHandlerID succConstraint[4] = { \ 00401 FrameSignpost_2DConsole::StaticID(r1), \ 00402 FrameSignpost_ConsoleDebug::StaticID(r1), \ 00403 FrameSignpost_DebugFrame::StaticID(r1), \ 00404 CS_HANDLERLIST_END \ 00405 }; \ 00406 return succConstraint; \ 00407 } 00408 00415 #define CS_EVENTHANDLER_PHASE_CONSOLE(x) \ 00416 CS_EVENTHANDLER_NAMES(x) \ 00417 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00418 virtual const csHandlerID * GenericPrec \ 00419 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00420 csEventID event) const { \ 00421 if (event != csevFrame(r2)) \ 00422 return 0; \ 00423 static csHandlerID precConstraint[4] = { \ 00424 FrameSignpost_Logic3D::StaticID(r1), \ 00425 FrameSignpost_3D2D::StaticID(r1), \ 00426 FrameSignpost_2DConsole::StaticID(r1), \ 00427 CS_HANDLERLIST_END \ 00428 }; \ 00429 return precConstraint; \ 00430 } \ 00431 virtual const csHandlerID * GenericSucc \ 00432 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00433 csEventID event) const { \ 00434 if (event != csevFrame(r2)) \ 00435 return 0; \ 00436 static csHandlerID succConstraint[3] = { \ 00437 FrameSignpost_ConsoleDebug::StaticID(r1), \ 00438 FrameSignpost_DebugFrame::StaticID(r1), \ 00439 CS_HANDLERLIST_END \ 00440 }; \ 00441 return succConstraint; \ 00442 } 00443 00450 #define CS_EVENTHANDLER_PHASE_DEBUG(x) \ 00451 CS_EVENTHANDLER_NAMES(x) \ 00452 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00453 virtual const csHandlerID * GenericPrec \ 00454 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00455 csEventID event) const { \ 00456 if (event != csevFrame(r2)) \ 00457 return 0; \ 00458 static csHandlerID precConstraint[5] = { \ 00459 FrameSignpost_Logic3D::StaticID(r1), \ 00460 FrameSignpost_3D2D::StaticID(r1), \ 00461 FrameSignpost_2DConsole::StaticID(r1), \ 00462 FrameSignpost_ConsoleDebug::StaticID(r1), \ 00463 CS_HANDLERLIST_END \ 00464 }; \ 00465 return precConstraint; \ 00466 } \ 00467 virtual const csHandlerID * GenericSucc \ 00468 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00469 csEventID event) const { \ 00470 if (event != csevFrame(r2)) \ 00471 return 0; \ 00472 static csHandlerID succConstraint[2] = { \ 00473 FrameSignpost_DebugFrame::StaticID(r1), \ 00474 CS_HANDLERLIST_END \ 00475 }; \ 00476 return succConstraint; \ 00477 } 00478 00484 #define CS_EVENTHANDLER_PHASE_FRAME(x) \ 00485 CS_EVENTHANDLER_NAMES(x) \ 00486 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00487 virtual const csHandlerID * GenericPrec \ 00488 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00489 csEventID event) const { \ 00490 if (event != csevFrame(r2)) \ 00491 return 0; \ 00492 static csHandlerID precConstraint[6]= { \ 00493 FrameSignpost_Logic3D::StaticID(r1), \ 00494 FrameSignpost_3D2D::StaticID(r1), \ 00495 FrameSignpost_2DConsole::StaticID(r1), \ 00496 FrameSignpost_ConsoleDebug::StaticID(r1), \ 00497 FrameSignpost_DebugFrame::StaticID(r1), \ 00498 CS_HANDLERLIST_END \ 00499 }; \ 00500 return precConstraint; \ 00501 } \ 00502 virtual const csHandlerID * GenericSucc \ 00503 (csRef<iEventHandlerRegistry> &, csRef<iEventNameRegistry> &, \ 00504 csEventID) const { \ 00505 return 0; \ 00506 } 00507 00508 #endif // __CS_CSUTIL_EVENTHANDLERS_H__
Generated for Crystal Space 2.1 by doxygen 1.6.1
