#include <string.h>
void devforge_add_mod(void* lib) {
- void** old_mods = loaded_mods;
+ struct devforge_mod** old_mods = loaded_mods;
int i;
for(i = 0; old_mods[i] != NULL; i++)
;
for(i = 0; old_mods[i] != NULL; i++) {
loaded_mods[i] = old_mods[i];
}
- loaded_mods[i] = lib;
+ loaded_mods[i] = malloc(sizeof(**loaded_mods));
+ loaded_mods[i]->lib = lib;
loaded_mods[i + 1] = NULL;
free(old_mods);
}
#define __DEVFORGE_DF_CONFIG_H__
#include <stddef.h>
+#include <sys/types.h>
int devforge_load_config(const char* path);
int devforge_create_config(const char* path);
+struct devforge_mod {
+ void* lib;
+ pid_t pid;
+};
+
#ifdef DF_CONFIG_SRC
#define DF_CONFIG_PREFIX
#else
#endif
;
-DF_CONFIG_PREFIX void** loaded_mods
+DF_CONFIG_PREFIX struct devforge_mod** loaded_mods
#ifdef DF_CONFIG_SRC
= NULL
#endif
if(loaded_mods != NULL) {
int i;
for(i = 0; loaded_mods[i] != NULL; i++) {
- const char* type = (const char*)dlsym(loaded_mods[i], "mod_type");
+ const char* type = (const char*)dlsym(loaded_mods[i]->lib, "mod_type");
if(strcmp(type, DF_MOD_LOG) == 0) {
- void (*mod_log)(const char*, const char*) = (void (*)(const char*, const char*))dlsym(loaded_mods[i], "mod_log");
+ void (*mod_log)(const char*, const char*) = (void (*)(const char*, const char*))dlsym(loaded_mods[i]->lib, "mod_log");
if(mod_log != NULL) {
fallback = false;
mod_log(name, log);
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include <dlfcn.h>
int main(int argc, char** argv) {
int i;
if(ret != 0) return ret;
}
devforge_log(DF_INFO, "Hello World, initialization done");
+ if(loaded_mods != NULL){
+ devforge_log(DF_INFO, "Starting server");
+ int i;
+ bool loaded_srv = false;
+ for(i = 0; loaded_mods[i] != NULL; i++){
+ const char* type = (const char*)dlsym(loaded_mods[i]->lib, "mod_type");
+ if(type != NULL){
+ if(strcmp(type, DF_MOD_SRV) == 0){
+ loaded_srv = true;
+ }
+ }
+ }
+ if(loaded_srv) return 0;
+ }
+ devforge_log(DF_ERROR, "Server module was not loaded!");
}