X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fonewire.c;h=cae0d63d4c22f529aab642a3e3f6dd37e8195fb4;hb=0bd574a28c06090f0c4b056f8a78e455455a6330;hp=77fe08ca23a582c698507572d13d54a5b32a1eb6;hpb=5b8102adb3d8d11a9c1e02081cc228101de80064;p=collectd.git diff --git a/src/onewire.c b/src/onewire.c index 77fe08ca..cae0d63d 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -59,13 +59,14 @@ static ow_family_features_t ow_family_features[] = static int ow_family_features_num = STATIC_ARRAY_SIZE (ow_family_features); static char *device_g = NULL; +static int ow_interval = 0; static const char *config_keys[] = { - "Alias", "Device", "IgnoreSelected", "Sensor", + "Interval" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -88,9 +89,7 @@ static int cow_load_config (const char *key, const char *value) else if (strcasecmp (key, "IgnoreSelected") == 0) { ignorelist_set_invert (sensor_list, 1); - if ((strcasecmp (value, "True") == 0) - || (strcasecmp (value, "Yes") == 0) - || (strcasecmp (value, "On") == 0)) + if (IS_TRUE (value)) ignorelist_set_invert (sensor_list, 0); } else if (strcasecmp (key, "Device") == 0) @@ -105,9 +104,14 @@ static int cow_load_config (const char *key, const char *value) sfree (device_g); device_g = temp; } - else if (strcasecmp (key, "Alias") == 0) + else if (strcasecmp ("Interval", key) == 0) { - /* azogtodo alias-list */ + int tmp; + tmp = atoi (value); + if (tmp > 0) + ow_interval = tmp; + else + ERROR ("onewire plugin: Invalid `Interval' setting: %s", value); } else { @@ -117,26 +121,6 @@ static int cow_load_config (const char *key, const char *value) return (0); } -static int cow_init (void) -{ - int status; - - if (device_g == NULL) - { - ERROR ("onewire plugin: cow_init: No device configured."); - return (-1); - } - - status = (int) OW_init (device_g); - if (status != 0) - { - ERROR ("onewire plugin: OW_init(%s) failed: %i.", device_g, status); - return (1); - } - - return (0); -} /* int cow_init */ - static int cow_read_values (const char *path, const char *name, const ow_family_features_t *family_info) { @@ -154,7 +138,6 @@ static int cow_read_values (const char *path, const char *name, vl.values = values; vl.values_len = 1; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin)); @@ -293,7 +276,7 @@ static int cow_read_bus (const char *path) return (0); } /* int cow_read_bus */ -static int cow_read (void) +static int cow_read (user_data_t *ud __attribute__((unused))) { return (cow_read_bus ("/")); } /* int cow_read */ @@ -305,11 +288,38 @@ static int cow_shutdown (void) return (0); } /* int cow_shutdown */ +static int cow_init (void) +{ + int status; + struct timespec cb_interval; + + if (device_g == NULL) + { + ERROR ("onewire plugin: cow_init: No device configured."); + return (-1); + } + + status = (int) OW_init (device_g); + if (status != 0) + { + ERROR ("onewire plugin: OW_init(%s) failed: %i.", device_g, status); + return (1); + } + + memset (&cb_interval, 0, sizeof (cb_interval)); + if (ow_interval > 0) + cb_interval.tv_sec = (time_t) ow_interval; + + plugin_register_complex_read ("onewire", cow_read, + &cb_interval, /* user data = */ NULL); + plugin_register_shutdown ("onewire", cow_shutdown); + + return (0); +} /* int cow_init */ + void module_register (void) { plugin_register_init ("onewire", cow_init); - plugin_register_read ("onewire", cow_read); - plugin_register_shutdown ("onewire", cow_shutdown); plugin_register_config ("onewire", cow_load_config, config_keys, config_keys_num); }