LCDproc development and user support list

Text archives Help


[Lcdproc] dynamic drivers patch - take 1


Chronological Thread 
  • From: ed.hunter AT seznam.cz (Ed Hunter)
  • Subject: [Lcdproc] dynamic drivers patch - take 1
  • Date: Mon Oct 1 16:05:02 2001

Hi all,

I have attached a following simple patch which makes LCDd use dynamically loaded drivers

Instructions to use:

apply the patch, then:

sh autogen.sh
./configure --enable-dl-drivers --with-driver-base=drivers/

cd server/drivers
gcc -shared curses_drv.o ../../shared/str.o -o curses.so

cd ..
./LCDd -d curses


Caveats:
- it works on unix only for now
- only curses driver is supported for now, due to an irregularity in driver file and entry point names: it's curses_drv_init(), but text_init(). Grrr. I guess it has to be be fixed
- there's not automatic building of .so files
- the dl* stuff should be moved to it's own file
- *.so is not in clean: target yet
- and many more


Your comments?
Jarda Benkovsky
diff --exclude-from diff_ignore -ruN lcdproc-orig/acconfig.h
lcdproc/acconfig.h
--- lcdproc-orig/acconfig.h Thu Sep 27 00:29:00 2001
+++ lcdproc/acconfig.h Mon Oct 1 17:47:34 2001
@@ -90,6 +90,12 @@

#undef T6963_DRV

+/* if defined, use dynamically loaded drivers */
+#undef DL_DRIVERS
+
+/* directory in which the dynamically loaded drivers are stored */
+#define DRIVER_BASE ""
+
/* Define the package version */
#undef VERSION

diff --exclude-from diff_ignore -ruN lcdproc-orig/configure.in
lcdproc/configure.in
--- lcdproc-orig/configure.in Thu Jul 19 03:07:33 2001
+++ lcdproc/configure.in Mon Oct 1 17:18:54 2001
@@ -92,6 +92,19 @@

AC_GET_FS_INFO

+AC_ARG_WITH(driver-base,
+ [ --with-driver-base=<dir> directory with dynamically loaded drivers],
+ DRIVER_BASE=$withval,
+ DRIVER_BASE=""
+)
+AC_DEFINE_UNQUOTED(DRIVER_BASE, "$DRIVER_BASE")
+
+AC_ARG_ENABLE(dl-drivers,
+ [ --enable-dl-drivers use dynamically loaded drivers],
+ AC_DEFINE(DL_DRIVERS)
+ LIBS="-ldl $LIBS"
+)
+
AC_ARG_ENABLE(stat-nfs,
[ --enable-stat-nfs display filesystem stats for NFS],
AC_DEFINE(STAT_NFS)
diff --exclude-from diff_ignore -ruN lcdproc-orig/server/drivers/lcd.c
lcdproc/server/drivers/lcd.c
--- lcdproc-orig/server/drivers/lcd.c Fri Sep 28 23:29:23 2001
+++ lcdproc/server/drivers/lcd.c Mon Oct 1 17:33:57 2001
@@ -31,6 +31,10 @@
#include "config.h"
#endif

+#ifdef DL_DRIVERS
+#include <dlfcn.h>
+#endif
+
#include "shared/LL.h"
#include "shared/debug.h"

@@ -146,6 +150,8 @@

lcd_logical_driver lcd, *lcd_root = NULL, *lcd_ptr = NULL;

+#ifndef DL_DRIVERS
+
// TODO: Add multiple names for the same driver?
//
// Would allow the use of "MatrixOrbital" (for example) or
@@ -220,6 +226,8 @@

};

+#endif /* ! DL_DRIVERS */
+
LL *list;

#define CurrentDriver (drivers[i].name)
@@ -227,6 +235,7 @@

void
lcd_list_drivers (void) {
+#ifndef DL_DRIVERS
int i = 0;

printf("\t");
@@ -242,6 +251,7 @@
}

printf("\n");
+#endif /* ! DL_DRIVERS */
}

////////////////////////////////////////////////////////////
@@ -361,6 +371,8 @@
return 0;
}

+#ifndef DL_DRIVERS /* drivers are static compiled in */
+
/*
* This function can be replaced later with something
* that utilizes the results of dynamic library loading
@@ -382,6 +394,49 @@
}
return NULL;
}
+
+#else /* DL_DRIVERS */
+
+/* #define DRIVER_BASE "/home/benkovsk/worx/cvs/lcdproc/server/drivers/" */
+
+/* FIXME: it's a dynamically loading version. Since it's only a hack over an
existing api, it's rather ugly. */
+
+static void*
+lcd_find_init (char *driver)
+{
+ void *driver_handle;
+ char *file = malloc (strlen (DRIVER_BASE) + strlen (driver) + strlen
(".so") + 1);
+ char *symbol_name = malloc (strlen (driver) + strlen ("_drv_init") + 1);
+ void *symbol_ptr;
+
+ sprintf (file, "%s%s.so", DRIVER_BASE, driver);
+ driver_handle = dlopen (file, RTLD_GLOBAL | RTLD_NOW);
+
+ if (! driver_handle) {
+ syslog (LOG_ERR, "DLError: %s\n", dlerror ());
+ return NULL;
+ }
+
+ sprintf (symbol_name, "%s_drv_init", driver);
+ symbol_ptr = dlsym (driver_handle, symbol_name);
+
+ if (! symbol_ptr) syslog (LOG_ERR, "DLError: %s\n", dlerror ());
+
+ return symbol_ptr;
+}
+
+/* FIXME: useless now */
+static void
+lcd_remove_driver (void *handle)
+{
+ dlclose (handle);
+}
+
+
+#endif /* DL_DRIVERS */
+
+
+

// TODO: lcd_remove_driver()




Archive powered by MHonArc 2.6.18.

Top of page