Author: adrian.chadd
Date: Fri Apr 17 07:15:00 2009
New Revision: 13941

Added:
    playpen/LUSCA_HEAD_module/libsqmod/module.h
Modified:
    playpen/LUSCA_HEAD_module/libsqmod/module.c

Log:
Continue fleshing out the basic module code - hopefully will be able
to load a few modules soon.



Modified: playpen/LUSCA_HEAD_module/libsqmod/module.c
==============================================================================
--- playpen/LUSCA_HEAD_module/libsqmod/module.c (original)
+++ playpen/LUSCA_HEAD_module/libsqmod/module.c Fri Apr 17 07:15:00 2009
@@ -1,8 +1,39 @@
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
-
  #include <dlfcn.h>
+#include <string.h>
+
+#include "../libcore/mem.h"
+#include "../libcore/dlink.h"
+#include "../libcore/varargs.h"
+
+#include "../libsqdebug/debug.h"
+
+#include "module.h"
+
+dlink_list module_list;
+
+int
+module_init(void)
+{
+       bzero(&module_list, sizeof(module_list));
+}
+
+module_t *
+module_lookup_bypath(const char *path)
+{
+       dlink_node *n = module_list.head;
+       module_t *m;
+
+       for (n = module_list.head; n != NULL; n = n->next) {
+               /* XXX strcmp? */
+               m = n->data;
+               if (strcmp(path, m->mod_path) == 0)
+                       return m;
+       }
+       return NULL;
+}

  /*
   * Stuff to look at
@@ -14,13 +45,62 @@
   *   who want to be able to make Lusca reload updated modules during
   *   reconfigure.
   */
-int
-module_load(const char *path)
+
+module_t *
+module_register(const char *path)
  {
-       void *handle = NULL;
+       module_t *m;
+
+       m = xxmalloc(sizeof(*m));
+       if (! m)
+               return NULL;
+
+       debug(85, 1) ("module_register: loading %s\n", path);
        
-       handle = dlopen(path, RTLD_LAZY);
-       if (! handle) {
-               return -1;
+       m->dl_handle = dlopen(path, RTLD_LAZY);
+       if (! m->dl_handle) {
+               /* XXX this should really log/return something */
+               xxfree(m);
+               debug(85, 1) ("module_register: failed: %s: %s\n", path, 
dlerror());
+               return NULL;
+       }
+
+       /* Lookup the init symbol */
+       m->mod_init = dlsym(m->dl_handle, "moduleInitFunc");
+       if (! m->mod_init) {
+               /* XXX this should really log/return something */
+               xxfree(m);
+               debug(85, 1) ("module_register: failed symbol lookup: %s: 
%s\n", path,  
dlerror());
+               return NULL;
+       }
+
+       /* Set the module state */
+       m->state = MOD_LOADED;
+
+       /* Add it to the list */
+       dlinkAddTail(m, &m->n, &module_list);
+
+       /* Return success */
+       debug(85, 1) ("module_register: %s: successful; state MOD_LOADED\n",  
path);
+       return m;
+}
+
+void
+module_setup(void)
+{
+       dlink_node *n;
+       module_t *m;
+       int r;
+
+       debug(85, 1) ("module_setup: beginning\n");
+
+       for (n = module_list.head; n != NULL; n = n->next) {
+               if (m->state != MOD_LOADED) {
+                       debug(85, 1) ("module_register: %p (%s): skipping; 
state = %d\n",
+                           m, m->mod_path, m->state);
+                       continue;
+               }
+               r = m->mod_init(m);
+               debug(85, 1) ("module_register: %p (%s): mod_init returned 
%d\n", m,  
m->mod_path, r);
        }
  }

Added: playpen/LUSCA_HEAD_module/libsqmod/module.h
==============================================================================
--- (empty file)
+++ playpen/LUSCA_HEAD_module/libsqmod/module.h Fri Apr 17 07:15:00 2009
@@ -0,0 +1,31 @@
+#ifndef        __LIBSQMOD_MODULE_H__
+#define        __LIBSQMOD_MODULE_H__
+
+struct _module;
+typedef struct _module module_t;
+
+typedef int MOD_INIT_FUNCTION(module_t *m);
+
+typedef enum {
+       MOD_NONE,
+       MOD_LOADED,
+       MOD_READY,
+       MOD_INACTIVE,
+       MOD_ERROR,
+       MOD_DYING
+} module_state_t;
+
+/*
+ * A configured module.
+ * For now there must not be >1 module with the same name.
+ */
+struct _module {
+       dlink_node n;
+       const char *mod_name;
+       const char *mod_path;
+       void *dl_handle;
+       MOD_INIT_FUNCTION *mod_init;
+       module_state_t state;
+};
+
+#endif

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to