Mod loading new style is working now
FossilOrigin-Name: 905983d556f8197f90e84e6f2e09b0543f708d51efbffc8de87ec89536c6b6f8
This commit is contained in:
parent
7ecca3ef1f
commit
524b8ed1fd
@ -577,10 +577,6 @@ static int conf_read_mods(cfg_t *cfg){
|
|||||||
|
|
||||||
for (i=0; i < n; i++){
|
for (i=0; i < n; i++){
|
||||||
char *modname = cfg_getnstr(cfg, CFG_ENTRY_MODS, i);
|
char *modname = cfg_getnstr(cfg, CFG_ENTRY_MODS, i);
|
||||||
|
|
||||||
printf("Modname: %s\n",modname);
|
|
||||||
|
|
||||||
|
|
||||||
struct cw_Mod * mod = cw_mod_load(modname);
|
struct cw_Mod * mod = cw_mod_load(modname);
|
||||||
if (!mod)
|
if (!mod)
|
||||||
return 0;
|
return 0;
|
||||||
@ -830,7 +826,9 @@ int read_config(const char *filename)
|
|||||||
if (!conf_image_dir)
|
if (!conf_image_dir)
|
||||||
conf_image_dir = CONF_DEFAULT_IMAGE_DIR;
|
conf_image_dir = CONF_DEFAULT_IMAGE_DIR;
|
||||||
|
|
||||||
init_mods();
|
//printf("INIT MODS\n");
|
||||||
|
// init_mods();
|
||||||
|
//printf("done init mods");
|
||||||
|
|
||||||
// conf_init_capwap_mode();
|
// conf_init_capwap_mode();
|
||||||
|
|
||||||
@ -839,7 +837,7 @@ int read_config(const char *filename)
|
|||||||
init_mcast_groups();
|
init_mcast_groups();
|
||||||
init_bcast_addrs();
|
init_bcast_addrs();
|
||||||
|
|
||||||
|
//printf("Yea all mods inited\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
59
src/cw/mod.c
59
src/cw/mod.c
@ -142,7 +142,7 @@ struct cw_actiondef *mod_cache_add(struct conn *conn, struct cw_Mod *c, struct c
|
|||||||
|
|
||||||
|
|
||||||
/* static mavl to store modules */
|
/* static mavl to store modules */
|
||||||
static struct mavl * modlist = NULL;
|
static struct mavl * mods_loaded = NULL;
|
||||||
static int mod_cmp(const void *e1, const void *e2){
|
static int mod_cmp(const void *e1, const void *e2){
|
||||||
struct cw_Mod * m1 = e1;
|
struct cw_Mod * m1 = e1;
|
||||||
struct cw_Mod * m2 = e2;
|
struct cw_Mod * m2 = e2;
|
||||||
@ -155,46 +155,36 @@ void cw_mod_set_mod_path(const char * path){
|
|||||||
mod_path = path;
|
mod_path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cw_mod_add(struct cw_Mod * mod ){
|
|
||||||
if (modlist == NULL){
|
|
||||||
modlist = mavl_create(mod_cmp,NULL);
|
|
||||||
if (modlist==NULL){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//mavl_add(modlist,modfn);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Load a module
|
* @brief Load a module
|
||||||
* @param path
|
* @param mod_name Name of the module
|
||||||
* @param mod_name
|
* @return a pointer to the module interface
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
struct cw_Mod * cw_mod_load(const char * mod_name){
|
struct cw_Mod * cw_mod_load(const char * mod_name){
|
||||||
|
|
||||||
|
|
||||||
/* if modlist is not initialized, initialize ... */
|
/* if modlist is not initialized, initialize ... */
|
||||||
if (modlist==NULL){
|
if (mods_loaded==NULL){
|
||||||
modlist=mavl_create(mod_cmp,NULL);
|
mods_loaded=mavl_create(mod_cmp,NULL);
|
||||||
if (modlist==NULL){
|
if (mods_loaded==NULL){
|
||||||
cw_log(LOG_ERROR, "Can't init modlist, no memory");
|
cw_log(LOG_ERROR, "Can't init modlist, no memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for the module in modlist, to see if it is
|
/* Search for the module in mods_loaded, to see if it is
|
||||||
* already loaded or was statically linked */
|
* already loaded or was statically linked */
|
||||||
struct cw_Mod search;
|
struct cw_Mod search;
|
||||||
memset(&search,0,sizeof(search));
|
memset(&search,0,sizeof(search));
|
||||||
search.name=mod_name;
|
search.name=mod_name;
|
||||||
struct cw_Mod * mod;
|
struct cw_Mod * mod;
|
||||||
mod = mavl_find(modlist,&search);
|
mod = mavl_find(mods_loaded,&search);
|
||||||
if (mod){
|
if (mod){
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(mod_name)>CW_MOD_MAX_MOD_NAME_LEN){
|
if (strlen(mod_name)>CW_MOD_MAX_MOD_NAME_LEN){
|
||||||
cw_log(LOG_ERROR,"Mod name too long: %s (max allowed = %d",
|
cw_log(LOG_ERROR,"Mod name too long: %s (max allowed = %d)",
|
||||||
mod_name,CW_MOD_MAX_MOD_NAME_LEN);
|
mod_name,CW_MOD_MAX_MOD_NAME_LEN);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -219,7 +209,7 @@ struct cw_Mod * cw_mod_load(const char * mod_name){
|
|||||||
|
|
||||||
struct cw_Mod * (*mod_get_interface)();
|
struct cw_Mod * (*mod_get_interface)();
|
||||||
|
|
||||||
mod_get_interface = dlsym(handle,"mod_get_interface");
|
mod_get_interface = dlsym(handle,mod_filename);
|
||||||
|
|
||||||
if (!mod_get_interface){
|
if (!mod_get_interface){
|
||||||
cw_log(LOG_ERROR,"Failed to load module: %s",dlerror());
|
cw_log(LOG_ERROR,"Failed to load module: %s",dlerror());
|
||||||
@ -227,8 +217,31 @@ struct cw_Mod * cw_mod_load(const char * mod_name){
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod = mod_get_interface();
|
mod = mod_get_interface();
|
||||||
|
mod->dll_handle=handle;
|
||||||
|
|
||||||
|
if (!mavl_add(mods_loaded,mod)){
|
||||||
|
dlclose(handle);
|
||||||
|
cw_log(LOG_ERR,"Can' add module %s",mod_name);
|
||||||
|
goto errX;
|
||||||
|
}
|
||||||
|
|
||||||
mod->init();
|
mod->init();
|
||||||
errX:
|
errX:
|
||||||
free(filename);
|
free(filename);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static struct mlist * mods_list = NULL;
|
||||||
|
|
||||||
|
struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod ){
|
||||||
|
if (!mods_list){
|
||||||
|
mods_list = mlist_create(mod_cmp);
|
||||||
|
if (!mods_list){
|
||||||
|
cw_log(LOG_ERROR,"Can't init mods_list");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mlist_append(mods_list,mod);
|
||||||
|
}
|
||||||
|
@ -92,6 +92,7 @@ extern int mod_caching;
|
|||||||
#define mod_get_caching() (mod_caching)
|
#define mod_get_caching() (mod_caching)
|
||||||
|
|
||||||
struct cw_Mod * cw_mod_load(const char * mod_name);
|
struct cw_Mod * cw_mod_load(const char * mod_name);
|
||||||
|
struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod );
|
||||||
|
|
||||||
#define CW_MOD_MAX_MOD_NAME_LEN 128
|
#define CW_MOD_MAX_MOD_NAME_LEN 128
|
||||||
#define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface"
|
#define CW_MOD_INTERFACE_FUNCTION_NAME_SUFFIX "_get_interface"
|
||||||
|
@ -22,9 +22,9 @@ OBJS=\
|
|||||||
LIBDIR := ../../../lib
|
LIBDIR := ../../../lib
|
||||||
LIBARCHDIR := $(LIBDIR)/$(ARCH)
|
LIBARCHDIR := $(LIBDIR)/$(ARCH)
|
||||||
OBJDIR := ../../../obj/mod_capwap/$(ARCH)
|
OBJDIR := ../../../obj/mod_capwap/$(ARCH)
|
||||||
SNAME := $(LIBARCHDIR)/libcapwap.a
|
SNAME := $(LIBARCHDIR)/libmod_capwap.a
|
||||||
DNAME := $(LIBARCHDIR)/capwap.so
|
DNAME := $(LIBARCHDIR)/mod_capwap.so
|
||||||
MODNAME := $(LIBDIR)/capwap.so
|
MODNAME := $(LIBDIR)/mod_capwap.so
|
||||||
SLIBS := -lcw
|
SLIBS := -lcw
|
||||||
|
|
||||||
include ../Mod.mak
|
include ../Mod.mak
|
||||||
|
@ -55,6 +55,6 @@ struct cw_Mod *mod_capwap_ac()
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct cw_Mod * mod_get_interface(){
|
struct cw_Mod * mod_capwap(){
|
||||||
return &capwap_ac;
|
return &capwap_ac;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user