Abort hook functions on any result other than `OK`

Instead of only aborting hook functions if a handler returns `EVENT_CONSUMED`,
only continue abortable hooks if a handler returns `OK`. For existing core
plugins, this shouldn't make any difference because none of them use the `ERROR`
return value.

Also rename `shouldAbortOnConsumedEvent` to better match the new conditional.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent e5e0544540
commit 9dd9c9557c
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -27,7 +27,7 @@
// OPERATION once for each event handler defined herein with the following // OPERATION once for each event handler defined herein with the following
// parameters: // parameters:
// //
// HOOK_NAME, SHOULD_ABORT_ON_CONSUMED_EVENT, SIGNATURE, ARGS_LIST, ... // HOOK_NAME, SHOULD_EXIT_IF_RESULT_NOT_OK, SIGNATURE, ARGS_LIST, ...
// //
// Any additional parameters that are added to an invokation // Any additional parameters that are added to an invokation
// of _FOR_EACH_EVENT_HANDLER are passed through to OP. // of _FOR_EACH_EVENT_HANDLER are passed through to OP.
@ -72,8 +72,8 @@
// Plugins' event handlers are called in the same order as the plugins // Plugins' event handlers are called in the same order as the plugins
// are passed to the KALEIDOSCOPE_INIT_PLUGINS(...) macro within the // are passed to the KALEIDOSCOPE_INIT_PLUGINS(...) macro within the
// sketch. For some handlers it is desirable to not call subsequent // sketch. For some handlers it is desirable to not call subsequent
// plugins' handlers once a plugin's handler returned the value // plugins' handlers once a plugin's handler returned a value other
// kaleidoscope::EventHandlerResult::EVENT_CONSUMED. To enable this // than kaleidoscope::EventHandlerResult::OK. To enable this,
// pass the abortable flag value _ABORTABLE, _NOT_ABORTABLE otherwise. // pass the abortable flag value _ABORTABLE, _NOT_ABORTABLE otherwise.
// //
// template parameter type list: // template parameter type list:

@ -32,7 +32,7 @@ namespace kaleidoscope {
#define INSTANTIATE_WEAK_HOOK_FUNCTION( \ #define INSTANTIATE_WEAK_HOOK_FUNCTION( \
HOOK_NAME, HOOK_VERSION, DEPRECATION_TAG, \ HOOK_NAME, HOOK_VERSION, DEPRECATION_TAG, \
SHOULD_ABORT_ON_CONSUMED_EVENT, \ SHOULD_EXIT_IF_RESULT_NOT_OK, \
TMPL_PARAM_TYPE_LIST, TMPL_PARAM_LIST, TMPL_DUMMY_ARGS_LIST, \ TMPL_PARAM_TYPE_LIST, TMPL_PARAM_LIST, TMPL_DUMMY_ARGS_LIST, \
SIGNATURE, ARGS_LIST) __NL__ \ SIGNATURE, ARGS_LIST) __NL__ \
__NL__ \ __NL__ \

@ -78,7 +78,7 @@ class Hooks {
#define DEFINE_WEAK_HOOK_FUNCTION( \ #define DEFINE_WEAK_HOOK_FUNCTION( \
HOOK_NAME, HOOK_VERSION, DEPRECATION_TAG, \ HOOK_NAME, HOOK_VERSION, DEPRECATION_TAG, \
SHOULD_ABORT_ON_CONSUMED_EVENT, \ SHOULD_EXIT_IF_RESULT_NOT_OK, \
TMPL_PARAM_TYPE_LIST, TMPL_PARAM_LIST, TMPL_DUMMY_ARGS_LIST, \ TMPL_PARAM_TYPE_LIST, TMPL_PARAM_LIST, TMPL_DUMMY_ARGS_LIST, \
SIGNATURE, ARGS_LIST) __NL__ \ SIGNATURE, ARGS_LIST) __NL__ \
__NL__ \ __NL__ \

@ -80,7 +80,7 @@
#define _REGISTER_EVENT_HANDLER( \ #define _REGISTER_EVENT_HANDLER( \
HOOK_NAME, HOOK_VERSION, DEPRECATION_TAG, \ HOOK_NAME, HOOK_VERSION, DEPRECATION_TAG, \
SHOULD_ABORT_ON_CONSUMED_EVENT, \ SHOULD_EXIT_IF_RESULT_NOT_OK, \
TMPL_PARAM_TYPE_LIST, TMPL_PARAM_LIST, TMPL_DUMMY_ARGS_LIST, \ TMPL_PARAM_TYPE_LIST, TMPL_PARAM_LIST, TMPL_DUMMY_ARGS_LIST, \
SIGNATURE, ARGS_LIST) __NL__ \ SIGNATURE, ARGS_LIST) __NL__ \
__NL__ \ __NL__ \
@ -116,8 +116,8 @@
MAKE_TEMPLATE_SIGNATURE(UNWRAP TMPL_PARAM_TYPE_LIST) __NL__ \ MAKE_TEMPLATE_SIGNATURE(UNWRAP TMPL_PARAM_TYPE_LIST) __NL__ \
struct _NAME4(EventHandler_, HOOK_NAME, _v, HOOK_VERSION) { __NL__ \ struct _NAME4(EventHandler_, HOOK_NAME, _v, HOOK_VERSION) { __NL__ \
__NL__ \ __NL__ \
static bool shouldAbortOnConsumedEvent() { __NL__ \ static bool shouldExitIfResultNotOk() { __NL__ \
return SHOULD_ABORT_ON_CONSUMED_EVENT; __NL__ \ return SHOULD_EXIT_IF_RESULT_NOT_OK; __NL__ \
} __NL__ \ } __NL__ \
__NL__ \ __NL__ \
template<typename Plugin__, __NL__ \ template<typename Plugin__, __NL__ \
@ -166,8 +166,8 @@
__NL__ \ __NL__ \
result = EventHandler__::call(PLUGIN, hook_args...); __NL__ \ result = EventHandler__::call(PLUGIN, hook_args...); __NL__ \
__NL__ \ __NL__ \
if (EventHandler__::shouldAbortOnConsumedEvent() && __NL__ \ if (EventHandler__::shouldExitIfResultNotOk() && __NL__ \
result == kaleidoscope::EventHandlerResult::EVENT_CONSUMED) { __NL__ \ result != kaleidoscope::EventHandlerResult::OK) { __NL__ \
return result; __NL__ \ return result; __NL__ \
} __NL__ } __NL__

Loading…
Cancel
Save