initialize plugin on first use

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@944 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
michael
2009-01-06 06:46:50 +00:00
parent 90caf91c83
commit 68bf671bff
+108 -90
View File
@@ -642,100 +642,17 @@ static int kvv_fork(void)
return 0;
}
static void kvv_line(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (index < shm->entries) {
SetResult(&result, R_STRING, shm->entry[index].line);
} else
SetResult(&result, R_STRING, "");
mutex_unlock(mutex);
}
static void kvv_station(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (shm->error && index == 0)
SetResult(&result, R_STRING, "Server Err");
else {
if (index < shm->entries)
SetResult(&result, R_STRING, shm->entry[index].station);
else
SetResult(&result, R_STRING, "");
}
mutex_unlock(mutex);
}
static void kvv_time(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
double value = -1.0;
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (index < shm->entries)
value = shm->entry[index].time;
SetResult(&result, R_NUMBER, &value);
mutex_unlock(mutex);
}
static void kvv_time_str(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (index < shm->entries) {
char str[8];
sprintf(str, "%d", shm->entry[index].time);
SetResult(&result, R_STRING, str);
} else
SetResult(&result, R_STRING, "");
mutex_unlock(mutex);
}
/* plugin initialization */
int plugin_init_kvv(void)
static void kvv_start(void)
{
static int started = 0;
int val;
char *p;
/* register all our cool functions */
AddFunction("kvv::line", 1, kvv_line);
AddFunction("kvv::station", 1, kvv_station);
AddFunction("kvv::time", 1, kvv_time);
AddFunction("kvv::time_str", 1, kvv_time_str);
if (started)
return;
started = 1;
/* parse parameter */
if ((p = cfg_get(SECTION, "StationID", DEFAULT_STATION_ID)) != NULL) {
@@ -771,6 +688,107 @@ int plugin_init_kvv(void)
info("[KVV] Default abbreviation setting: %s", abbreviate ? "on" : "off");
}
}
static void kvv_line(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
kvv_start();
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (index < shm->entries) {
SetResult(&result, R_STRING, shm->entry[index].line);
} else
SetResult(&result, R_STRING, "");
mutex_unlock(mutex);
}
static void kvv_station(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
kvv_start();
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (shm->error && index == 0)
SetResult(&result, R_STRING, "Server Err");
else {
if (index < shm->entries)
SetResult(&result, R_STRING, shm->entry[index].station);
else
SetResult(&result, R_STRING, "");
}
mutex_unlock(mutex);
}
static void kvv_time(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
double value = -1.0;
kvv_start();
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (index < shm->entries)
value = shm->entry[index].time;
SetResult(&result, R_NUMBER, &value);
mutex_unlock(mutex);
}
static void kvv_time_str(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
kvv_start();
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
}
mutex_lock(mutex);
if (index < shm->entries) {
char str[8];
sprintf(str, "%d", shm->entry[index].time);
SetResult(&result, R_STRING, str);
} else
SetResult(&result, R_STRING, "");
mutex_unlock(mutex);
}
/* plugin initialization */
int plugin_init_kvv(void)
{
/* register all our cool functions */
AddFunction("kvv::line", 1, kvv_line);
AddFunction("kvv::station", 1, kvv_station);
AddFunction("kvv::time", 1, kvv_time);
AddFunction("kvv::time_str", 1, kvv_time_str);
return 0;
}