#include #include #include #include "nfcommander.h" #include "reader.h" #include "config.h" #define MAX_PLUGIN_PATH NAME_MAX void* reader_module = NULL; reader_plugin_handle reader_backend_handle = NULL; int reader_init(){ char plugin[MAX_PLUGIN_PATH] = ""; char* reader = config_get("nfc", "reader"); if(!reader){ printf("No reader plugin configured\n"); return -1; } snprintf(plugin, sizeof(plugin), "./reader_%s.so", reader); reader_module = dlopen(plugin, RTLD_NOW); if(!reader_module){ printf("Failed to load reader plugin %s: %s\n", plugin, dlerror()); return -1; } reader_backend_handle = dlsym(reader_module, "handle"); //call initializer reader_plugin_init init = dlsym(reader_module, "init"); if(!reader_backend_handle || !init || init()){ printf("Failed to initialize the reader\n"); return 1; } return 0; } int reader_handle(int fd){ return reader_backend_handle(fd); } void reader_free(){ if(reader_module){ dlclose(reader_module); reader_backend_handle = NULL; reader_module = NULL; } }