Experimental Physics and Industrial Control System
Hi Kate and all others,
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);
- Replies:
- Re: R3.14 and registerRecordDeviceDriver Kate Feng
- References:
- R3.14 and registerRecordDeviceDriver Kate Feng
- Navigate by Date:
- Prev:
Re: R3.14 and registerRecordDeviceDriver Kate Feng
- Next:
EPICS collaboration meeting presentations Hayton, TG (Tim)
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
<2003>
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: R3.14 and registerRecordDeviceDriver Kate Feng
- Next:
Re: R3.14 and registerRecordDeviceDriver Kate Feng
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
<2003>
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024