|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #ifndef TC_HEADER_Platform_Event ! 10: #define TC_HEADER_Platform_Event ! 11: ! 12: #include "PlatformBase.h" ! 13: #include "ForEach.h" ! 14: #include "Mutex.h" ! 15: #include "SharedPtr.h" ! 16: ! 17: namespace TrueCrypt ! 18: { ! 19: struct EventArgs ! 20: { ! 21: virtual ~EventArgs () { } ! 22: }; ! 23: ! 24: class EventConnectorBase ! 25: { ! 26: public: ! 27: virtual ~EventConnectorBase () { } ! 28: virtual void operator() (EventArgs &args) = 0; ! 29: ! 30: virtual EventConnectorBase *CloneNew () const = 0; ! 31: virtual void *GetHandler () const = 0; ! 32: }; ! 33: ! 34: typedef list < shared_ptr <EventConnectorBase> > EventHandlerList; ! 35: ! 36: template <class T> ! 37: class EventConnector : public EventConnectorBase ! 38: { ! 39: public: ! 40: typedef void (T::*EventHandlerFunction) (EventArgs &); ! 41: ! 42: EventConnector (T *handler, EventHandlerFunction function) ! 43: : Handler (handler), Function (function) { } ! 44: ! 45: virtual void operator() (EventArgs &args) { (Handler->*Function) (args); } ! 46: ! 47: virtual EventConnectorBase *CloneNew () const { return new EventConnector <T> (*this); } ! 48: virtual void *GetHandler () const { return Handler; } ! 49: ! 50: protected: ! 51: T *Handler; ! 52: EventHandlerFunction Function; ! 53: }; ! 54: ! 55: class Event ! 56: { ! 57: public: ! 58: Event () { } ! 59: virtual ~Event () { } ! 60: ! 61: void Connect (const EventConnectorBase &connector); ! 62: void Disconnect (void *handler); ! 63: void Raise (); ! 64: void Raise (EventArgs &args); ! 65: ! 66: protected: ! 67: EventHandlerList ConnectedHandlers; ! 68: Mutex HandlersMutex; ! 69: ! 70: private: ! 71: Event (const Event &); ! 72: Event &operator= (const Event &); ! 73: }; ! 74: ! 75: struct ExceptionEventArgs : EventArgs ! 76: { ! 77: ExceptionEventArgs (exception &ex) : mException (ex) { } ! 78: exception &mException; ! 79: ! 80: private: ! 81: ExceptionEventArgs (const ExceptionEventArgs &); ! 82: ExceptionEventArgs &operator= (const ExceptionEventArgs &); ! 83: }; ! 84: } ! 85: ! 86: #endif // TC_HEADER_Platform_Event
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.