1 /* gom-resource.h
2  *
3  * Copyright (C) 2011 Christian Hergert <chris@dronelabs.com>
4  *
5  * This file is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This file is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef GOM_RESOURCE_H
20 #define GOM_RESOURCE_H
21 
22 #include <gio/gio.h>
23 
24 #include "gom-filter.h"
25 
26 G_BEGIN_DECLS
27 
28 #define GOM_TYPE_RESOURCE            (gom_resource_get_type())
29 #define GOM_RESOURCE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOM_TYPE_RESOURCE, GomResource))
30 #define GOM_RESOURCE_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOM_TYPE_RESOURCE, GomResource const))
31 #define GOM_RESOURCE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GOM_TYPE_RESOURCE, GomResourceClass))
32 #define GOM_IS_RESOURCE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOM_TYPE_RESOURCE))
33 #define GOM_IS_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GOM_TYPE_RESOURCE))
34 #define GOM_RESOURCE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GOM_TYPE_RESOURCE, GomResourceClass))
35 #define GOM_RESOURCE_NEW_IN_VERSION  (gom_resource_new_in_version_quark())
36 #define GOM_RESOURCE_NOT_MAPPED      (gom_resource_not_mapped_quark())
37 #define GOM_RESOURCE_TO_BYTES_FUNC   (gom_resource_to_bytes_func_quark())
38 #define GOM_RESOURCE_FROM_BYTES_FUNC (gom_resource_from_bytes_func_quark())
39 #define GOM_RESOURCE_REF_TABLE_CLASS (gom_resource_ref_table_class())
40 #define GOM_RESOURCE_REF_PROPERTY_NAME (gom_resource_ref_property_name())
41 #define GOM_RESOURCE_UNIQUE          (gom_resource_unique())
42 #define GOM_RESOURCE_NOTNULL         (gom_resource_notnull())
43 
44 typedef struct _GomResource        GomResource;
45 typedef struct _GomResourceClass   GomResourceClass;
46 typedef struct _GomResourcePrivate GomResourcePrivate;
47 
48 #include "gom-resource-group.h"
49 
50 struct _GomResource
51 {
52    GObject parent;
53 
54    /*< private >*/
55    GomResourcePrivate *priv;
56 };
57 
58 struct _GomResourceClass
59 {
60    GObjectClass parent_class;
61 
62    gchar primary_key[64];
63    gchar table[64];
64 };
65 
66 typedef GBytes * (*GomResourceToBytesFunc) (GValue *value);
67 typedef void (*GomResourceFromBytesFunc) (GBytes *bytes, GValue *value);
68 
69 GQuark            gom_resource_new_in_version_quark  (void) G_GNUC_CONST;
70 GQuark            gom_resource_not_mapped_quark      (void) G_GNUC_CONST;
71 GQuark            gom_resource_to_bytes_func_quark   (void) G_GNUC_CONST;
72 GQuark            gom_resource_from_bytes_func_quark (void) G_GNUC_CONST;
73 GQuark            gom_resource_ref_table_class       (void) G_GNUC_CONST;
74 GQuark            gom_resource_ref_property_name     (void) G_GNUC_CONST;
75 GQuark            gom_resource_unique                (void) G_GNUC_CONST;
76 GQuark            gom_resource_notnull               (void) G_GNUC_CONST;
77 GType             gom_resource_get_type              (void) G_GNUC_CONST;
78 
79 void              gom_resource_class_set_table       (GomResourceClass *resource_class,
80                                                       const gchar      *table);
81 void              gom_resource_class_set_primary_key (GomResourceClass *resource_class,
82                                                       const gchar      *primary_key);
83 void              gom_resource_class_set_property_new_in_version (GomResourceClass         *resource_class,
84                                                                   const gchar              *property_name,
85                                                                   guint                     version);
86 void              gom_resource_class_set_property_set_mapped     (GomResourceClass         *resource_class,
87                                                                   const gchar              *property_name,
88                                                                   gboolean                  is_mapped);
89 void              gom_resource_class_set_property_transform      (GomResourceClass         *resource_class,
90                                                                   const gchar              *property_name,
91                                                                   GomResourceToBytesFunc    to_bytes_func,
92                                                                   GomResourceFromBytesFunc  from_bytes_func);
93 void              gom_resource_class_set_property_to_bytes       (GomResourceClass         *resource_class,
94                                                                   const gchar              *property_name,
95                                                                   GomResourceToBytesFunc    to_bytes_func,
96                                                                   GDestroyNotify            notify);
97 void              gom_resource_class_set_property_from_bytes     (GomResourceClass         *resource_class,
98                                                                   const gchar              *property_name,
99                                                                   GomResourceFromBytesFunc  from_bytes_func,
100                                                                   GDestroyNotify            notify);
101 void              gom_resource_class_set_reference               (GomResourceClass         *resource_class,
102                                                                   const gchar              *property_name,
103                                                                   const gchar              *ref_table_name,
104                                                                   const gchar              *ref_property_name);
105 void              gom_resource_class_set_unique                  (GomResourceClass         *resource_class,
106                                                                   const gchar              *property_name);
107 void              gom_resource_class_set_notnull                 (GomResourceClass         *resource_class,
108                                                                   const gchar              *property_name);
109 
110 void              gom_resource_delete_async          (GomResource          *resource,
111                                                       GAsyncReadyCallback   callback,
112                                                       gpointer              user_data);
113 gboolean          gom_resource_delete_finish         (GomResource          *resource,
114                                                       GAsyncResult         *result,
115                                                       GError              **error);
116 gboolean          gom_resource_delete_sync           (GomResource          *resource,
117                                                       GError              **error);
118 void              gom_resource_save_async            (GomResource          *resource,
119                                                       GAsyncReadyCallback   callback,
120                                                       gpointer              user_data);
121 gboolean          gom_resource_save_finish           (GomResource          *resource,
122                                                       GAsyncResult         *result,
123                                                       GError              **error);
124 gboolean          gom_resource_save_sync             (GomResource          *resource,
125                                                       GError              **error);
126 void              gom_resource_fetch_m2m_async       (GomResource          *resource,
127                                                       GType                 resource_type,
128                                                       const gchar          *m2m_table,
129                                                       GomFilter            *filter,
130                                                       GAsyncReadyCallback   callback,
131                                                       gpointer              user_data);
132 GomResourceGroup *gom_resource_fetch_m2m_finish      (GomResource          *resource,
133                                                       GAsyncResult         *result,
134                                                       GError              **error);
135 
136 G_END_DECLS
137 
138 #endif /* GOM_RESOURCE_H */
139