src/graph_instance.[ch]: Implement "inst_data_to_json".
[collection4.git] / src / dp_rrdtool.c
index 214603d..f90b79e 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "graph_types.h"
 #include "graph_ident.h"
-#include "graph_list.h"
 #include "data_provider.h"
 #include "filesystem.h"
 #include "oconfig.h"
@@ -285,6 +284,9 @@ static int get_ident_data (void *priv,
   unsigned long data_index;
   unsigned long data_length;
 
+  dp_data_point_t *dp = NULL;
+  size_t dp_num = 0;
+
   status = ident_to_rrdfile (ident, config, filename, sizeof (filename));
   if (status != 0)
     return (status);
@@ -309,6 +311,7 @@ static int get_ident_data (void *priv,
     free (ds_namv[i]);            \
   free (ds_namv);                 \
   free (data);                    \
+  free (dp);                      \
   return (ret_status);            \
 } while (0)
 
@@ -322,21 +325,24 @@ static int get_ident_data (void *priv,
   /* Number of data points returned. */
   data_length = (rrd_end - rrd_start) / step;
 
+  dp_num = (size_t) data_length;
+  dp = calloc (dp_num, sizeof (*dp));
+  if (dp == NULL)
+    BAIL_OUT (ENOMEM);
+
   for (data_index = 0; data_index < data_length; data_index++)
   {
-    dp_data_point_t dp;
     unsigned long index = (ds_count * data_index) + ds_index;
 
-    memset (&dp, 0, sizeof (dp));
-    dp.time.tv_sec = rrd_start + (data_index * step);
-    dp.time.tv_nsec = 0;
-    dp.value = (double) data[index];
-
-    status = (*cb) (ident, ds_name, &dp, ud);
-    if (status != 0)
-      BAIL_OUT (status);
+    dp[data_index].time.tv_sec = rrd_start + (data_index * step);
+    dp[data_index].time.tv_nsec = 0;
+    dp[data_index].value = (double) data[index];
   }
 
+  status = (*cb) (ident, ds_name, dp, dp_num, ud);
+  if (status != 0)
+    BAIL_OUT (status);
+
   BAIL_OUT (0);
 #undef BAIL_OUT
 } /* }}} int get_ident_data */
@@ -351,7 +357,7 @@ static int print_graph (void *priv,
   return (-1);
 } /* }}} int print_graph */
 
-int dp_rrdtool_config (oconfig_item_t *ci)
+int dp_rrdtool_config (const oconfig_item_t *ci)
 { /* {{{ */
   dp_rrdtool_t *conf;
 
@@ -371,7 +377,7 @@ int dp_rrdtool_config (oconfig_item_t *ci)
 
   dp.private_data = conf;
 
-  gl_register_data_provider ("rrdtool", &dp);
+  data_provider_register ("rrdtool", &dp);
 
   return (0);
 } /* }}} int dp_rrdtool_config */