summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 29b74c4)
raw | patch | inline | side by side (parent: 29b74c4)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 18 Aug 2010 14:21:43 +0000 (16:21 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 18 Aug 2010 14:21:43 +0000 (16:21 +0200) |
src/Makefile.am | patch | blob | history | |
src/collectd-tg.c | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index 24d3c348c2acc976ef430c2f733463e72d4f9ef0..d5fdc1e1b03a37c01a28312f34e032a42d9dbf5c 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collectdctl_LDADD += libcollectdclient/libcollectdclient.la
collectdctl_DEPENDENCIES = libcollectdclient/libcollectdclient.la
-collectd_tg_SOURCES = collectd-tg.c
+collectd_tg_SOURCES = collectd-tg.c \
+ utils_heap.c utils_heap.h
collectd_tg_LDADD =
if BUILD_WITH_LIBSOCKET
collectd_tg_LDADD += -lsocket
diff --git a/src/collectd-tg.c b/src/collectd-tg.c
index c5e15194050d0201be8f295f80b54ecd04255903..5b31cc9d13a423e4b66a2384a0581177e221943b 100644 (file)
--- a/src/collectd-tg.c
+++ b/src/collectd-tg.c
#include <string.h>
#include <time.h>
+#include "utils_heap.h"
+
#include "libcollectdclient/collectd/client.h"
#include "libcollectdclient/collectd/network.h"
#include "libcollectdclient/collectd/network_buffer.h"
static lcc_network_t *net;
-static lcc_value_list_t **values;
-static size_t values_num;
+static c_heap_t *values_heap = NULL;
static int compare_time (const void *v0, const void *v1) /* {{{ */
{
int main (int argc, char **argv) /* {{{ */
{
- size_t i;
+ int i;
+
+ values_heap = c_heap_create (compare_time);
+ if (values_heap == NULL)
+ {
+ fprintf (stderr, "c_heap_create failed.\n");
+ exit (EXIT_FAILURE);
+ }
net = lcc_network_create ();
if (net == NULL)
}
lcc_server_set_ttl (srv, 42);
- }
-
- values_num = (size_t) conf_num_values;
- values = calloc (values_num, sizeof (*values));
- if (values == NULL)
- {
- fprintf (stderr, "calloc failed.\n");
- exit (EXIT_FAILURE);
+#if 0
+ lcc_server_set_security_level (srv, ENCRYPT,
+ "admin", "password1");
+#endif
}
fprintf (stdout, "Creating %i values ... ", conf_num_values);
fflush (stdout);
- for (i = 0; i < values_num; i++)
+ for (i = 0; i < conf_num_values; i++)
{
- values[i] = create_value_list ();
- if (values[i] == NULL)
+ lcc_value_list_t *vl;
+
+ vl = create_value_list ();
+ if (vl == NULL)
{
fprintf (stderr, "create_value_list failed.\n");
exit (EXIT_FAILURE);
}
+
+ c_heap_insert (values_heap, vl);
}
fprintf (stdout, "done\n");
- fprintf (stdout, "Sorting values by time ... ");
- fflush (stdout);
- qsort (values, values_num, sizeof (*values), compare_time);
- fprintf (stdout, "done\n");
+ while (42)
+ {
+ lcc_value_list_t *vl = c_heap_get_root (values_heap);
- for (i = 0; i < values_num; i++)
- send_value (values[i]);
+ if (vl == NULL)
+ break;
+
+ send_value (vl);
+ destroy_value_list (vl);
+ }
- for (i = 0; i < values_num; i++)
- destroy_value_list (values[i]);
- free (values);
+ c_heap_destroy (values_heap);
lcc_network_destroy (net);
exit (EXIT_SUCCESS);