|
|
| version 1.1, 2011/11/23 00:42:16 | version 1.1.2.1, 2011/11/23 00:42:16 |
|---|---|
| Line 0 | Line 1 |
| #include "global.h" | |
| #include "rtlm.h" | |
| static void *acc_rtlm, *pub_rtlm; | |
| /* | |
| * mqttLog() Log message to syslog | |
| * | |
| * @fmt = format string | |
| * @... = argument list | |
| * return: none | |
| */ | |
| void | |
| mqttLog(const char *fmt, ...) | |
| { | |
| va_list lst; | |
| va_start(lst, fmt); | |
| vsyslog(LOG_ERR, fmt, lst); | |
| va_end(lst); | |
| } | |
| void * | |
| mqttLoadRTLM(sl_config *cfg, int modtype) | |
| { | |
| char *str; | |
| void *rtlm = NULL; | |
| if (!cfg) | |
| return NULL; | |
| str = CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG(modtype ? "pub_file" : "acc_file"))); | |
| if (!str) { | |
| mqttLog("Error:: RTL module not found\n"); | |
| return NULL; | |
| } | |
| rtlm = dlopen(str, RTLD_LAZY); | |
| if (!rtlm) { | |
| mqttLog("Error:: RTL module not found %s\n", dlerror()); | |
| return NULL; | |
| } | |
| mqttOpenDB = dlsym(rtlm, "mqtt_db_open"); | |
| if (!mqttOpenDB) { | |
| mqttLog("Error:: Can't found mqtt_db_open call\n"); | |
| dlclose(rtlm); | |
| return NULL; | |
| } | |
| mqttCloseDB = dlsym(rtlm, "mqtt_db_close"); | |
| if (!mqttCloseDB) { | |
| mqttLog("Error:: Can't found mqtt_db_close call\n"); | |
| dlclose(rtlm); | |
| return NULL; | |
| } | |
| if (modtype) { | |
| pub_rtlm = rtlm; | |
| } else { | |
| acc_rtlm = rtlm; | |
| } | |
| return rtlm; | |
| } | |
| void | |
| mqttUnloadRTLM(int modtype) | |
| { | |
| dlclose((modtype ? pub_rtlm : acc_rtlm)); | |
| } |