diff mbox

[42/58] vmstate: port stellaris gamepad

Message ID a769cdcd3c865270c62daf7b00f853f33614742d.1298569508.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Feb. 24, 2011, 5:57 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/stellaris_input.c |   50 ++++++++++++++++++++++++--------------------------
 1 files changed, 24 insertions(+), 26 deletions(-)

Comments

Blue Swirl Feb. 26, 2011, 10:56 a.m. UTC | #1
On Thu, Feb 24, 2011 at 7:57 PM, Juan Quintela <quintela@redhat.com> wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  hw/stellaris_input.c |   50 ++++++++++++++++++++++++--------------------------
>  1 files changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/hw/stellaris_input.c b/hw/stellaris_input.c
> index 16aae96..b5b3bd7 100644
> --- a/hw/stellaris_input.c
> +++ b/hw/stellaris_input.c
> @@ -13,7 +13,7 @@
>  typedef struct {
>     qemu_irq irq;
>     int keycode;
> -    int pressed;
> +    uint8_t pressed;
>  } gamepad_button;
>
>  typedef struct {
> @@ -47,30 +47,29 @@ static void stellaris_gamepad_put_key(void * opaque, int keycode)
>     s->extension = 0;
>  }
>
> -static void stellaris_gamepad_save(QEMUFile *f, void *opaque)
> -{
> -    gamepad_state *s = (gamepad_state *)opaque;
> -    int i;
> -
> -    qemu_put_be32(f, s->extension);
> -    for (i = 0; i < s->num_buttons; i++)
> -        qemu_put_byte(f, s->buttons[i].pressed);
> -}
> -
> -static int stellaris_gamepad_load(QEMUFile *f, void *opaque, int version_id)
> -{
> -    gamepad_state *s = (gamepad_state *)opaque;
> -    int i;
> -
> -    if (version_id != 1)
> -        return -EINVAL;
> -
> -    s->extension = qemu_get_be32(f);
> -    for (i = 0; i < s->num_buttons; i++)
> -        s->buttons[i].pressed = qemu_get_byte(f);
> +static const VMStateDescription vmstate_stellaris_button = {
> +    .name = "stellaris_button",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .minimum_version_id_old = 1,

For consistency with other structures, these version fields should be 0.
Juan Quintela Feb. 26, 2011, 2:12 p.m. UTC | #2
Blue Swirl <blauwirbel@gmail.com> wrote:
> On Thu, Feb 24, 2011 at 7:57 PM, Juan Quintela <quintela@redhat.com> wrote:
>> +static const VMStateDescription vmstate_stellaris_button = {
>> +    .name = "stellaris_button",
>> +    .version_id = 1,
>> +    .minimum_version_id = 1,
>> +    .minimum_version_id_old = 1,
>
> For consistency with other structures, these version fields should be 0.

From the part that you didn't posted.

@@ -86,6 +85,5 @@ void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
     }
     s->num_buttons = n;
     qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s);
-    register_savevm(NULL, "stellaris_gamepad", -1, 1,
-                    stellaris_gamepad_save, stellaris_gamepad_load, s);
+    vmstate_register(NULL, -1, &vmstate_stellaris_gamepad, s);
 }
Blue Swirl Feb. 26, 2011, 4:32 p.m. UTC | #3
On Sat, Feb 26, 2011 at 4:12 PM, Juan Quintela <quintela@redhat.com> wrote:
> Blue Swirl <blauwirbel@gmail.com> wrote:
>> On Thu, Feb 24, 2011 at 7:57 PM, Juan Quintela <quintela@redhat.com> wrote:
>>> +static const VMStateDescription vmstate_stellaris_button = {
>>> +    .name = "stellaris_button",
>>> +    .version_id = 1,
>>> +    .minimum_version_id = 1,
>>> +    .minimum_version_id_old = 1,
>>
>> For consistency with other structures, these version fields should be 0.
>
> From the part that you didn't posted.
>
> @@ -86,6 +85,5 @@ void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
>     }
>     s->num_buttons = n;
>     qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s);
> -    register_savevm(NULL, "stellaris_gamepad", -1, 1,
> -                    stellaris_gamepad_save, stellaris_gamepad_load, s);
> +    vmstate_register(NULL, -1, &vmstate_stellaris_gamepad, s);
>  }
> --
> 1.7.4
>
>
> Version is already at ' (4th argument of register_savevm).  I just used
> the version that was there.  I agree that some devices had started at
> version 0 and others at version 1, but that is independent of this series.

The patch introduces two VMState structures, main VMState for the
whole gamepad and a secondary VMState for button structures. The
version for main VMState is OK at 1, but I was talking about the
button substructure VMState version, which is 0 in other patches.
diff mbox

Patch

diff --git a/hw/stellaris_input.c b/hw/stellaris_input.c
index 16aae96..b5b3bd7 100644
--- a/hw/stellaris_input.c
+++ b/hw/stellaris_input.c
@@ -13,7 +13,7 @@ 
 typedef struct {
     qemu_irq irq;
     int keycode;
-    int pressed;
+    uint8_t pressed;
 } gamepad_button;

 typedef struct {
@@ -47,30 +47,29 @@  static void stellaris_gamepad_put_key(void * opaque, int keycode)
     s->extension = 0;
 }

-static void stellaris_gamepad_save(QEMUFile *f, void *opaque)
-{
-    gamepad_state *s = (gamepad_state *)opaque;
-    int i;
-
-    qemu_put_be32(f, s->extension);
-    for (i = 0; i < s->num_buttons; i++)
-        qemu_put_byte(f, s->buttons[i].pressed);
-}
-
-static int stellaris_gamepad_load(QEMUFile *f, void *opaque, int version_id)
-{
-    gamepad_state *s = (gamepad_state *)opaque;
-    int i;
-
-    if (version_id != 1)
-        return -EINVAL;
-
-    s->extension = qemu_get_be32(f);
-    for (i = 0; i < s->num_buttons; i++)
-        s->buttons[i].pressed = qemu_get_byte(f);
+static const VMStateDescription vmstate_stellaris_button = {
+    .name = "stellaris_button",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT8(pressed, gamepad_button),
+        VMSTATE_END_OF_LIST()
+    }
+};

-    return 0;
-}
+static const VMStateDescription vmstate_stellaris_gamepad = {
+    .name = "stellaris_gamepad",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_INT32(extension, gamepad_state),
+        VMSTATE_STRUCT_VARRAY_INT32(buttons, gamepad_state, num_buttons, 0,
+                              vmstate_stellaris_button, gamepad_button),
+        VMSTATE_END_OF_LIST()
+    }
+};

 /* Returns an array 5 ouput slots.  */
 void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
@@ -86,6 +85,5 @@  void stellaris_gamepad_init(int n, qemu_irq *irq, const int *keycode)
     }
     s->num_buttons = n;
     qemu_add_kbd_event_handler(stellaris_gamepad_put_key, s);
-    register_savevm(NULL, "stellaris_gamepad", -1, 1,
-                    stellaris_gamepad_save, stellaris_gamepad_load, s);
+    vmstate_register(NULL, -1, &vmstate_stellaris_gamepad, s);
 }