unsigned long nbuf;
};
+G_DEFINE_TYPE(UObject, u_object, G_TYPE_OBJECT);
+
static unsigned long
get_real_size(unsigned long *real, unsigned size, unsigned char *buf, size_t n)
{
return 0;
}
-int u_object_deserialize(GObject *obj, struct upkg_file *f)
+int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx)
{
g_return_val_if_fail(IS_U_OBJECT(obj), -1);
- return U_OBJECT_GET_CLASS(obj)->deserialize(U_OBJECT(obj), f);
+ UObject *uo = U_OBJECT(obj);
+ struct upkg_file *f;
+ int rc;
+
+ g_return_val_if_fail(uo->pkg_file == NULL, -1);
+ f = upkg_export_open(pkg, idx);
+ if (!f) {
+ return -1;
+ }
+
+ rc = U_OBJECT_GET_CLASS(obj)->deserialize(uo, f);
+ if (rc != 0) {
+ upkg_export_close(f);
+ } else {
+ uo->pkg = pkg;
+ uo->pkg_idx = idx;
+ uo->pkg_file = f;
+ }
+
+ return rc;
}
static void u_object_init(UObject *o)
{
- struct uobject_priv *priv = U_OBJECT_GET_PRIV(o);
+ o->pkg = NULL;
+ o->pkg_file = NULL;
+ o->pkg_idx = 0;
+}
+
+static void u_object_finalize(GObject *o)
+{
+ UObject *uo = U_OBJECT(o);
+
+ if (uo->pkg_file) {
+ upkg_export_close(uo->pkg_file);
+ }
+
+ G_OBJECT_CLASS(u_object_parent_class)->finalize(o);
}
static void u_object_class_init(UObjectClass *class)
{
g_type_class_add_private(class, sizeof (struct uobject_priv));
+ GObjectClass *go = G_OBJECT_CLASS(class);
class->deserialize = deserialize;
+ go->finalize = u_object_finalize;
}
-
-G_DEFINE_TYPE(UObject, u_object, G_TYPE_OBJECT);
#include <glib-object.h>
#include "upkg.h"
-#include "avl.h"
#define U_OBJECT_TYPE u_object_get_type()
#define U_OBJECT(obj) \
struct UObject {
GObject parent;
+
+ struct upkg *pkg;
+ struct upkg_file *pkg_file;
+ unsigned long pkg_idx;
};
struct UObjectClass {
const GValue *u_object_get_property(UObject *obj, const char *name);
void u_object_set_property(UObject *obj, const char *name, const GValue *val);
-int u_object_deserialize(GObject *obj, struct upkg_file *f);
+int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx);
#endif
static int export(struct upkg *pkg, GObject *obj, unsigned idx)
{
- struct upkg_file *f = upkg_export_open(pkg, idx);
char name[256];
FILE *of;
- int rc = -1;
- if (u_object_deserialize(obj, f) != 0) {
- goto out;
+ if (u_object_deserialize(obj, pkg, idx) != 0) {
+ return -1;
}
if (U_OBJECT_IS_LOADABLE(obj) && u_object_load(obj) != 0) {
- goto out;
+ return -1;
}
u_object_export_name(obj, name, sizeof name);
of = fopen(name, "wb");
if (!of) {
perror(name);
- goto out;
+ return -1;
}
- rc = u_object_export(obj, of);
+ u_object_export(obj, of);
if (fclose(of) != 0) {
perror(name);
- rc = -1;
- goto out;
+ return -1;
}
if (U_OBJECT_IS_LOADABLE(obj)) {
u_object_unload(obj);
}
-out:
- upkg_export_close(f);
- return rc;
+ return 0;
}
int package_export(struct upkg *pkg)