+static struct dcpu16_hw_ctl_cmd ctl_[] = {
+ { "buffer_size", "const size_t *", "size_t *", "get or set current buffer size" },
+ { "associate_rfbScreen", "rfbScreenInfoPtr", "NULL", "associates this keyboard instance with an rfb display" },
+ { NULL, NULL, NULL, NULL }
+};
+static
+int keyboard_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void *data_out) {
+ if (strcmp(cmd, "buffer_size") == 0) {
+ struct keyboard_ *keyboard = (struct keyboard_ *)hw->data;
+ void *tmp_ptr;
+ const size_t *buf_sz_in = (const size_t *)data_in;
+ size_t *buf_sz_out = (size_t *)data_out;
+
+ if (buf_sz_out) {
+ *buf_sz_out = keyboard->buf_sz;
+ }
+
+ if (buf_sz_in) {
+ MSG_DEBUG(hw->vm, "%s>> resizing buffer from %zu to %zu", __func__, keyboard->buf_sz, *buf_sz_in);
+
+ tmp_ptr = realloc(keyboard->buf, *buf_sz_in);
+ if (tmp_ptr == NULL) {
+ MSG_ERROR(hw->vm, "%s():%s", "realloc", strerror(errno));
+ return -1;
+ }
+ keyboard->buf = tmp_ptr;
+ keyboard->buf_sz = *buf_sz_in;
+ keyboard->buf_head = keyboard->buf_tail = 0;
+ }
+
+ MSG_DEBUG(hw->vm, "%s>> %s now:%zu was:%zu", __func__, "buffer_size", *buf_sz_in, *buf_sz_out);
+
+ return 0;
+ }