]> git.draconx.ca Git - upkg.git/commitdiff
Early start of the module system.
authorNick Bowler <nbowler@draconx.ca>
Tue, 9 Jun 2009 19:23:10 +0000 (15:23 -0400)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Jun 2009 19:25:04 +0000 (15:25 -0400)
src/Makefile.am
src/module.c [new file with mode: 0644]
src/module.h [new file with mode: 0644]
src/upkg.c

index 95e7082795b48b8fa8e7fd41ccef3f408297954c..8b3567639e97e72baff8e2518a6b6b9aab606201 100644 (file)
@@ -5,9 +5,11 @@ include_HEADERS = upkg.h
 noinst_HEADERS = pack.h
 
 if BUILD_UPKG
-bin_PROGRAMS = upkg
-upkg_SOURCES = upkg.c exportable.c serializable.c music.c
-upkg_CFLAGS  = $(GLIB_CFLAGS)
-upkg_LDFLAGS = $(GLIB_LIBS)
-upkg_LDADD = libupkg.la $(LIBLTDL)
+
+bin_PROGRAMS  = upkg
+upkg_SOURCES  = upkg.c module.c exportable.c serializable.c music.c
+upkg_CPPFLAGS = $(GLIB_CFLAGS) $(LTDLINCL)
+upkg_LDFLAGS  = $(GLIB_LIBS)
+upkg_LDADD    = libupkg.la $(LIBLTDL)
+
 endif
diff --git a/src/module.c b/src/module.c
new file mode 100644 (file)
index 0000000..5edc5e2
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <glib-object.h>
+#include <ltdl.h>
+
+#include "module.h"
+
+static unsigned initialized;
+
+static void dl_print_errors(const char *prefix)
+{
+       const char *err;
+       while (err = lt_dlerror()) {
+               if (prefix) fprintf(stderr, "%s: ", prefix);
+               puts(lt_dlerror());
+       }
+}
+
+int module_init(void)
+{
+       if (!initialized) {
+               if (lt_dlinit() != 0) {
+                       dl_print_errors(__func__);
+                       return -1;
+               }
+
+               g_type_init();
+       }
+
+       initialized++;
+       return 0;
+}
+
+int module_exit(void)
+{
+       if (--initialized)
+               return 0;
+
+       if (lt_dlexit() != 0) {
+               dl_print_errors(__func__);
+               return -1;
+       }
+}
diff --git a/src/module.h b/src/module.h
new file mode 100644 (file)
index 0000000..ea52071
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef MODULE_H_
+#define MODULE_H_
+
+int module_init(void);
+int module_exit(void);
+
+#endif
index bcbee2fbcd291b5522ea551942e81c5ec07ed729..a7e96bf02984fbbf21c95ac7e4d8841b86e72a85 100644 (file)
@@ -22,6 +22,7 @@
 #include <glib-object.h>
 
 #include "upkg.h"
+#include "module.h"
 #include "serializable.h"
 #include "exportable.h"
 #include "music.h"
@@ -57,13 +58,14 @@ int main(int argc, char **argv)
 {
        struct upkg *pkg;
 
-       g_type_init();
-
        if (argc < 2) {
                fprintf(stderr, "usage: upkg file\n");
                return EXIT_FAILURE;
        }
 
+       if (module_init() != 0)
+               return EXIT_FAILURE;
+
        pkg = upkg_fopen(argv[1]);
        if (!pkg) {
                fprintf(stderr, "failed to open package!\n");
@@ -99,5 +101,7 @@ int main(int argc, char **argv)
        printf("Wrote %s\n", name);
 
        upkg_close(pkg);
+       module_exit();
+
        return 0;
 }