#include <glib-object.h>
#include <uobject/uobject.h>
+#include <uobject/module.h>
#include "upkg.h"
#include "pack.h"
return rc;
}
+GObject *u_object_new_from_package(struct upkg *upkg, unsigned long idx)
+{
+ const struct upkg_export *export;
+ const char *class, *package;
+ GObject *obj = NULL;
+ GType type;
+
+ class = upkg_export_class(upkg, idx, &package);
+
+ type = u_object_module_get_class(package, class);
+ if (type) {
+ obj = g_object_new(type, NULL);
+ if (u_object_deserialize(obj, upkg, idx) != 0) {
+ g_object_unref(obj);
+ return NULL;
+ }
+ }
+
+ return obj;
+}
+
static void u_object_init(UObject *o)
{
o->pkg = NULL;
int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx);
+GObject *u_object_new_from_package(struct upkg *pkg, unsigned long idx);
+
#endif
if (verbose >= 1) {
GParamSpec **props;
GObject *obj;
- GType type;
unsigned n;
- type = u_object_module_get_class(package, class);
- if (!type) {
- printf(" (unknown class)\n");
- return 0;
- }
-
- obj = g_object_new(type, NULL);
-
- if (u_object_deserialize(obj, upkg, idx) != 0) {
- g_object_unref(obj);
+ obj = u_object_new_from_package(upkg, idx);
+ if (!obj) {
+ fprintf(stderr, "%s: failed to load object.\n",
+ progname);
return -1;
}