Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 1bc1b688 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Reg update

parent 99593911
Branches
Aucune étiquette associée trouvée
1 requête de fusion!102Modules
Ce commit fait partie de la requête de fusion !102. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -6,14 +6,19 @@ struct lkt_state; ...@@ -6,14 +6,19 @@ struct lkt_state;
with a name that can be generated or red from a config file. */ with a name that can be generated or red from a config file. */
struct module_reg { struct module_reg {
const char *name; const char *name;
union {
void (*func)(void); void (*func)(void);
void *obj;
};
}; };
#define REG_EXPORT_NAME "__reg__"
#define REG_BEGIN(reg) struct module_reg reg[] = { #define REG_BEGIN(reg) struct module_reg reg[] = {
#define REG_ADD(__f) { .name = #__f, .func = (void(*)(void)) __f }, #define REG_ADD(f) { .name = #f, .func = (void(*)(void)) f },
#define REG_ADD_NAMED(__n, __f) { .name = __n, .func = (void(*)(void)) __f }, #define REG_ADD_NAMED(n, f) { .name = n, .func = (void(*)(void)) f },
#define REG_END() { .name = NULL, .func = NULL } }; #define REG_END() { .name = NULL, .func = NULL } };
/* Use only once per .so files or you will have some problems... */
#if ! defined(_STATIC_MODULES) #if ! defined(_STATIC_MODULES)
#define REG_EXPORT(__reg) struct module_reg *__reg__ = __reg; #define REG_EXPORT(__reg) struct module_reg *__reg__ = __reg;
#else #else
...@@ -29,10 +34,14 @@ void *reg_pick(const char *file, void **handle, const char *symbol); ...@@ -29,10 +34,14 @@ void *reg_pick(const char *file, void **handle, const char *symbol);
shared library with REG_EXPORT. Note that this reg is named `__reg__`, shared library with REG_EXPORT. Note that this reg is named `__reg__`,
thus no symbol must be named `__reg__` in the .so file. thus no symbol must be named `__reg__` in the .so file.
Returns 0 on success, something else on error. */ Returns 0 on success, something else on error. */
int reg_from_file(const char *file, struct module_reg *ret); int reg_from_file(const char *file, struct module_reg **ret, void **handle);
/* Set the __reg__ pointer. */
void reg_export(struct module_reg *reg);
/* Set the ref for this .a / .so file */ /* Get the object named with 'name' from the reg. Returns NULL on error
void reg_set(struct module_reg *); or 'not found'. */
void *__reg_get(struct module_reg *reg, const char *name);
/* Load a module by its name. Also initialize the mod pointer. No check on data /* Load a module by its name. Also initialize the mod pointer. No check on data
type is done, it is up to the user to check if the structure passed as a type is done, it is up to the user to check if the structure passed as a
......
...@@ -66,7 +66,7 @@ main(int argc, char *argv[]) ...@@ -66,7 +66,7 @@ main(int argc, char *argv[])
} }
normal_launch: normal_launch:
reg_set(server_reg); reg_export(server_reg);
mthread_init(); mthread_init();
pthread_create(&th, NULL, mthread_main, NULL); pthread_create(&th, NULL, mthread_main, NULL);
if (read_self_exe(exe, PATH_MAX)) if (read_self_exe(exe, PATH_MAX))
......
...@@ -608,11 +608,10 @@ kara_read_length(double *len, const char *filename) ...@@ -608,11 +608,10 @@ kara_read_length(double *len, const char *filename)
} else { } else {
if (mkv_read_element_length(&file, &elength) < 0) if (mkv_read_element_length(&file, &elength) < 0)
goto error; goto error;
if (bufferfd_skip(&file, elength) < 0) { if (bufferfd_skip(&file, elength) < 0)
goto error; goto error;
} }
} }
}
status_code = 0; status_code = 0;
error: error:
......
...@@ -10,12 +10,27 @@ ...@@ -10,12 +10,27 @@
#include <strings.h> #include <strings.h>
#include <stddef.h> #include <stddef.h>
struct module_reg *reg; struct module_reg *__reg__;
void
reg_export(struct module_reg *reg)
{
__reg__ = reg;
}
void * void *
reg_pick(const char *file, void **handle, const char *symbol) __reg_get(struct module_reg *reg, const char *name)
{ {
int i; int i;
for (i = 0; reg[i].name && reg[i].func; ++i)
if (STR_MATCH(reg[i].name, name))
return *(void **) &reg[i].func;
return NULL;
}
void *
reg_pick(const char *file, void **handle, const char *symbol)
{
if (!symbol) if (!symbol)
return NULL; return NULL;
...@@ -48,17 +63,7 @@ reg_pick(const char *file, void **handle, const char *symbol) ...@@ -48,17 +63,7 @@ reg_pick(const char *file, void **handle, const char *symbol)
/* Read the reg */ /* Read the reg */
use_reg: use_reg:
LOG_INFO("REG", "Using the reg structure to find %s", symbol); LOG_INFO("REG", "Using the reg structure to find %s", symbol);
for (i = 0; reg[i].name && reg[i].func; ++i) return __reg_get(__reg__, symbol);
if (STR_MATCH(reg[i].name, symbol))
return *(void **) &reg[i].func;
return NULL;
}
void
reg_set(struct module_reg *_reg)
{
reg = _reg;
} }
int int
...@@ -104,3 +109,9 @@ load_module_by_name(struct lkt_state *srv, const char *name, void *mod) ...@@ -104,3 +109,9 @@ load_module_by_name(struct lkt_state *srv, const char *name, void *mod)
return load_so(mod_path, mod_load, mod, srv); return load_so(mod_path, mod_load, mod, srv);
} }
int
reg_from_file(const char *file, struct module_reg **ret, void **handle)
{
*ret = reg_pick(file, handle, REG_EXPORT_NAME);
return *ret != NULL;
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter