mirror of
https://git.sr.ht/~leon_plickat/wlopm
synced 2024-12-25 13:08:21 +01:00
Use function for json error messages
This commit is contained in:
parent
fec8a5db3d
commit
ec680722d4
33
wlopm.c
33
wlopm.c
@ -201,6 +201,17 @@ static char *power_mode_to_string (enum zwlr_output_power_v1_mode mode)
|
||||
return mode == ZWLR_OUTPUT_POWER_V1_MODE_ON ? "on" : "off";
|
||||
}
|
||||
|
||||
static void print_json_error (const char *output_name, const char *msg)
|
||||
{
|
||||
fprintf(stdout,
|
||||
"%s\n {\n"
|
||||
" \"output\": \"%s\",\n"
|
||||
" \"error\": \"%s\"\n"
|
||||
" }",
|
||||
json_prev ? "," : "", output_name, msg);
|
||||
json_prev = true;
|
||||
}
|
||||
|
||||
static void do_operation (struct Operation *operation)
|
||||
{
|
||||
if ( *operation->name == '*' )
|
||||
@ -215,16 +226,7 @@ static void do_operation (struct Operation *operation)
|
||||
if ( output == NULL )
|
||||
{
|
||||
if (json)
|
||||
{
|
||||
fprintf(stdout,
|
||||
"%s\n {\n"
|
||||
" \"output\": \"%s\",\n"
|
||||
" \"error\": \"output does not exist\"\n"
|
||||
" }",
|
||||
json_prev ? "," : "",
|
||||
operation->name);
|
||||
json_prev = true;
|
||||
}
|
||||
print_json_error(operation->name, "output does not exist");
|
||||
else
|
||||
fprintf(stderr, "ERROR: Output '%s' does not exist.\n",
|
||||
operation->name);
|
||||
@ -338,16 +340,7 @@ static void sync_handle_done (void *data, struct wl_callback *wl_callback, uint3
|
||||
if (output->operation_failed)
|
||||
{
|
||||
if (json)
|
||||
{
|
||||
fprintf(stdout,
|
||||
"%s\n {\n"
|
||||
" \"output\": \"%s\","
|
||||
" \"error\": \"setting power mode failed\"\n"
|
||||
" }",
|
||||
json_prev ? "," : "",
|
||||
output->name);
|
||||
json_prev = true;
|
||||
}
|
||||
print_json_error(output->name, "setting power mode failed");
|
||||
else
|
||||
fprintf(stderr, "ERROR: Setting power mode for output '%s' failed.\n",
|
||||
output->name);
|
||||
|
Loading…
Reference in New Issue
Block a user