aboutsummaryrefslogtreecommitdiff
path: root/qom/object.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2015-02-06 14:55:45 +1100
committerAlexander Graf <agraf@suse.de>2015-03-09 14:59:55 +0100
commit8e099d14f5233f330c4a6f03ff655219cd789c8f (patch)
tree355f72ea6b80b702f968c72677e36dcfa5bf967c /qom/object.c
parentb194df478ae7607d93b47a8307e623c9f9f2b3ab (diff)
Generalize QOM publishing of date and time from mc146818rtc.c
The mc146818rtc driver exposes the current RTC date and time via the "date" property in QOM (which is also aliased to the machine's "rtc-time" property). Currently it uses a custom visitor function rtc_get_date to do this. This patch introduces new helpers to the QOM core to expose struct tm valued properties via a getter function, so that this functionality can be more easily duplicated in other RTC implementations. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'qom/object.c')
-rw-r--r--qom/object.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/qom/object.c b/qom/object.c
index 1812c73327..d1670387b4 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1543,6 +1543,85 @@ void object_property_add_bool(Object *obj, const char *name,
}
}
+typedef struct TMProperty {
+ void (*get)(Object *, struct tm *, Error **);
+} TMProperty;
+
+static void property_get_tm(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ TMProperty *prop = opaque;
+ Error *err = NULL;
+ struct tm value;
+
+ prop->get(obj, &value, &err);
+ if (err) {
+ goto out;
+ }
+
+ visit_start_struct(v, NULL, "struct tm", name, 0, &err);
+ if (err) {
+ goto out;
+ }
+ visit_type_int32(v, &value.tm_year, "tm_year", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_mon, "tm_mon", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_mday, "tm_mday", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_hour, "tm_hour", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_min, "tm_min", &err);
+ if (err) {
+ goto out_end;
+ }
+ visit_type_int32(v, &value.tm_sec, "tm_sec", &err);
+ if (err) {
+ goto out_end;
+ }
+out_end:
+ error_propagate(errp, err);
+ err = NULL;
+ visit_end_struct(v, errp);
+out:
+ error_propagate(errp, err);
+
+}
+
+static void property_release_tm(Object *obj, const char *name,
+ void *opaque)
+{
+ TMProperty *prop = opaque;
+ g_free(prop);
+}
+
+void object_property_add_tm(Object *obj, const char *name,
+ void (*get)(Object *, struct tm *, Error **),
+ Error **errp)
+{
+ Error *local_err = NULL;
+ TMProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->get = get;
+
+ object_property_add(obj, name, "struct tm",
+ get ? property_get_tm : NULL, NULL,
+ property_release_tm,
+ prop, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ g_free(prop);
+ }
+}
+
static char *qdev_get_type(Object *obj, Error **errp)
{
return g_strdup(object_get_typename(obj));