typedef struct td_client_ctx {
enum {
- // Enables debugging output
- DEBUG = (1 << 0),
+ OMIT_TITLE = (1 << 0),
} flags;
// DBus
} td_client_ctx;
enum {
- OPT_FORMAT = 1,
- OPT_HEIGHT = 2,
- OPT_WIDTH = 3,
- OPT_SINCE = 4,
- OPT_UNTIL = 5,
+ OPT_FORMAT = 1,
+ OPT_HEIGHT = 2,
+ OPT_WIDTH = 3,
+ OPT_SINCE = 4,
+ OPT_UNTIL = 5,
+ OPT_OMIT_TITLE = 6,
};
static struct argp_option options[] = {
// Time
{ "since", OPT_SINCE, "TIMESTAMP", 0, "Start the graph from the specified date", 0 },
{ "until", OPT_UNTIL, "TIMESTAMP", 0, "End the graph at the specified date", 0 },
+
+ // Flags
+ { "omit-title", OPT_OMIT_TITLE, NULL, 0, "Omit the title in the graph image", 0},
{ NULL },
};
ctx->interval.until = arg;
break;
+ case OPT_OMIT_TITLE:
+ ctx->flags |= OMIT_TITLE;
+ break;
+
// Called for each argument
case ARGP_KEY_ARG:
// Take the graph name as first argument
goto ERROR;
}
+ // Omit the title?
+ if (ctx->flags & OMIT_TITLE) {
+ r = sd_bus_message_append(m, "{sv}", "omit-title", "b", 1);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Close the array
r = sd_bus_message_close_container(m);
if (r < 0)
const char* since = NULL;
const char* until = NULL;
+ // Flags
+ int omit_title = 0;
+
// Open the options array
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
if (r < 0)
SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", until);
goto ERROR;
}
+
+ // Parse "omit-title"
+ } else if (td_string_equals(key, "omit-title")) {
+ r = sd_bus_message_read(m, "v", "b", &omit_title);
+ if (r < 0)
+ goto ERROR;
+
+ if (omit_title)
+ options.flags |= TD_GRAPH_OMIT_TITLE;
}
// Leave the container
return r;
}
+static int td_graph_render_title(td_graph* self, const char* object,
+ const td_graph_render_options* options, td_args* args) {
+ char title[TITLE_MAX] = "";
+ int r;
+
+ // Don't render the title if requested to omit
+ if (options->flags & TD_GRAPH_OMIT_TITLE)
+ return 0;
+
+ // Call the implementation
+ if (self->impl->title) {
+ // Fetch the title
+ r = self->impl->title(self->ctx, self, object, title, sizeof(title));
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r));
+ return r;
+ }
+
+ // Add the title to the command line
+ if (*title) {
+ r = td_args_push(args, "--title=%s", title);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ return 0;
+}
+
int td_graph_render(td_graph* self, const char* object,
const td_graph_render_options* options, char** buffer, size_t* length) {
td_args* args = NULL;
char vlabel[VLABEL_MAX] = "";
- char title[TITLE_MAX] = "";
char** data = NULL;
FILE* f = NULL;
int w = 0;
}
// Set the title
- if (self->impl->title) {
- // Fetch the title
- r = self->impl->title(self->ctx, self, object, title, sizeof(title));
- if (r < 0) {
- ERROR(self->ctx, "Failed to render the title: %s\n", strerror(-r));
- goto ERROR;
- }
-
- // Add the title to the command line
- if (*title) {
- r = td_args_push(args, "--title=%s", title);
- if (r < 0)
- goto ERROR;
- }
- }
+ r = td_graph_render_title(self, object, options, args);
+ if (r < 0)
+ goto ERROR;
// Set the vertical label
if (self->impl->vlabel) {
time_t t_start;
time_t t_end;
} interval;
+
+ // Flags
+ enum {
+ TD_GRAPH_OMIT_TITLE = (1 << 0),
+ } flags;
} td_graph_render_options;
int td_graph_render(td_graph* self, const char* object,