kopia lustrzana https://github.com/Hamlib/Hamlib
use define ABI_VERSION when declaring backends, patch by Stelios Bounanos M0GLD
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2719 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.10
rodzic
6282f571eb
commit
e7a8fe2fb2
|
@ -286,6 +286,28 @@ int rig_load_all_backends()
|
||||||
|
|
||||||
|
|
||||||
#define MAXFUNCNAMELEN 64
|
#define MAXFUNCNAMELEN 64
|
||||||
|
typedef int (*backend_init_t)(rig_ptr_t);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rig_check_backend_version
|
||||||
|
* Check that the versioned init function name for be_name is the correct version.
|
||||||
|
*/
|
||||||
|
static backend_init_t rig_check_backend_version(const lt_dlhandle be_handle, const char *be_name,
|
||||||
|
backend_init_t **be_init)
|
||||||
|
{
|
||||||
|
char initfname[MAXFUNCNAMELEN];
|
||||||
|
|
||||||
|
snprintf(initfname, MAXFUNCNAMELEN, "initrigs%d_%s", ABI_VERSION, be_name);
|
||||||
|
*be_init = (backend_init_t) lt_dlsym(be_handle, initfname);
|
||||||
|
if (!*be_init) {
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "rig: dlsym(%s) failed (%s)\n",
|
||||||
|
initfname, lt_dlerror());
|
||||||
|
return -RIG_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* rig_load_backend
|
* rig_load_backend
|
||||||
* Dynamically load a rig backend through dlopen mechanism
|
* Dynamically load a rig backend through dlopen mechanism
|
||||||
|
@ -295,10 +317,9 @@ int HAMLIB_API rig_load_backend(const char *be_name)
|
||||||
# define PREFIX "hamlib-"
|
# define PREFIX "hamlib-"
|
||||||
|
|
||||||
lt_dlhandle be_handle;
|
lt_dlhandle be_handle;
|
||||||
int (*be_init)(rig_ptr_t);
|
backend_init_t be_init;
|
||||||
int status;
|
int status;
|
||||||
char libname[PATH_MAX];
|
char libname[PATH_MAX];
|
||||||
char initfname[MAXFUNCNAMELEN];
|
|
||||||
char probefname[MAXFUNCNAMELEN];
|
char probefname[MAXFUNCNAMELEN];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -333,26 +354,16 @@ int HAMLIB_API rig_load_backend(const char *be_name)
|
||||||
* external module not found? try dlopenself for backends
|
* external module not found? try dlopenself for backends
|
||||||
* compiled in static
|
* compiled in static
|
||||||
*/
|
*/
|
||||||
if (!be_handle) {
|
if (!be_handle || rig_check_backend_version(be_handle, be_name, &be_init) != RIG_OK) {
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "rig: lt_dlopen(\"%s\") failed (%s), "
|
rig_debug(RIG_DEBUG_VERBOSE, "rig: lt_dlopen(\"%s\") failed (%s), "
|
||||||
"trying static symbols...\n",
|
"trying static symbols...\n",
|
||||||
libname, lt_dlerror());
|
libname, lt_dlerror());
|
||||||
be_handle = lt_dlopen (NULL);
|
be_handle = lt_dlopen (NULL);
|
||||||
}
|
if (!be_handle || rig_check_backend_version(be_handle, be_name, &be_init) != RIG_OK) {
|
||||||
|
|
||||||
if (!be_handle) {
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "rig: lt_dlopen(\"%s\") failed (%s)\n",
|
rig_debug(RIG_DEBUG_ERR, "rig: lt_dlopen(\"%s\") failed (%s)\n",
|
||||||
libname, lt_dlerror());
|
libname, lt_dlerror());
|
||||||
return -RIG_EINVAL;
|
return -RIG_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(initfname, MAXFUNCNAMELEN, "initrigs%d_%s", ABI_VERSION, be_name);
|
|
||||||
be_init = (int (*)(rig_ptr_t)) lt_dlsym (be_handle, initfname);
|
|
||||||
if (!be_init) {
|
|
||||||
rig_debug(RIG_DEBUG_ERR, "rig: dlsym(%s) failed (%s)\n",
|
|
||||||
initfname, lt_dlerror());
|
|
||||||
lt_dlclose(be_handle);
|
|
||||||
return -RIG_EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,24 +32,32 @@
|
||||||
#define EXTERN_C extern
|
#define EXTERN_C extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CONCAT4(w__, x__, y__, z__) w__ ## x__ ## y__ ## z__
|
||||||
|
#define MAKE_VERSIONED_FN(prefix__, version__, name_args__) CONCAT4(prefix__, version__, _, name_args__)
|
||||||
|
/* void MAKE_VERSIONED_FN(foo, 42, bar(int i)) -> void foo42_bar(int i) */
|
||||||
|
|
||||||
|
#ifndef ABI_VERSION
|
||||||
|
#error ABI_VERSION undefined! Did you include config.h?
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DECLARE_INITRIG_BACKEND
|
#ifdef DECLARE_INITRIG_BACKEND
|
||||||
#undef DECLARE_INITRIG_BACKEND
|
#undef DECLARE_INITRIG_BACKEND
|
||||||
#endif
|
#endif
|
||||||
#define DECLARE_INITRIG_BACKEND(backend) EXTERN_C BACKEND_EXPORT(int) initrigs2_##backend(void *be_handle)
|
#define DECLARE_INITRIG_BACKEND(backend) EXTERN_C BACKEND_EXPORT(int) MAKE_VERSIONED_FN(initrigs, ABI_VERSION, backend(void *be_handle))
|
||||||
|
|
||||||
#ifdef DECLARE_PROBERIG_BACKEND
|
#ifdef DECLARE_PROBERIG_BACKEND
|
||||||
#undef DECLARE_PROBERIG_BACKEND
|
#undef DECLARE_PROBERIG_BACKEND
|
||||||
#endif
|
#endif
|
||||||
#define DECLARE_PROBERIG_BACKEND(backend) EXTERN_C BACKEND_EXPORT(rig_model_t) probeallrigs2_##backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)
|
#define DECLARE_PROBERIG_BACKEND(backend) EXTERN_C BACKEND_EXPORT(rig_model_t) MAKE_VERSIONED_FN(probeallrigs, ABI_VERSION, backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data))
|
||||||
|
|
||||||
#ifdef DECLARE_INITROT_BACKEND
|
#ifdef DECLARE_INITROT_BACKEND
|
||||||
#undef DECLARE_INITROT_BACKEND
|
#undef DECLARE_INITROT_BACKEND
|
||||||
#endif
|
#endif
|
||||||
#define DECLARE_INITROT_BACKEND(backend) EXTERN_C BACKEND_EXPORT(int) initrots2_##backend(void *be_handle)
|
#define DECLARE_INITROT_BACKEND(backend) EXTERN_C BACKEND_EXPORT(int) MAKE_VERSIONED_FN(initrots, ABI_VERSION, backend(void *be_handle))
|
||||||
|
|
||||||
#ifdef DECLARE_PROBEROT_BACKEND
|
#ifdef DECLARE_PROBEROT_BACKEND
|
||||||
#undef DECLARE_PROBEROT_BACKEND
|
#undef DECLARE_PROBEROT_BACKEND
|
||||||
#endif
|
#endif
|
||||||
#define DECLARE_PROBEROT_BACKEND(backend) EXTERN_C BACKEND_EXPORT(rot_model_t) probeallrots2_##backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)
|
#define DECLARE_PROBEROT_BACKEND(backend) EXTERN_C BACKEND_EXPORT(rot_model_t) MAKE_VERSIONED_FN(probeallrots, ABI_VERSION, backend(hamlib_port_t *port, rig_probe_func_t cfunc, rig_ptr_t data))
|
||||||
|
|
||||||
#endif /* _REGISTER_H */
|
#endif /* _REGISTER_H */
|
||||||
|
|
Ładowanie…
Reference in New Issue