]> git.draconx.ca Git - upkg.git/blobdiff - src/uobject/uobject.c
uobject: Add a helper function to load objects from packages.
[upkg.git] / src / uobject / uobject.c
index 581ac0798f3d45d0c4542ba31f3c5d49e5d52950..7b0a79e4e4a751f2a435582ea1ee934e30afdfbb 100644 (file)
@@ -23,6 +23,7 @@
 #include <glib-object.h>
 
 #include <uobject/uobject.h>
+#include <uobject/module.h>
 #include "upkg.h"
 #include "pack.h"
 
@@ -216,6 +217,27 @@ int u_object_deserialize(GObject *obj, struct upkg *pkg, unsigned long idx)
        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;