Skip to content

Commit

Permalink
Merge pull request #354 from keyboardio/f/v1-plugin-api-removal
Browse files Browse the repository at this point in the history
Drop the V1 Plugin API
  • Loading branch information
algernon committed Aug 20, 2018
2 parents 526b0e4 + 297dab5 commit 568355b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 303 deletions.
8 changes: 4 additions & 4 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ If any of this does not make sense to you, or you have trouble updating your
.ino sketch, do not hesitate to write us at help@keyboard.io, we can help you
fix it.

### Scheduled for removal by 2018-08-20
Deprecated and removed APIs
---------------------------

### Removed on 2018-08-20

We aim at making a new release by mid-July, and APIs we deprecate now, will be
removed shortly after the major release, before the next point release. We may
Expand Down Expand Up @@ -145,9 +148,6 @@ Plugins are supposed to implement this new API, and then be initialised via
A key with a typo in its name, which was left in place after fixing the typo, so
as to not break any code that may be using it already, however unlikely.

Deprecated and removed APIs
---------------------------

### Removed on 2018-06-10 (originally scheduled for 2018-05-27)

These APIs and functions have been deprecated for a long time, and as far as we
Expand Down
79 changes: 0 additions & 79 deletions src/Kaleidoscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

namespace kaleidoscope {

#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
Kaleidoscope_::eventHandlerHook Kaleidoscope_::eventHandlers[HOOK_MAX];
Kaleidoscope_::loopHook Kaleidoscope_::loopHooks[HOOK_MAX];
#endif

uint32_t Kaleidoscope_::millis_at_cycle_start_;

Kaleidoscope_::Kaleidoscope_(void) {
Expand Down Expand Up @@ -47,23 +42,9 @@ Kaleidoscope_::loop(void) {

kaleidoscope::Hooks::beforeReportingState();

#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
loopHook hook = loopHooks[i];
(*hook)(false);
}
#endif

kaleidoscope::hid::sendKeyboardReport();
kaleidoscope::hid::releaseAllKeys();

#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
loopHook hook = loopHooks[i];
(*hook)(true);
}
#endif

kaleidoscope::Hooks::afterEachCycle();
}

Expand Down Expand Up @@ -110,64 +91,4 @@ Kaleidoscope_::focusHook(const char *command) {

Kaleidoscope_ Kaleidoscope;

/* Deprecated functions */

/* Disable deprecation warnings for these, we only want to have those at
* non-internal call sites. */

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void
Kaleidoscope_::replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook) {
for (byte i = 0; i < HOOK_MAX; i++) {
if (eventHandlers[i] == oldHook) {
eventHandlers[i] = newHook;
return;
}
}
}

void
Kaleidoscope_::appendEventHandlerHook(eventHandlerHook hook) {
replaceEventHandlerHook((eventHandlerHook)NULL, hook);
}

void
Kaleidoscope_::useEventHandlerHook(eventHandlerHook hook) {
for (byte i = 0; i < HOOK_MAX; i++) {
if (eventHandlers[i] == hook)
return;
}
appendEventHandlerHook(hook);
}

void
Kaleidoscope_::replaceLoopHook(loopHook oldHook, loopHook newHook) {
for (byte i = 0; i < HOOK_MAX; i++) {
if (loopHooks[i] == oldHook) {
loopHooks[i] = newHook;
return;
}
}
}

void
Kaleidoscope_::appendLoopHook(loopHook hook) {
replaceLoopHook((loopHook)NULL, hook);
}

void
Kaleidoscope_::useLoopHook(loopHook hook) {
for (byte i = 0; i < HOOK_MAX; i++) {
if (loopHooks[i] == hook)
return;
}
appendLoopHook(hook);
}
#endif

#pragma GCC diagnostic pop // restore diagnostic options

} // namespace kaleidoscope
77 changes: 0 additions & 77 deletions src/Kaleidoscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void setup();
#include "layers.h"
#include "macro_map.h"
#include "kaleidoscope_internal/event_dispatch.h"
#include "kaleidoscope_internal/deprecations.h"
#include "macro_helpers.h"
#include "plugin.h"

Expand Down Expand Up @@ -109,82 +108,6 @@ class Kaleidoscope_ {
return millis_at_cycle_start_;
}

// ---- Kaleidoscope.use() ----

#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
// First, we have the zero-argument version, which will satisfy the tail case.
inline void use() {
}

// Then, the one-argument version, that gives us type safety for a single
// plugin.
inline void DEPRECATED(USE) use(kaleidoscope::Plugin *p) {
p->begin();
}

// We have a no-op with a int argument, as a temporary hack until we remove
// the last instance of a NULL-terminated Kaleidoscope.use() call.
inline void use(int) {
}

// And the magic is in the last one, a template. The first parameter is
// matched out by the compiler, and passed to one of the functions above. The
// rest of the parameter pack (which may be an empty set in a recursive case),
// are passed back to either ourselves, or the zero-argument version a few
// lines above.
template <typename... Plugins>
void DEPRECATED(USE) use(kaleidoscope::Plugin *first, Plugins&&... plugins) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
use(first);
use(plugins...);
#pragma GCC diagnostic pop
}
#else
// NOTE: Do **NOT** remove this when sunsetting the V1 API!
template <typename Plugin__>
inline void use(Plugin__ first, ...) {
static_assert(sizeof(Plugin__) < 0, _DEPRECATE(_DEPRECATED_MESSAGE_USE));
}
#endif

// ---- hooks ----

/*
* In most cases, one only wants a single copy of a hook. On the other hand,
* plugins that depend on other plugins, may want to make it easier for the
* end-user to use the plugin, and call the setup function of the dependent
* plugins too. In case the end-user calls the same setup function, we'd end up
* with hooks registered multiple times.
*
* To avoid this, protection against double-registration has been introduced.
* The `event_handler_hook_use` and `loop_hook_use` functions will only allow
* one copy of the hook. The `event_handler_hook_append` and `loop_hook_append`
* functions will, on the other hand, just append the hooks, and not care about
* protection.
*/
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
typedef Key(*eventHandlerHook)(Key mappedKey, byte row, byte col, uint8_t keyState);
typedef void (*loopHook)(bool postClear);

static eventHandlerHook eventHandlers[HOOK_MAX];
static loopHook loopHooks[HOOK_MAX];

static void replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook)
DEPRECATED(EVENT_HANDLER_HOOK);
static void appendEventHandlerHook(eventHandlerHook hook)
DEPRECATED(EVENT_HANDLER_HOOK);
static void useEventHandlerHook(eventHandlerHook hook)
DEPRECATED(EVENT_HANDLER_HOOK);

static void replaceLoopHook(loopHook oldHook, loopHook newHook)
DEPRECATED(LOOP_HOOK);
static void appendLoopHook(loopHook hook)
DEPRECATED(LOOP_HOOK);
static void useLoopHook(loopHook hook)
DEPRECATED(LOOP_HOOK);
#endif

static bool focusHook(const char *command);

private:
Expand Down
56 changes: 0 additions & 56 deletions src/kaleidoscope_internal/deprecations.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,3 @@
"------------------------------------------------------------------------\n" \

/* Messages */

#define _DEPRECATED_MESSAGE_USE \
"Your sketch uses Kaleidoscope.use(), an old-style API to initialize\n" \
"plugins. To fix this, you need to modify your .ino sketch file, and\n" \
"replacing the text \"Kaleidoscope.use\" with \"KALEIDOSCOPE_INIT_PLUGINS\",\n" \
"then remove the & from all of the plugins inside it, and finally, move\n" \
"it outside of \"setup()\":\n" \
"\n" \
"If your current sketch looks like this: \n" \
" void setup() {\n" \
" Kaleidoscope.use(&Plugin1, &Plugin2);\n" \
" Kaleidoscope.setup();\n" \
" }\n" \
"\n" \
"You should change it so that it looks like this:\n" \
" KALEIDOSCOPE_INIT_PLUGINS(Plugin1, Plugin2);\n" \
" void setup() {\n" \
" Kaleidoscope.setup();\n" \
" }\n" \
"\n" \
"If this error doesn't make sense to you or you have any trouble, please\n" \
"send a copy of your .ino sketch file to help@keyboard.io and we can\n" \
"help fix it."

#define _DEPRECATED_MESSAGE_EVENT_HANDLER_HOOK \
"The legacy plugin API based on hook registration is deprecated.\n" \
"\n" \
"Consider upgrading your plugins, or implementing the new interface\n" \
"described by `kaleidoscope::Plugin`. In particular, instead of using\n" \
"`Kaleidoscope.useEventHandlerHook`, implement the\n" \
"`.onKeyswitchEvent()` method instead.\n" \
"\n" \
"If your plugins are up-to-date, and you are not a developer, it is\n" \
"usually safe to ignore this message. Especally if the full error\n" \
"points to a line containing `legacyLoopHook` or `legacyEventHandler`."


#define _DEPRECATED_MESSAGE_LOOP_HOOK \
"The legacy plugin API based on hook registration is deprecated.\n" \
"\n" \
"Consider upgrading your plugins, or implementing the new interface\n" \
"described by `kaleidoscope::Plugin`. In particular, instead of using\n" \
"`Kaleidoscope.useLoopHook`, implement `.beforeEachCycle`,\n" \
"`.beforeReportingState()`, or `.afterEachCycle()` instead.\n" \
"\n" \
"If your plugins are up-to-date, and you are not a developer, it is\n" \
"usually safe to ignore this message. Especally if the full error\n" \
"points to a line containing `legacyLoopHook` or `legacyEventHandler`."


#define _DEPRECATED_MESSAGE_USE_INSTEAD(new_method) \
"Please use `" new_method "` instead."

#define _DEPRECATED_MESSAGE_KALEIDOSCOPEPLUGIN \
"The `KaleidoscopePlugin` class is deprecated. Please derive plugins from\n" \
"`kaleidoscope::Plugin` instead."
1 change: 0 additions & 1 deletion src/key_defs_consumerctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#define Consumer_VCRSlashTV CONSUMER_KEY(HID_CONSUMER_VCR_SLASH_TV, KEY_FLAGS | HID_TYPE_OOC )
#define Consumer_BroadcastMode CONSUMER_KEY(HID_CONSUMER_BROADCAST_MODE, KEY_FLAGS | HID_TYPE_OSC )
#define Consumer_Snapshot CONSUMER_KEY(HID_CONSUMER_SNAPSHOT, KEY_FLAGS | HID_TYPE_OSC )
#define Consumer_SNapshot Consumer_Snapshot
#define Consumer_Still CONSUMER_KEY(HID_CONSUMER_STILL, KEY_FLAGS | HID_TYPE_OSC )

#define Consumer_Selection CONSUMER_KEY(HID_CONSUMER_SELECTION, KEY_FLAGS | HID_TYPE_NARY )
Expand Down
11 changes: 0 additions & 11 deletions src/key_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,7 @@ void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {

// Keypresses with out-of-bounds (row,col) start here in the processing chain

// Legacy event handlers
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i];
mappedKey = (*handler)(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
}
#endif

// New event handler interface
//
if (kaleidoscope::Hooks::onKeyswitchEvent(mappedKey, row, col, keyState) != kaleidoscope::EventHandlerResult::OK)
return;

Expand Down
Loading

0 comments on commit 568355b

Please sign in to comment.