src/utils_cmd_listval.[ch]: Added a new module which implements the `LISTVAL' command.
authorFlorian Forster <octo@huhu.verplant.org>
Mon, 24 Mar 2008 10:29:46 +0000 (11:29 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Mon, 24 Mar 2008 10:29:46 +0000 (11:29 +0100)
It's done using the global cache implemented in `src/utils_cache.[ch]'.

src/Makefile.am
src/utils_cmd_listval.c [new file with mode: 0644]
src/utils_cmd_listval.h [new file with mode: 0644]

index 194e118..618ef0a 100644 (file)
@@ -597,6 +597,7 @@ pkglib_LTLIBRARIES += unixsock.la
 unixsock_la_SOURCES = unixsock.c \
                      utils_cmd_flush.h utils_cmd_flush.c \
                      utils_cmd_getval.h utils_cmd_getval.c \
+                     utils_cmd_listval.h utils_cmd_listval.c \
                      utils_cmd_putval.h utils_cmd_putval.c \
                      utils_cmd_putnotif.h utils_cmd_putnotif.c
 unixsock_la_LDFLAGS = -module -avoid-version -lpthread
diff --git a/src/utils_cmd_listval.c b/src/utils_cmd_listval.c
new file mode 100644 (file)
index 0000000..644a67c
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * collectd - src/utils_cms_listval.c
+ * Copyright (C) 2008  Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ * Author:
+ *   Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include "utils_cmd_listval.h"
+#include "utils_cache.h"
+
+int handle_listval (FILE *fh, char **fields, int fields_num)
+{
+  char **names = NULL;
+  time_t *times = NULL;
+  size_t number = 0;
+  size_t i;
+  int status;
+
+  if (fields_num != 1)
+  {
+    DEBUG ("command listval: us_handle_listval: Wrong number of fields: %i",
+       fields_num);
+    fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1.\n",
+       fields_num);
+    fflush (fh);
+    return (-1);
+  }
+
+  status = uc_get_names (&names, &times, &number);
+  if (status != 0)
+  {
+    DEBUG ("command listval: uc_get_names failed with status %i", status);
+    fprintf (fh, "-1 uc_get_names failed.\n");
+    fflush (fh);
+    return (-1);
+  }
+
+  fprintf (fh, "%i Values found\n", (int) number);
+  for (i = 0; i < number; i++)
+    fprintf (fh, "%u %s\n", (unsigned int) times[i], names[i]);
+  fflush (fh);
+
+  return (0);
+} /* int handle_listval */
+
+/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/utils_cmd_listval.h b/src/utils_cmd_listval.h
new file mode 100644 (file)
index 0000000..c918796
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * collectd - src/utils_cms_listval.h
+ * Copyright (C) 2008  Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ * Author:
+ *   Florian octo Forster <octo at verplant.org>
+ **/
+
+#ifndef UTILS_CMD_LISTVAL_H
+#define UTILS_CMD_LISTVAL_H 1
+
+int handle_listval (FILE *fh, char **fields, int fields_num);
+
+#endif /* UTILS_CMD_LISTVAL_H */
+
+/* vim: set sw=2 sts=2 ts=8 : */