#############################################################################*/
#include <errno.h>
+#include <limits.h>
#include <stdlib.h>
#include <rrd.h>
const unsigned int DEFAULT_HEIGHT = 480;
const unsigned int DEFAULT_WIDTH = 960;
+static int collecty_graph_check(collecty_graph* self) {
+ // Check if upper and lower limits are set (at least one must be set)
+ if (!self->impl->lower_limit && !self->impl->upper_limit) {
+ ERROR(self->ctx, "lower_limit and upper_limit are not set\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static void collecty_graph_free(collecty_graph* self) {
if (self->daemon)
collecty_daemon_unref(self->daemon);
int collecty_graph_create(collecty_graph** graph,
collecty_ctx* ctx, collecty_daemon* daemon, const collecty_graph_impl* impl) {
collecty_graph* self = NULL;
+ int r;
// Allocate some memory
self = calloc(1, sizeof(*self));
// Store the implementation
self->impl = impl;
+ // Perform some basic checks
+ r = collecty_graph_check(self);
+ if (r < 0)
+ goto ERROR;
+
// Return the pointer
*graph = self;
return 0;
+
+ERROR:
+ if (self)
+ collecty_graph_unref(self);
+
+ return r;
}
collecty_graph* collecty_graph_ref(collecty_graph* self) {
if (r < 0)
goto ERROR;
+ // Set lower limit
+ if (self->impl->lower_limit > -LONG_MAX) {
+ r = collecty_args_push(args, "--lower-limit=%ld", self->impl->lower_limit);
+ if (r < 0)
+ goto ERROR;
+ }
+
+ // Set upper limit
+ if (self->impl->upper_limit < LONG_MAX) {
+ r = collecty_args_push(args, "--upper-limit=%ld", self->impl->upper_limit);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Write the graph to the output stream
r = collecty_args_push(args, "-");
if (r < 0)