aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-03-30 00:29:31 -0700
committerDan Williams <dcbw@redhat.com>2010-03-30 00:29:31 -0700
commitcff40ac4724780e73f47af4f17cba952ab1ed680 (patch)
tree6d4391384fb616aa8e9885d2d6bc4cf34b1dd98f
parent71c6fa79f77a5475d03e276ddd782decf1f00fa4 (diff)
qcdm: allow result objects to hold boxed types
-rw-r--r--libqcdm/src/result-private.h10
-rw-r--r--libqcdm/src/result.c44
2 files changed, 53 insertions, 1 deletions
diff --git a/libqcdm/src/result-private.h b/libqcdm/src/result-private.h
index 2a5fd5db..0db63f5e 100644
--- a/libqcdm/src/result-private.h
+++ b/libqcdm/src/result-private.h
@@ -19,6 +19,7 @@
#define LIBQCDM_RESULT_PRIVATE_H
#include <glib.h>
+#include <glib-object.h>
#include "result.h"
QCDMResult *qcdm_result_new (void);
@@ -37,5 +38,14 @@ void qcdm_result_add_uint32 (QCDMResult *result,
const char *key,
guint32 num);
+void qcdm_result_add_boxed (QCDMResult *result,
+ const char *key,
+ GType btype,
+ gpointer boxed);
+
+gboolean qcdm_result_get_boxed (QCDMResult *result,
+ const char *key,
+ gpointer *out_val);
+
#endif /* LIBQCDM_RESULT_PRIVATE_H */
diff --git a/libqcdm/src/result.c b/libqcdm/src/result.c
index 37898f39..2440478e 100644
--- a/libqcdm/src/result.c
+++ b/libqcdm/src/result.c
@@ -75,7 +75,6 @@ qcdm_result_unref (QCDMResult *result)
}
}
-
void
qcdm_result_add_string (QCDMResult *result,
const char *key,
@@ -204,3 +203,46 @@ qcdm_result_get_uint32 (QCDMResult *result,
return TRUE;
}
+void
+qcdm_result_add_boxed (QCDMResult *result,
+ const char *key,
+ GType btype,
+ gpointer boxed)
+{
+ GValue *val;
+
+ g_return_if_fail (result != NULL);
+ g_return_if_fail (result->refcount > 0);
+ g_return_if_fail (key != NULL);
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, btype);
+ g_value_set_static_boxed (val, boxed);
+
+ g_hash_table_insert (result->hash, (gpointer) key, val);
+}
+
+gboolean
+qcdm_result_get_boxed (QCDMResult *result,
+ const char *key,
+ gpointer *out_val)
+{
+ GValue *val;
+
+ g_return_val_if_fail (result != NULL, FALSE);
+ g_return_val_if_fail (result->refcount > 0, FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+ g_return_val_if_fail (out_val != NULL, FALSE);
+
+ val = g_hash_table_lookup (result->hash, key);
+ if (!val)
+ return FALSE;
+
+ g_warn_if_fail (G_VALUE_HOLDS_BOXED (val));
+ if (!G_VALUE_HOLDS_BOXED (val))
+ return FALSE;
+
+ *out_val = g_value_get_boxed (val);
+ return TRUE;
+}
+