]> git.webhop.me Git - lcd4linux.git/commitdiff
initialize plugin on first use
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 6 Jan 2009 06:46:50 +0000 (06:46 +0000)
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Tue, 6 Jan 2009 06:46:50 +0000 (06:46 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@944 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

plugin_kvv.c

index a1089c2d93474cb7f71a090464ebed05c70d870c..2291af1488c125566e27eac674d480d7a0ba0ab9 100644 (file)
@@ -642,10 +642,60 @@ static int kvv_fork(void)
     return 0;
 }
 
+static void kvv_start(void)
+{
+    static int started = 0;
+    int val;
+    char *p;
+
+
+    if (started)
+       return;
+
+    started = 1;
+
+    /* parse parameter */
+    if ((p = cfg_get(SECTION, "StationID", DEFAULT_STATION_ID)) != NULL) {
+       station_id = malloc(strlen(p) + 1);
+       strcpy(station_id, p);
+    }
+    info("[KVV] Using station %s", station_id);
+
+    if ((p = cfg_get(SECTION, "Proxy", NULL)) != NULL) {
+       proxy_name = malloc(strlen(p) + 1);
+       strcpy(proxy_name, p);
+       info("[KVV] Using proxy \"%s\"", proxy_name);
+    }
+
+    if (cfg_number(SECTION, "Port", 0, 0, 65535, &val) > 0) {
+       port = val;
+       info("[KVV] Using port %d", port);
+    } else {
+       info("[KVV] Using default port %d", port);
+    }
+
+    if (cfg_number(SECTION, "Refresh", 0, 0, 65535, &val) > 0) {
+       refresh = val;
+       info("[KVV] Using %d seconds refresh interval", refresh);
+    } else {
+       info("[KVV] Using default refresh interval of %d seconds", refresh);
+    }
+
+    if (cfg_number(SECTION, "Abbreviate", 0, 0, 65535, &val) > 0) {
+       abbreviate = val;
+       info("[KVV] Abbreviation enabled: %s", abbreviate ? "on" : "off");
+    } else {
+       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;
@@ -665,6 +715,8 @@ static void kvv_station(RESULT * result, RESULT * arg1)
 {
     int index = (int) R2N(arg1);
 
+    kvv_start();
+
     if (kvv_fork() != 0) {
        SetResult(&result, R_STRING, "");
        return;
@@ -689,6 +741,8 @@ 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;
@@ -708,6 +762,8 @@ 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;
@@ -728,49 +784,11 @@ static void kvv_time_str(RESULT * result, RESULT * arg1)
 /* plugin initialization */
 int plugin_init_kvv(void)
 {
-    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);
-
-    /* parse parameter */
-    if ((p = cfg_get(SECTION, "StationID", DEFAULT_STATION_ID)) != NULL) {
-       station_id = malloc(strlen(p) + 1);
-       strcpy(station_id, p);
-    }
-    info("[KVV] Using station %s", station_id);
-
-    if ((p = cfg_get(SECTION, "Proxy", NULL)) != NULL) {
-       proxy_name = malloc(strlen(p) + 1);
-       strcpy(proxy_name, p);
-       info("[KVV] Using proxy \"%s\"", proxy_name);
-    }
-
-    if (cfg_number(SECTION, "Port", 0, 0, 65535, &val) > 0) {
-       port = val;
-       info("[KVV] Using port %d", port);
-    } else {
-       info("[KVV] Using default port %d", port);
-    }
-
-    if (cfg_number(SECTION, "Refresh", 0, 0, 65535, &val) > 0) {
-       refresh = val;
-       info("[KVV] Using %d seconds refresh interval", refresh);
-    } else {
-       info("[KVV] Using default refresh interval of %d seconds", refresh);
-    }
-
-    if (cfg_number(SECTION, "Abbreviate", 0, 0, 65535, &val) > 0) {
-       abbreviate = val;
-       info("[KVV] Abbreviation enabled: %s", abbreviate ? "on" : "off");
-    } else {
-       info("[KVV] Default abbreviation setting: %s", abbreviate ? "on" : "off");
-    }
-
     return 0;
 }