X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FEvents.hh;h=698a43320cad76090c6ab1941181265501f350fc;hb=48bbf27e9e89d6eba4754fba65d70a15b115ac8b;hp=d077ac4ea71ff7a7676f5c8a43b3eb9a55e5a2e4;hpb=89efe5f504c400212090aba703c7ee385f483c64;p=senf.git diff --git a/PPI/Events.hh b/PPI/Events.hh index d077ac4..698a433 100644 --- a/PPI/Events.hh +++ b/PPI/Events.hh @@ -25,6 +25,9 @@ #define HH_Events_ 1 // Custom includes +#include +#include +#include "predecl.hh" //#include "Events.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -32,43 +35,101 @@ namespace senf { namespace ppi { + // Implementation: The concrete EventDescriptor implementation will need to set things up so + // some callback (within the EventDescriptor implementation) will be called when the event + // happens. This setup happens in 'v_enable()'. This internal handler sets up an EventType + // instance if needed and calls 'callback()'. + // + // 'callback()' will access the EventBinding wrapper to find the user-callback to signal. It + // will do any needed internal processing, call that user callback and clean up afterwards. + /** \brief Generic event interface baseclass - The EventDescriptor baseclass provides an interface to manuplate events in a generic + The EventDescriptor baseclass provides an interface to manipulate events in a generic way. This allows to register events or to temporarily disable event processing. */ class EventDescriptor { public: + virtual ~EventDescriptor(); + bool enabled(); ///< Check, whether the event is currently enabled - void enabled(bool); ///< Enable or disable the event + void enabled(bool v); ///< Enable or disable the event protected: - typedef unspecified CallbackType; ///< Fixed type of the (internal) event handler. - - void register(CallbackType handler); ///< Register the event - void unregister(); ///< Unregister the event + EventDescriptor(); private: - virtual void v_register(CallbackType handler) = 0; ///< Called to register the event - virtual void v_unregister() = 0; ///< Called to unregister the event virtual void v_enable() = 0; ///< Called to enable the event delivery - virtual void v_disable() = 0; ///< Called to disable the event delilvery - virtual void v_process() = 0; ///< Called whenever the event is signaled - /**< This virtual method is called \e after every call to - the event handler to provide a hook for further - processing (example: calculate the next time, an - interval timer expires) */ + virtual void v_disable() = 0; ///< Called to disable the event delivery + + virtual bool v_isRegistered() = 0; + + void notifyThrottle(); + void notifyUnthrottle(); + + void registerRoute(ForwardingRoute & route); bool enabled_; + + typedef std::vector Routes; + Routes routes_; + + friend class ForwardingRoute; + }; + + template + class EventImplementationHelper + { + protected: + typedef typename detail::EventArgType::type EventArg; + + void callback(EventArg event, boost::posix_time::ptime time); + void callback(EventArg event); + + private: + detail::EventBinding & binding(); + }; + + template + class EventImplementationHelper + { + protected: + void callback(boost::posix_time::ptime time); + void callback(); + + private: + detail::EventBinding & binding(); + }; + + template + class EventImplementation + : public EventDescriptor, + public EventImplementationHelper< EventType, EventImplementation > + { + public: + typedef EventType Event; + typedef typename detail::EventArgType::type EventArg; + + protected: + EventImplementation(); + + private: + virtual bool v_isRegistered(); + void setBinding(detail::EventBinding & binding); + + detail::EventBinding * binding_; + + friend class EventManager; + friend class EventImplementationHelper< EventType, EventImplementation >; }; }} ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Events.cci" +#include "Events.cci" //#include "Events.ct" -//#include "Events.cti" +#include "Events.cti" #endif @@ -78,4 +139,6 @@ namespace ppi { // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: