diff options
author | Nicholas Tay <nick@windblume.net> | 2022-05-11 19:22:08 +1000 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-05-11 19:22:08 +1000 |
commit | 2fee408d6fe0964e245dc0bae90027baa13b159a (patch) | |
tree | 8ff7cd648f2e9331b6e86ac3dfeb7c4e07df8f99 /clak.c | |
parent | 6a1e6a7d6b6a3d987f2fccb3c06f4f5da071f504 (diff) | |
download | clak-2fee408d6fe0964e245dc0bae90027baa13b159a.tar.gz clak-2fee408d6fe0964e245dc0bae90027baa13b159a.tar.bz2 clak-2fee408d6fe0964e245dc0bae90027baa13b159a.zip |
Improve plugin loading architecture
This should be better, maybe the variable names could be better though.
Init is more extensible, we take in a 'board_data' struct on the plugin
end that has everything it needs (mainly function pointers for now).
Then, a 'board' struct is given back to the main Clak runtime, with
everything it needs to know (again, mainly function pointers).
It is a bit weird that the board is not stored with Clak but as a
pointer to the dynamically loaded bit, but not sure.
Diffstat (limited to 'clak.c')
-rw-r--r-- | clak.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -2,13 +2,15 @@ #include <unistd.h> #include <string.h> #include <stdlib.h> +#include <assert.h> -#include "clak.h" #include "platform/platform.h" #include "board/board.h" #define VOLUME 0.15 +struct board *board = NULL; + void do_exit(int code) { keyboard_unhook(); @@ -17,17 +19,16 @@ void do_exit(int code) } void on_clean_exit(void) { do_exit(0); } -fn_board_on_down board_on_down; -fn_board_on_up board_on_up; - void keyboard_on_down(void) { - board_on_down(); + assert(board != NULL); + board->on_down(); } void keyboard_on_up(void) { - board_on_up(); + assert(board != NULL); + board->on_up(); } int main(int argc, char **argv) @@ -39,10 +40,11 @@ int main(int argc, char **argv) // TODO: List valid boards. return 1; } - if (!load_board(argv[1], &board_on_down, &board_on_up)) { + if ((board = load_board(argv[1])) == NULL) { + printf("Failed to load board, exiting.\n"); return 1; } - fprintf(stderr, "Loaded board: %s\n", argv[1]); + fprintf(stderr, "Loaded board: %s\n", board->name); if (!sound_init(VOLUME)) { printf("ERROR: Could not initialise sound system.\n"); |