wireless plugin: Correct the handling of cards returning signal and noise quality...
[collectd.git] / src / plugin.c
index be28671..d708b6b 100644 (file)
@@ -34,6 +34,7 @@ typedef struct plugin
        void (*init) (void);
        void (*read) (void);
        void (*write) (char *host, char *inst, char *val);
+       void (*shutdown) (void);
        struct plugin *next;
 } plugin_t;
 
@@ -276,16 +277,29 @@ void plugin_init_all (void)
 /*
  * Call `read' on all plugins (if given)
  */
-void plugin_read_all (void)
+void plugin_read_all (const int *loop)
 {
        plugin_t *p;
 
-       for (p = first_plugin; p != NULL; p = p->next)
+       for (p = first_plugin; (*loop == 0) && (p != NULL); p = p->next)
                if (p->read != NULL)
                        (*p->read) ();
 }
 
 /*
+ * Call `shutdown' on all plugins (if given)
+ */
+void plugin_shutdown_all (void)
+{
+       plugin_t *p;
+
+       for (p = first_plugin; NULL != p; p = p->next)
+               if (NULL != p->shutdown)
+                       (*p->shutdown) ();
+       return;
+}
+
+/*
  * Add plugin to the linked list of registered plugins.
  */
 void plugin_register (char *type,
@@ -317,11 +331,27 @@ void plugin_register (char *type,
        p->read  = read;
        p->write = write;
 
+       p->shutdown = NULL;
+
        p->next = first_plugin;
        first_plugin = p;
 }
 
 /*
+ * Register the shutdown function (optional).
+ */
+int plugin_register_shutdown (char *type, void (*shutdown) (void))
+{
+       plugin_t *p = plugin_search (type);
+
+       if (NULL == p)
+               return -1;
+
+       p->shutdown = shutdown;
+       return 0;
+}
+
+/*
  * Send received data back to the plugin/module which will append DS
  * definitions and pass it on to ``rrd_update_file''.
  */
@@ -345,6 +375,18 @@ void plugin_write (char *host, char *type, char *inst, char *val)
  */
 void plugin_submit (char *type, char *inst, char *val)
 {
+       if (inst == NULL)
+               inst = "-";
+
+       if ((type == NULL) || (val == NULL))
+       {
+               DBG ("Help! NULL-pointer! type = %s; inst = %s; val = %s;",
+                               (type == NULL) ? "(null)" : type,
+                               inst,
+                               (val == NULL) ? "(null)" : val);
+               return;
+       }
+
         if (operating_mode == MODE_CLIENT)
                network_send (type, inst, val);
        else