/* # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING # # If you have any feedback please consult http://openslx.org/feedback and # send your suggestions, praise, or complaints to feedback@openslx.org # # General information about OpenSLX can be found at http://openslx.org/ # -------------------------------------------------------------------------- # inputEventHandler.h: # - Common definitions for input event handlers # -------------------------------------------------------------------------- */ #ifndef INPUTEVENTHANDLER_H_ #define INPUTEVENTHANDLER_H_ #include #include #include #include #include #define HANDLER_TYPE_DONT_CARE 0xffff #define HANDLER_CODE_DONT_CARE 0xffff #define HANDLER_VALUE_DONT_CARE 0xffffffff template class DefaultInputEventHandler { public: static bool matches(InputEvent const& evt) { if(Type != 0xffff) { if(evt.type() != Type) return false; } if(Code != 0xffff) { if(evt.code() != Code) return false; } if(Value != 0xffffffff) { if(evt.value() != Value) return false; } return true; } static void initialize() { } }; namespace policy { struct NoSecurityCheck { static bool allow(InputEvent const&) { return true; } }; struct PhysicalSeatSecurityCheck { static bool allow(InputEvent const&) { return /* TODO implement */ true; } }; struct AlwaysDenySecurityCheck { static bool allow(InputEvent const&) { return false; } }; struct UnixLike; struct Linux; struct Windows; #if defined(__linux) typedef boost::mpl::vector2::type Systems; #elif defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) typedef boost::mpl::vector1::type Systems; #else # error "Porting is needed!" #endif struct SystemEnabled; struct SystemDisabled; template struct RequireSystem { typedef typename boost::mpl::contains::type enabled_type; static const bool enabled = enabled_type::value; }; struct RequireNoSystem { typedef boost::mpl::bool_::type enabled_type; static const bool enabled = enabled_type::value; }; } template class HandlerHelper { public: static bool handle(InputEvent const& evt) { if(!SecurityPolicy::allow(evt)) { return true; } if(Delegate::matches(evt)) { Delegate::handle(evt); return true; } else { return false; } } static void initialize() { Delegate::initialize(); } }; template class HandlerHelper { public: static bool handle(InputEvent const& evt) { return false; } static void initialize() { } }; template struct Handler : public HandlerHelper { }; template struct InputEventHandlerChainHelper { private: typedef typename boost::mpl::next::type next_iterator_type; typedef InputEventHandlerChainHelper next_in_chain; typedef typename boost::mpl::deref::type handler_type; public: static void handle(InputEvent const& evt) { if(!handler_type::handle(evt)) { next_in_chain::handle(evt); } } static void initialize() { handler_type::initialize(); next_in_chain::initialize(); } }; template struct InputEventHandlerChainHelper { public: static void handle(InputEvent const&) { // do nothing } static void initialize() { // do nothing } }; template struct InputEventHandlerChain : public InputEventHandlerChainHelper::type, typename boost::mpl::end::type> { }; #endif /* INPUTEVENTHANDLER_H_ */