From 6d298a977a906aa9029b8f82b19fae71562db5fe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Feb 2011 17:15:14 -0600 Subject: Create an entry structure and functions for creating and destroying it --- libdbusmenu-glib/defaults.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'libdbusmenu-glib/defaults.c') diff --git a/libdbusmenu-glib/defaults.c b/libdbusmenu-glib/defaults.c index c225612..3a98923 100644 --- a/libdbusmenu-glib/defaults.c +++ b/libdbusmenu-glib/defaults.c @@ -40,6 +40,12 @@ struct _DbusmenuDefaultsPrivate { GHashTable * types; }; +typedef struct _DefaultEntry DefaultEntry; +struct _DefaultEntry { + GVariantType * type; + GVariant * value; +}; + #define DBUSMENU_DEFAULTS_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_DEFAULTS_TYPE, DbusmenuDefaultsPrivate)) @@ -48,6 +54,9 @@ static void dbusmenu_defaults_init (DbusmenuDefaults *self); static void dbusmenu_defaults_dispose (GObject *object); static void dbusmenu_defaults_finalize (GObject *object); +static DefaultEntry * entry_create (GVariantType * type, GVariant * variant); +static void entry_destroy (gpointer entry); + G_DEFINE_TYPE (DbusmenuDefaults, dbusmenu_defaults, G_TYPE_OBJECT); static void @@ -98,6 +107,44 @@ dbusmenu_defaults_finalize (GObject *object) return; } +/* Create a new entry based on the info provided */ +static DefaultEntry * +entry_create (GVariantType * type, GVariant * variant) +{ + DefaultEntry * defentry = g_new0(DefaultEntry, 1); + + if (type != NULL) { + defentry->type = g_variant_type_copy(type); + } + + if (variant != NULL) { + defentry->value = variant; + g_variant_ref_sink(variant); + } + + return defentry; +} + +/* Destroy an entry */ +static void +entry_destroy (gpointer entry) +{ + DefaultEntry * defentry = (DefaultEntry *)entry; + + if (defentry->type != NULL) { + g_variant_type_free(defentry->type); + defentry->type = NULL; + } + + if (defentry->value != NULL) { + g_variant_unref(defentry->value); + defentry->value = NULL; + } + + g_free(defentry); + return; +} + static DbusmenuDefaults * default_defaults = NULL; /** -- cgit v1.2.3