|
|
Experimental Physics and
| ||||||||||||||
|
|
Kate Feng wrote:
> ... My wish also gives RTEMS or Linux users an option to dynamically
> load a new application code (e.g. ld("new.obj")), which might need a
> new record/device/driver support entry table registered (e.g.
> new_SRCS += new_registerRecordDeviceDriver.cpp) at run time or even
> during an IOC test/development stage, which could occur very often
> during a development cycle. I actually found it handy in beamline
> applications.
> ...Attached you will find a Linux (UNIX?) implementation of the 'ld' command. Just link it to your iocsh. On Linux, it can load shared libraries (*.so). Maybe the code has to be modified to run on other platforms. I used the 'dlopen' function to implement it. ld ("foo") Searches LD_LIBRARY_PATH for libfoo.so, foo.so, foo (in this order). After loading the code, all C++ constructors of global objects are executed (for registering, etc.) I have not tried it on any other platform. Dirk -- Dr. Dirk Zimoch Swiss Light Source Paul Scherrer Institut Computing and Controls phone +41 56 310 5182 fax +41 56 310 4413 /*
* ld - load code dynamically
*
* $Author$
* $ID$
* $Date$
*
* DISCLAIMER: Use at your own risc and so on. No warranty, no refund.
*/
#include <iocsh.h>
#include <stdio.h>
#include <dlfcn.h>
/* ld (dynamicLibrary) */
static const iocshArg ldArg0 = { "library", iocshArgString };
static const iocshArg * const ldArgs[1] = { &ldArg0 };
static const iocshFuncDef ldFuncDef = { "ld", 1, ldArgs };
static void ldCallFunc (const iocshArgBuf *args)
{
#ifdef UNIX
char libname[256];
if (!args[0].sval)
{
fprintf (stderr, "missing library name");
return;
}
sprintf (libname, "lib%.249s.so", args[0].sval);
if (dlopen (libname, RTLD_NOW|RTLD_GLOBAL)) return;
sprintf (libname, "%.252s.so", args[0].sval);
if (dlopen (libname, RTLD_NOW|RTLD_GLOBAL)) return;
sprintf (libname, "%.255s", args[0].sval);
if (dlopen (libname, RTLD_NOW|RTLD_GLOBAL)) return;
fprintf (stderr, "%s\n", dlerror());
#else
fprintf (stderr, "not supported for this operating system");
#endif
}
class IocshRegister {
public:
IocshRegister (const iocshFuncDef& piocshFuncDef, iocshCallFunc func) {
iocshRegister (&piocshFuncDef, func); }
};
static IocshRegister register_ld (ldFuncDef, ldCallFunc);
| ||||||||||||||
| ANJ, 10 Aug 2010 |
·
Home
·
News
·
About
·
Talk
·
Base
·
Modules
·
Extensions
·
· Distributions · Download · Documents · Links · Licensing · |