Skip to content
Snippets Groups Projects
Commit 5613d864 authored by Ludovico de Nittis's avatar Ludovico de Nittis
Browse files

Merge branch 'wip/input-monitor-hotplug' into 'main'

input-monitor: Add --only-new option

See merge request !569
parents fa3b734a 1e7b9b0b
No related branches found
No related tags found
1 merge request!569input-monitor: Add --only-new option
......@@ -42,6 +42,7 @@
#define RECORD_SEPARATOR "\x1e"
static FILE *original_stdout = NULL;
static gboolean ignoring_initial_devices = FALSE;
static gboolean opt_one_line = FALSE;
static gboolean opt_seq = FALSE;
static gboolean opt_verbose = FALSE;
......@@ -181,8 +182,12 @@ added (SrtInputDeviceMonitor *monitor,
SrtInputDevice *dev,
void *user_data)
{
g_autoptr(JsonBuilder) builder = json_builder_new ();
g_autoptr(JsonBuilder) builder = NULL;
if (ignoring_initial_devices)
return;
builder = json_builder_new ();
json_builder_begin_object (builder);
{
json_builder_set_member_name (builder, "added");
......@@ -776,8 +781,12 @@ removed (SrtInputDeviceMonitor *monitor,
SrtInputDevice *dev,
void *user_data)
{
g_autoptr(JsonBuilder) builder = json_builder_new ();
g_autoptr(JsonBuilder) builder = NULL;
if (ignoring_initial_devices)
return;
builder = json_builder_new ();
json_builder_begin_object (builder);
{
json_builder_set_member_name (builder, "removed");
......@@ -805,6 +814,12 @@ all_for_now (SrtInputDeviceMonitor *source,
g_autoptr(SrtInputDeviceMonitor) monitor = NULL;
SrtInputDeviceMonitor **monitor_p = user_data;
if (ignoring_initial_devices)
{
ignoring_initial_devices = FALSE;
return;
}
if (srt_input_device_monitor_get_flags (source) & SRT_INPUT_DEVICE_MONITOR_FLAGS_ONCE)
{
monitor = g_steal_pointer (monitor_p);
......@@ -879,6 +894,8 @@ static const GOptionEntry option_entries[] =
{ "one-line", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_one_line,
"Print one device per line [default: pretty-print as concatenated JSON]",
NULL },
{ "only-new", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &ignoring_initial_devices,
"Don't print devices that are initially discovered", NULL },
{ "seq", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_seq,
"Output application/json-seq [default: pretty-print as concatenated JSON]",
NULL },
......@@ -908,6 +925,14 @@ run (int argc,
if (!g_option_context_parse (option_context, &argc, &argv, error))
return FALSE;
if (ignoring_initial_devices
&& (opt_flags & SRT_INPUT_DEVICE_MONITOR_FLAGS_ONCE) != 0)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
"Combining --only-new with --once is not useful");
return FALSE;
}
if (opt_print_version)
{
/* Output version number as YAML for machine-readability,
......@@ -947,6 +972,10 @@ run (int argc,
g_signal_connect (monitor, "removed", G_CALLBACK (removed), NULL);
g_signal_connect (monitor, "all-for-now", G_CALLBACK (all_for_now), &monitor);
if (ignoring_initial_devices && !(opt_one_line || opt_seq))
fputs ("{\"#\": \"devices that were already connected are not shown\"}\n",
original_stdout);
if (!srt_input_device_monitor_start (monitor, error))
return FALSE;
......
......@@ -42,6 +42,12 @@ steam-runtime-input-monitor - list input devices
readable indentation, which is convenient for a human reader but
less suitable for machine-readable use.
**--only-new**
: Do not show any of the input devices that would have been reported
by **--once**, only additional devices that are connected after that
initial enumeration.
The **--once** and **--only-new** options are mutually exclusive.
**--seq**
: Print events in **application/json-seq** format (RFC 7464):
each event is printed as U+001E RECORD SEPARATOR, followed by
......@@ -103,6 +109,9 @@ unknown keys to allow for future expansion.
: A device was removed. The value is an object with keys **dev_node**
and **sys_path**, as above.
**#**
: Informational messages which are not intended to be machine-readable.
# EXIT STATUS
0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment