]> git.draconx.ca Git - upkg.git/commitdiff
uobject: Make interface functions take UObjects directly.
authorNick Bowler <nbowler@draconx.ca>
Mon, 28 Mar 2011 23:35:28 +0000 (19:35 -0400)
committerNick Bowler <nbowler@draconx.ca>
Mon, 28 Mar 2011 23:35:28 +0000 (19:35 -0400)
This makes implementing the functions a little cleaner.

src/engine/music.gob
src/uobject/exportable.c
src/uobject/exportable.h
src/uobject/loadable.c
src/uobject/loadable.h

index 920e23c372854433af49a940c6e360b537092f15..879e0adbbf0c66f6cf8d61b516b6f48e59420bd3 100644 (file)
@@ -39,10 +39,10 @@ class Engine:Music from U:Object (dynamic)
        private unsigned loaded = 0;
 
        interface U:Object:Loadable
-       private int load(G:Object *go)
+       private int load(U:Object *uo)
        {
-               struct upkg_file *f = U_OBJECT(go)->pkg_file;
-               Self *self = SELF(go);
+               struct upkg_file *f = uo->pkg_file;
+               Self *self = SELF(uo);
 
                if (!self->_priv->loaded) {
                        g_return_val_if_fail(f != NULL, -1);
@@ -60,9 +60,9 @@ class Engine:Music from U:Object (dynamic)
        }
 
        interface U:Object:Loadable
-       private void unload(G:Object *go)
+       private void unload(U:Object *uo)
        {
-               Self *self = SELF(go);
+               Self *self = SELF(uo);
 
                g_return_if_fail(self->_priv->loaded > 0);
 
@@ -71,37 +71,37 @@ class Engine:Music from U:Object (dynamic)
        }
 
        interface U:Object:Exportable
-       private int export(G:Object *go, FILE *f)
+       private int export(U:Object *uo, FILE *f)
        {
-               Self *self = SELF(go);
+               Self *self = SELF(uo);
                int rc;
 
-               if (self_load(go) != 0)
+               if (self_load(uo) != 0)
                        return -1;
 
                rc = music_mod_dump(self->_priv->mod, f);
 
-               self_unload(go);
+               self_unload(uo);
                return rc;
        }
 
        interface U:Object:Exportable
-       private int export_name(G:Object *go, char *buf, size_t n)
+       private int export_name(U:Object *uo, char *buf, size_t n)
        {
-               Self *self = SELF(go);
+               Self *self = SELF(uo);
                const char *type;
                int rc;
 
-               if (self_load(go) != 0) {
+               if (self_load(uo) != 0) {
                        if (n > 0)
                                buf[0] = '\0';
                        return 0;
                }
 
                type = music_mod_type(self->_priv->mod);
-               rc = snprintf(buf, n, "%s.%s", U_OBJECT(go)->pkg_file->name, type);
+               rc = snprintf(buf, n, "%s.%s", uo->pkg_file->name, type);
 
-               self_unload(go);
+               self_unload(uo);
                return rc;
        }
 
index 9cb1de1240a7580fc9d0ee56f8dec983f8660d42..541e6980017a7aa7220a7e393bc6a08642739145 100644 (file)
@@ -17,8 +17,7 @@
  */
 
 #include <stdio.h>
-#include <glib-object.h>
-#include <uobject/exportable.h>
+#include "exportable.h"
 
 GType u_object_exportable_get_type(void)
 {
@@ -36,14 +35,20 @@ GType u_object_exportable_get_type(void)
        return type;
 }
 
-int u_object_export(GObject *obj, FILE *f)
+int u_object_export(GObject *go, FILE *f)
 {
-       g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(obj), -1);
-       return U_OBJECT_EXPORTABLE_GET_INTERFACE(obj)->export(obj, f);
+       g_return_val_if_fail(IS_U_OBJECT(go), -1);
+       g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(go), -1);
+       UObject *uo = U_OBJECT(go);
+
+       return U_OBJECT_EXPORTABLE_GET_INTERFACE(go)->export(uo, f);
 }
 
-int u_object_export_name(GObject *obj, char *buf, size_t n)
+int u_object_export_name(GObject *go, char *buf, size_t n)
 {
-       g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(obj), -1);
-       return U_OBJECT_EXPORTABLE_GET_INTERFACE(obj)->export_name(obj, buf, n);
+       g_return_val_if_fail(IS_U_OBJECT(go), -1);
+       g_return_val_if_fail(U_OBJECT_IS_EXPORTABLE(go), -1);
+       UObject *uo = U_OBJECT(go);
+
+       return U_OBJECT_EXPORTABLE_GET_INTERFACE(go)->export_name(uo, buf, n);
 }
index d3e9ce869c9c781cee1b72da79dc821fee7ef5c1..4033a1a15976122704e152e1b67d7fe04a2bf758 100644 (file)
@@ -20,7 +20,7 @@
 #define U_OBJECT_EXPORTABLE_H_
 
 #include <stdio.h>
-#include <glib-object.h>
+#include <uobject/uobject.h>
 
 #define U_TYPE_OBJECT_EXPORTABLE (u_object_exportable_get_type())
 #define U_OBJECT_EXPORTABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
@@ -39,8 +39,8 @@ typedef struct UObjectExportableIface UObjectExportableIface;
 struct UObjectExportableIface {
        GTypeInterface parent;
 
-       int (*export)(GObject *obj, FILE *f);
-       int (*export_name)(GObject *obj, char *buf, size_t n);
+       int (*export)(UObject *obj, FILE *f);
+       int (*export_name)(UObject *obj, char *buf, size_t n);
 };
 
 GType u_object_exportable_get_type(void);
index 8ed00ffdb3ad7d0bbdc0a33a0ce3b1a7391ed446..1e41c465157c198cbd4cfd4a3641ef0cccb25c8d 100644 (file)
@@ -16,9 +16,7 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdio.h>
-#include <glib-object.h>
-#include <uobject/loadable.h>
+#include "loadable.h"
 
 GType u_object_loadable_get_type(void)
 {
@@ -36,14 +34,18 @@ GType u_object_loadable_get_type(void)
        return type;
 }
 
-int u_object_load(GObject *obj)
+int u_object_load(GObject *go)
 {
-       g_return_val_if_fail(U_OBJECT_IS_LOADABLE(obj), -1);
-       return U_OBJECT_LOADABLE_GET_INTERFACE(obj)->load(obj);
+       g_return_val_if_fail(IS_U_OBJECT(go), -1);
+       g_return_val_if_fail(U_OBJECT_IS_LOADABLE(go), -1);
+
+       return U_OBJECT_LOADABLE_GET_INTERFACE(go)->load(U_OBJECT(go));
 }
 
-void u_object_unload(GObject *obj)
+void u_object_unload(GObject *go)
 {
-       g_return_if_fail(U_OBJECT_IS_LOADABLE(obj));
-       U_OBJECT_LOADABLE_GET_INTERFACE(obj)->unload(obj);
+       g_return_if_fail(IS_U_OBJECT(go));
+       g_return_if_fail(U_OBJECT_IS_LOADABLE(go));
+
+       U_OBJECT_LOADABLE_GET_INTERFACE(go)->unload(U_OBJECT(go));
 }
index 296366b6272c6d7c4ecf0566c39d6700ae221891..d862583890fac12a6609b0b0ca6e25083f758d97 100644 (file)
@@ -19,8 +19,7 @@
 #ifndef U_OBJECT_LOADABLE_H_
 #define U_OBJECT_LOADABLE_H_
 
-#include <stdio.h>
-#include <glib-object.h>
+#include <uobject/uobject.h>
 
 #define U_TYPE_OBJECT_LOADABLE (u_object_loadable_get_type())
 #define U_OBJECT_LOADABLE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, \
@@ -41,8 +40,8 @@ typedef struct UObjectLoadableIface UObjectLoadableIface;
 struct UObjectLoadableIface {
        GTypeInterface parent;
 
-       int (*load)(GObject *obj);
-       void (*unload)(GObject *obj);
+       int (*load)(UObject *obj);
+       void (*unload)(UObject *obj);
 };
 
 GType u_object_loadable_get_type(void);