// Output
FILE* f;
+
+ // Dimensions
+ struct {
+ uint64_t h;
+ uint64_t w;
+ } dimensions;
} collecty_client_ctx;
enum {
OPT_FORMAT = 1,
+ OPT_HEIGHT = 2,
+ OPT_WIDTH = 3,
};
static struct argp_option options[] = {
{ "format", OPT_FORMAT, "FORMAT", 0, "Output Format", 0 },
+ { "height", OPT_HEIGHT, "PIXELS", 0, "Height of the output image", 1 },
+ { "width", OPT_WIDTH, "PIXELS", 0, "Width of the output image", 1 },
{ NULL },
};
static error_t parse(int key, char* arg, struct argp_state* state) {
collecty_client_ctx* ctx = state->input;
+ char* p = NULL;
switch (key) {
case OPT_FORMAT:
ctx->format = arg;
break;
+ case OPT_HEIGHT:
+ ctx->dimensions.h = strtoul(arg, &p, 10);
+
+ // Fail if we could not parse the height
+ if (ctx->dimensions.h == ULONG_MAX || *p)
+ argp_error(state, "Invalid value for --height: %s", arg);
+
+ break;
+
+ case OPT_WIDTH:
+ ctx->dimensions.w = strtoul(arg, &p, 10);
+
+ // Fail if we could not parse the height
+ if (ctx->dimensions.w == ULONG_MAX || *p)
+ argp_error(state, "Invalid value for --width: %s", arg);
+
+ break;
+
// Called for each argument
case ARGP_KEY_ARG:
// Take the graph name as first argument
goto ERROR;
}
+ // Send the desired height
+ if (ctx->dimensions.h) {
+ r = sd_bus_message_append(m, "{sv}", "height", "t", ctx->dimensions.h);
+ if (r < 0)
+ goto ERROR;
+ }
+
+ // Send the desired width
+ if (ctx->dimensions.w) {
+ r = sd_bus_message_append(m, "{sv}", "width", "t", ctx->dimensions.w);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Close the array
r = sd_bus_message_close_container(m);
if (r < 0)
if (r < 0)
goto ERROR;
- // Parse the values
+ // Parse "format"
if (strcmp(key, "format") == 0) {
r = sd_bus_message_read(m, "v", "s", &options.format);
if (r < 0)
goto ERROR;
+
+ // Parse "height"
+ } else if (strcmp(key, "height") == 0) {
+ r = sd_bus_message_read(m, "v", "t", &options.dimensions.h);
+ if (r < 0)
+ goto ERROR;
+
+ // Parse "width"
+ } else if (strcmp(key, "width") == 0) {
+ r = sd_bus_message_read(m, "v", "t", &options.dimensions.w);
+ if (r < 0)
+ goto ERROR;
}
// Leave the container
NULL,
};
+const unsigned int DEFAULT_HEIGHT = 480;
+const unsigned int DEFAULT_WIDTH = 960;
+
static void collecty_graph_free(collecty_graph* self) {
if (self->daemon)
collecty_daemon_unref(self->daemon);
goto ERROR;
}
+ // Configure the desired output height
+ r = collecty_args_push(args, "--height=%u",
+ (options->dimensions.h) ? options->dimensions.h : DEFAULT_HEIGHT);
+ if (r < 0)
+ goto ERROR;
+
+ // Configure the desired output width
+ r = collecty_args_push(args, "--width=%u",
+ (options->dimensions.w) ? options->dimensions.w : DEFAULT_WIDTH);
+ if (r < 0)
+ goto ERROR;
+
// Write the graph to the output stream
r = collecty_args_push(args, "-");
if (r < 0)