File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / dl.c
Revision 1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Wed Nov 23 00:42:16 2011 UTC (12 years, 7 months ago) by misho
Branches: mqtt1_0
add many code
- db* funcs
- rtlm handling
- new files

#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));
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>