From: Justin Wind Date: Sun, 20 May 2012 21:57:35 +0000 (-0700) Subject: finished reorg of abstracted module interfaces X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=d3c579a9b588b7f94fca88474ab2bd010f67a22f;p=dcpu16 finished reorg of abstracted module interfaces all hw modules now controllable via single generic ctl function. --- diff --git a/hw_keyboard.c b/hw_keyboard.c index 592b673..7192efd 100644 --- a/hw_keyboard.c +++ b/hw_keyboard.c @@ -91,11 +91,6 @@ void keyboard_rfbevent_(rfbBool down, rfbKeySym key, rfbClientPtr cl) { dcpu16_interrupt(hw->vm, keyboard->interrupt_message); } } - -void keyboard_vnc_associate(struct dcpu16_hw *hw, rfbScreenInfoPtr rfbScreen) { - rfbScreen->screenData = hw; - rfbScreen->kbdAddEvent = keyboard_rfbevent_; -} #endif /* HAVE_LIBVNCSERVER */ static diff --git a/hw_lem1802.c b/hw_lem1802.c index 06b0d5a..0c70754 100644 --- a/hw_lem1802.c +++ b/hw_lem1802.c @@ -319,7 +319,8 @@ f_done: #ifdef HAVE_LIBVNCSERVER /* create and return a new screen, easiest to do here because we know the screen dimensions */ -rfbScreenInfoPtr lem1802_rfb_new(int argc, char *argv[]) { +static +rfbScreenInfoPtr lem1802_rfb_new_(int argc, char *argv[]) { rfbScreenInfoPtr s; int paddedWidth = PIX_X + ( (PIX_X & 3) ? (4 - (PIX_X & 3)) : 0 ); int height = PIX_Y; @@ -509,8 +510,8 @@ static struct renderer_ { { NULL, NULL, NULL } }; - -char *lem1802_renderers_iter(void **iterp, char **name, char **args) { +static +char *lem1802_renderers_iter_(void **iterp, char **name, char **args) { struct renderer_ **r = (struct renderer_ **)iterp; if (*r == NULL) @@ -529,6 +530,7 @@ char *lem1802_renderers_iter(void **iterp, char **name, char **args) { return (*r)->name; } +static int lem1802_data_init_(struct dcpu16_hw *hw, void *data) { (void)data; @@ -552,6 +554,7 @@ int lem1802_data_init_(struct dcpu16_hw *hw, void *data) { return 0; } +static void lem1802_data_free_(struct dcpu16_hw *hw) { if (hw) { if (hw->data) { @@ -566,15 +569,19 @@ void lem1802_data_free_(struct dcpu16_hw *hw) { } static struct dcpu16_hw_ctl_cmd ctl_[] = { - { "blink_rate", "const unsigned int *rate", "unsigned int *rate", "sets or gets cycles per blink toggle" }, - { "refresh_rate", "const unsigned int *rate", "unsigned int *rate", "sets or gets cycles per screen refresh" }, + { "blink_rate", "const unsigned int *", "unsigned int *", "sets or gets cycles per blink toggle" }, + { "refresh_rate", "const unsigned int *", "unsigned int *", "sets or gets cycles per screen refresh" }, #ifdef HAVE_LIBVNCSERVER + { "new_rfbScreen", "struct { int argc; char **argv;} *", "rfbScreenInfoPtr *", "allocates a new rfb screen" }, { "associate_rfbScreen", "rfbScreenInfoPtr", "NULL", "associates this lem1802 instance with an rfb display" }, #endif /* HAVE_LIBVNCSERVER */ + { "renderers_iter", "void **", "struct {char *name; char *args;} *", "returns the next renderer this module is capable of using" }, { "renderer", "const char *", "NULL", "sets this lem1802 instance to use renderer" }, { "renderer_data", "void *", "NULL", "sets renderer-specific data" }, { NULL, NULL, NULL, NULL } }; + +static int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void *data_out) { if (strcmp(cmd, "blink_rate") == 0) { struct lem1802_ *display = (struct lem1802_ *)hw->data; @@ -609,10 +616,22 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void } #ifdef HAVE_LIBVNCSERVER + if (strcmp(cmd, "new_rfbScreen") == 0) { + struct args_ { int argc; char **argv;} *in = (struct args_ *)data_in; + rfbScreenInfoPtr *s_out = (rfbScreenInfoPtr *)data_out; + + if (in == NULL || s_out == NULL) + return -EFAULT; + + *s_out = lem1802_rfb_new_(in->argc, in->argv); + + return 0; + } + if (strcmp(cmd, "associate_rfbScreen") == 0) { struct lem1802_ *display = (struct lem1802_ *)hw->data; - rfbScreenInfoPtr rfbScreen = (rfbScreenInfoPtr)data_out; - (void)data_in; + rfbScreenInfoPtr rfbScreen = (rfbScreenInfoPtr)data_in; + (void)data_out; if (rfbScreen == NULL) return -EFAULT; @@ -624,6 +643,21 @@ int lem1802_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void } #endif /* HAVE_LIBVNCSERVER */ + if (strcmp(cmd, "renderers_iter") == 0) { + void **iterp = (void **)data_in; + struct packed_out_ { + char *name; + char *args; + } *parg = (struct packed_out_ *)data_out; + + if (iterp == NULL || parg == NULL) + return -EFAULT; + + (void)lem1802_renderers_iter_(iterp, &parg->name, &parg->args); + + return 0; + } + if (strcmp(cmd, "renderer") == 0) { struct lem1802_ *display = (struct lem1802_ *)hw->data; char *renderer = (char *)data_in; diff --git a/hw_lem1802.h b/hw_lem1802.h index 38ffbb0..1c4f24b 100644 --- a/hw_lem1802.h +++ b/hw_lem1802.h @@ -1,18 +1,8 @@ #ifndef LEM1802_H_WH5E5NOE #define LEM1802_H_WH5E5NOE -#ifdef HAVE_LIBVNCSERVER -#include "rfb/rfb.h" -#endif /* HAVE_LIBVNCSERVER */ - #include "dcpu16.h" extern struct dcpu16_hw_module dcpu16_hw_module_lem1802; -char *lem1802_renderers_iter(void **, char **, char **); - -#ifdef HAVE_LIBVNCSERVER -rfbScreenInfoPtr lem1802_rfb_new(int argc, char *argv[]); -#endif /* HAVE_LIBVNCSERVER */ - #endif /* LEM1802_H_WH5E5NOE */ diff --git a/vm-dcpu16.c b/vm-dcpu16.c index a6dc67d..86f773a 100644 --- a/vm-dcpu16.c +++ b/vm-dcpu16.c @@ -151,7 +151,7 @@ int file_load_(struct dcpu16 *vm, char *filename, DCPU16_WORD addr) { #ifdef HAVE_LIBVNCSERVER static struct dynamic_array rfbScreens_; -/* wups, kbdAddEvent isn't null by default, so I guess track things externally */ +/* wups, kbdAddEvent isn't null by default, so I guess track associations externally */ struct rfb_instance_ { rfbScreenInfoPtr screen; struct dcpu16_hw *attached_display; @@ -163,6 +163,10 @@ static struct rfb_instance_ *rfbScreen_next_available_display_(struct dynamic_array *rfbScreens, int argc, char *argv[]) { size_t i; struct rfb_instance_ new_instance, *s; + struct packed_args_ { + int argc; + char **argv; + } parg = { argc, argv }; fprintf(stderr, "DEBUG: rfbScreens->entries:%zu\n", rfbScreens->entries); @@ -172,7 +176,11 @@ struct rfb_instance_ *rfbScreen_next_available_display_(struct dynamic_array *rf return s; } - new_instance.screen = lem1802_rfb_new(argc, argv); + if (dcpu16_hw_module_lem1802.ctl(NULL, "new_rfbScreen", &parg, &new_instance.screen)) { + fprintf(stderr, "failed to allocate new rfbScreen"); + return NULL; + } + new_instance.attached_display = NULL; new_instance.attached_keyboard = NULL; s = dynarray_add(rfbScreens, &new_instance); @@ -184,6 +192,10 @@ static struct rfb_instance_ *rfbScreen_next_available_keyboard_(struct dynamic_array *rfbScreens, int argc, char *argv[]) { size_t i; struct rfb_instance_ new_instance, *s; + struct packed_args_ { + int argc; + char **argv; + } parg = { argc, argv }; for (i = 0; i < rfbScreens->entries; i++) { s = (struct rfb_instance_ *)DYNARRAY_ITEM(*rfbScreens, i); @@ -191,7 +203,11 @@ struct rfb_instance_ *rfbScreen_next_available_keyboard_(struct dynamic_array *r return s; } - new_instance.screen = lem1802_rfb_new(argc, argv); + if (dcpu16_hw_module_lem1802.ctl(NULL, "new_rfbScreen", &parg, &new_instance.screen)) { + fprintf(stderr, "failed to allocate new rfbScreen"); + return NULL; + } + new_instance.attached_display = NULL; new_instance.attached_keyboard = NULL; s = dynarray_add(rfbScreens, &new_instance); @@ -590,9 +606,7 @@ COMMAND_HELP(display) { struct renderer_ { char *name; char *args; - int (*renderer)(void *, void *, size_t, size_t); - } *r; - char *name, *args; + } renderer; void *iter; fprintf(f, "\tdisplay renderer [renderer data]\n"); @@ -603,19 +617,17 @@ COMMAND_HELP(display) { fprintf(f, "Supported renderers:\n"); - if (dcpu16_hw_module_lem1802.ctl(NULL, "get_renderers", NULL, &r)) { - fprintf(stderr, "error fetching list of renderers\n"); - return; - } - - while (r->name) { - fprintf(f, "name:%s args:%s\n", r->name, r->args); - } - iter = NULL; - while ( (lem1802_renderers_iter(&iter, &name, &args)) ) { - fprintf(f, "\t%s %s\n", name, args); - } + do { + if (dcpu16_hw_module_lem1802.ctl(NULL, "renderers_iter", &iter, &renderer)) { + fprintf(stderr, "error fetching next renderer\n"); + break; + } + if (iter == NULL || renderer.name == NULL) + break; + + fprintf(f, "\t%s %s\n", renderer.name, renderer.args); + } while (iter); } COMMAND_IMPL(keyboard) {