[gom] gom: Add to/from bytes metadata properties
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] gom: Add to/from bytes metadata properties
- Date: Thu, 17 Apr 2014 07:25:10 +0000 (UTC)
commit 3506261a519a7519a55aae72625b04be559c32c1
Author: Bastien Nocera <hadess hadess net>
Date: Wed Apr 16 01:21:00 2014 +0200
gom: Add to/from bytes metadata properties
If a property is not a number or a string, we'll need help
serialising and deserialising it to a GBytes which we would fit
in a BLOB column.
gom/gom-resource.c | 31 +++++++++++++++++++++++++++++++
gom/gom-resource.h | 23 +++++++++++++++++------
2 files changed, 48 insertions(+), 6 deletions(-)
---
diff --git a/gom/gom-resource.c b/gom/gom-resource.c
index 43affe3..b032a05 100644
--- a/gom/gom-resource.c
+++ b/gom/gom-resource.c
@@ -86,6 +86,25 @@ gom_resource_class_set_property_set_mapped (GomResourceClass *resource_class,
}
void
+gom_resource_class_set_property_transform (GomResourceClass *resource_class,
+ const gchar *property_name,
+ GomResourceToBytesFunc to_bytes_func,
+ GomResourceFromBytesFunc from_bytes_func)
+{
+ GParamSpec *pspec;
+
+ g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
+ g_return_if_fail(to_bytes_func != NULL);
+ g_return_if_fail(from_bytes_func != NULL);
+
+ pspec = g_object_class_find_property(G_OBJECT_CLASS(resource_class), property_name);
+ g_assert(pspec);
+
+ g_param_spec_set_qdata(pspec, GOM_RESOURCE_TO_BYTES_FUNC, to_bytes_func);
+ g_param_spec_set_qdata(pspec, GOM_RESOURCE_FROM_BYTES_FUNC, from_bytes_func);
+}
+
+void
gom_resource_class_set_table (GomResourceClass *resource_class,
const gchar *table)
{
@@ -852,3 +871,15 @@ gom_resource_not_mapped_quark (void)
{
return g_quark_from_static_string("gom_resource_not_mapped_quark");
}
+
+GQuark
+gom_resource_to_bytes_func_quark (void)
+{
+ return g_quark_from_static_string("gom_resource_to_bytes_func_quark");
+}
+
+GQuark
+gom_resource_from_bytes_func_quark (void)
+{
+ return g_quark_from_static_string("gom_resource_from_bytes_func_quark");
+}
diff --git a/gom/gom-resource.h b/gom/gom-resource.h
index 320f1d5..77ab73c 100644
--- a/gom/gom-resource.h
+++ b/gom/gom-resource.h
@@ -35,6 +35,8 @@ G_BEGIN_DECLS
#define GOM_RESOURCE_ERROR (gom_resource_error_quark())
#define GOM_RESOURCE_NEW_IN_VERSION (gom_resource_new_in_version_quark())
#define GOM_RESOURCE_NOT_MAPPED (gom_resource_not_mapped_quark())
+#define GOM_RESOURCE_TO_BYTES_FUNC (gom_resource_to_bytes_func_quark())
+#define GOM_RESOURCE_FROM_BYTES_FUNC (gom_resource_from_bytes_func_quark())
typedef struct _GomResource GomResource;
typedef struct _GomResourceClass GomResourceClass;
@@ -64,16 +66,23 @@ struct _GomResourceClass
gchar table[64];
};
+typedef GBytes * (*GomResourceToBytesFunc) (GValue *value);
+typedef void (*GomResourceFromBytesFunc) (GBytes *bytes, GValue *value);
+
void gom_resource_class_set_table (GomResourceClass *resource_class,
const gchar *table);
void gom_resource_class_set_primary_key (GomResourceClass *resource_class,
const gchar *primary_key);
-void gom_resource_class_set_property_new_in_version (GomResourceClass *resource_class,
- const gchar *property_name,
- guint version);
-void gom_resource_class_set_property_set_mapped (GomResourceClass *resource_class,
- const gchar *property_name,
- gboolean is_mapped);
+void gom_resource_class_set_property_new_in_version (GomResourceClass *resource_class,
+ const gchar *property_name,
+ guint version);
+void gom_resource_class_set_property_set_mapped (GomResourceClass *resource_class,
+ const gchar *property_name,
+ gboolean is_mapped);
+void gom_resource_class_set_property_transform (GomResourceClass *resource_class,
+ const gchar *property_name,
+ GomResourceToBytesFunc to_bytes_func,
+ GomResourceFromBytesFunc from_bytes_func);
void gom_resource_delete_async (GomResource *resource,
GAsyncReadyCallback callback,
@@ -86,6 +95,8 @@ gboolean gom_resource_delete_sync (GomResource *reso
GQuark gom_resource_error_quark (void) G_GNUC_CONST;
GQuark gom_resource_new_in_version_quark (void) G_GNUC_CONST;
GQuark gom_resource_not_mapped_quark (void) G_GNUC_CONST;
+GQuark gom_resource_to_bytes_func_quark (void) G_GNUC_CONST;
+GQuark gom_resource_from_bytes_func_quark (void) G_GNUC_CONST;
GType gom_resource_get_type (void) G_GNUC_CONST;
void gom_resource_save_async (GomResource *resource,
GAsyncReadyCallback callback,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]