diff options
| author | Sebastien Braun | 2010-10-04 00:22:14 +0200 |
|---|---|---|
| committer | Sebastien Braun | 2010-10-05 18:15:48 +0200 |
| commit | 266eb5fb14c07e67aa211a5860e9abf3009136e3 (patch) | |
| tree | 9eeb8b159edf6e83880c056f1177cebec2ad354c /src/input/inputEventHandler.h | |
| parent | Defect #715, apply patch by Sébastien (diff) | |
| download | pvs-266eb5fb14c07e67aa211a5860e9abf3009136e3.tar.gz pvs-266eb5fb14c07e67aa211a5860e9abf3009136e3.tar.xz pvs-266eb5fb14c07e67aa211a5860e9abf3009136e3.zip | |
Implement first version of basic input event support
Diffstat (limited to 'src/input/inputEventHandler.h')
| -rw-r--r-- | src/input/inputEventHandler.h | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/src/input/inputEventHandler.h b/src/input/inputEventHandler.h new file mode 100644 index 0000000..3910f93 --- /dev/null +++ b/src/input/inputEventHandler.h @@ -0,0 +1,187 @@ +/* + # 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 <QtGlobal> +#include <boost/mpl/contains.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/vector.hpp> +#include <src/input/inputEvent.h> + +#define HANDLER_TYPE_DONT_CARE 0xffff +#define HANDLER_CODE_DONT_CARE 0xffff +#define HANDLER_VALUE_DONT_CARE 0xffffffff + +template<quint16 Type = HANDLER_TYPE_DONT_CARE, + quint16 Code = HANDLER_CODE_DONT_CARE, + quint32 Value = HANDLER_VALUE_DONT_CARE> +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<UnixLike,Linux>::type Systems; +#elif defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) +typedef boost::mpl::vector1<Windows>::type Systems; +#else +# error "Porting is needed!" +#endif + +struct SystemEnabled; +struct SystemDisabled; + +template<typename System> +struct RequireSystem +{ + typedef typename boost::mpl::contains<Systems, System>::type enabled_type; + static const bool enabled = enabled_type::value; +}; + +struct RequireNoSystem +{ + typedef boost::mpl::bool_<true>::type enabled_type; + static const bool enabled = enabled_type::value; +}; + +} + +template<bool Enabled, typename Delegate, typename SecurityPolicy> +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<typename Delegate, typename SecurityPolicy> +class HandlerHelper<false, Delegate, SecurityPolicy> +{ +public: + static bool handle(InputEvent const& evt) { + return false; + } + + static void initialize() + { + } +}; + +template<typename Delegate, typename SecurityPolicy = policy::NoSecurityCheck, typename SystemPolicy = policy::RequireNoSystem> +struct Handler : public HandlerHelper<SystemPolicy::enabled, Delegate, SecurityPolicy> +{ +}; + +template<typename Begin, typename End> +struct InputEventHandlerChainHelper +{ +private: + typedef typename boost::mpl::next<Begin>::type next_iterator_type; + typedef InputEventHandlerChainHelper<next_iterator_type, End> next_in_chain; + + typedef typename boost::mpl::deref<Begin>::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<typename End> +struct InputEventHandlerChainHelper<End, End> +{ +public: + static void handle(InputEvent const&) { + // do nothing + } + + static void initialize() { + // do nothing + } +}; + +template<typename Collection> +struct InputEventHandlerChain : public InputEventHandlerChainHelper<typename boost::mpl::begin<Collection>::type, typename boost::mpl::end<Collection>::type> +{ +}; + +#endif /* INPUTEVENTHANDLER_H_ */ |
