Patchwork [07/17] qapi: add open-coded visitors for QEMUTimer/struct tm types

login
register
mail settings
Submitter Michael Roth
Date June 5, 2012, 1 a.m.
Message ID <1338858018-17189-8-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/162988/
State New
Headers show

Comments

Michael Roth - June 5, 2012, 1 a.m.
These are common types that don't lend themselves to script-generated
visitors and require special handling. These will be useful for device
state serialization.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qapi/misc-qapi-visit.c |   35 +++++++++++++++++++++++++++++++++++
 qapi/qc.h              |    7 +++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
 create mode 100644 qapi/misc-qapi-visit.c

Patch

diff --git a/qapi/misc-qapi-visit.c b/qapi/misc-qapi-visit.c
new file mode 100644
index 0000000..fedc063
--- /dev/null
+++ b/qapi/misc-qapi-visit.c
@@ -0,0 +1,35 @@ 
+#include <time.h>
+#include "qapi-visit-core.h"
+#include "qc.h"
+#include "qemu-timer.h"
+
+void visit_type_tm(Visitor *v, struct tm *obj, const char *name, Error **errp)
+{
+    visit_start_struct(v, NULL, "struct tm", name, 0, errp);
+    visit_type_int32(v, &obj->tm_year, "tm_year", errp);
+    visit_type_int32(v, &obj->tm_mon, "tm_mon", errp);
+    visit_type_int32(v, &obj->tm_mday, "tm_mday", errp);
+    visit_type_int32(v, &obj->tm_hour, "tm_hour", errp);
+    visit_type_int32(v, &obj->tm_min, "tm_min", errp);
+    visit_type_int32(v, &obj->tm_sec, "tm_sec", errp);
+    visit_end_struct(v, errp);
+}
+
+void visit_type_QEMUTimer(Visitor *v, QEMUTimer **obj, const char *name,
+                          Error **errp)
+{
+    int64_t expire_time, expire_time_cpy;
+    expire_time = expire_time_cpy = qemu_timer_expire_time_ns(*obj);
+    visit_start_struct(v, NULL, "QEMUTimer", name, 0, errp);
+    visit_type_int64(v, &expire_time, "expire_time", errp);
+    visit_end_struct(v, errp);
+
+    /* if we're modifying a QEMUTimer, re-arm/delete accordingly */
+    if (expire_time != expire_time_cpy) {
+        if (expire_time != -1) {
+            qemu_mod_timer_ns(*obj, expire_time);
+        } else {
+            qemu_del_timer(*obj);
+        }
+    }
+}
diff --git a/qapi/qc.h b/qapi/qc.h
index 3b3a8b9..cf12c07 100644
--- a/qapi/qc.h
+++ b/qapi/qc.h
@@ -1,6 +1,8 @@ 
 #ifndef QC_H
 #define QC_H
 
+#include "qemu-timer.h"
+
 #define qc_declaration
 #define _immutable
 #define _derived
@@ -8,4 +10,9 @@ 
 #define _version(x)
 #define _size_is(x)
 
+/* misc. visitors */
+void visit_type_tm(Visitor *m, struct tm *obj, const char *name, Error **errp);
+void visit_type_QEMUTimer(Visitor *v, QEMUTimer **obj, const char *name,
+                          Error **errp);
+
 #endif