mirror of
https://github.com/albfan/miraclecast.git
synced 2025-02-12 16:41:59 +00:00
miracled: send ScanStopped events
We should notify miraclectl about ScanStopped events so we can correctly track active scans. If we don't do that, we would have to explicitly track it on connect/disconnect/etc. commands, which seems cumbersome given the undeterminisc actions they cause. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
parent
533959633e
commit
14aa8368e6
6 changed files with 76 additions and 0 deletions
|
@ -1956,6 +1956,33 @@ static int filters_peer_fn(sd_bus *bus,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int filters_link_fn(sd_bus *bus,
|
||||
sd_bus_message *m,
|
||||
void *data,
|
||||
sd_bus_error *err)
|
||||
{
|
||||
_shl_cleanup_free_ char *link = NULL;
|
||||
const char *path;
|
||||
|
||||
path = sd_bus_message_get_path(m);
|
||||
path = shl_startswith(path, "/org/freedesktop/miracle/link/");
|
||||
if (!path)
|
||||
return 0;
|
||||
|
||||
link = sd_bus_label_unescape(path);
|
||||
if (!link)
|
||||
return cli_ENOMEM();
|
||||
|
||||
if (sd_bus_message_is_signal(m,
|
||||
"org.freedesktop.miracle.Link",
|
||||
"ScanStopped")) {
|
||||
if (scan_link && !strcmp(link, scan_link))
|
||||
cmd_scan_stop(true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void filters_init()
|
||||
{
|
||||
int r;
|
||||
|
@ -1986,10 +2013,26 @@ static void filters_init()
|
|||
NULL);
|
||||
if (r < 0)
|
||||
cli_error("cannot add dbus match: %d", r);
|
||||
|
||||
r = sd_bus_add_match(bus,
|
||||
"type='signal',"
|
||||
"sender='org.freedesktop.miracle',"
|
||||
"interface='org.freedesktop.miracle.Link'",
|
||||
filters_link_fn,
|
||||
NULL);
|
||||
if (r < 0)
|
||||
cli_error("cannot add dbus match: %d", r);
|
||||
}
|
||||
|
||||
static void filters_destroy()
|
||||
{
|
||||
sd_bus_remove_match(bus,
|
||||
"type='signal',"
|
||||
"sender='org.freedesktop.miracle',"
|
||||
"interface='org.freedesktop.miracle.Link'",
|
||||
filters_link_fn,
|
||||
NULL);
|
||||
|
||||
sd_bus_remove_match(bus,
|
||||
"type='signal',"
|
||||
"sender='org.freedesktop.miracle',"
|
||||
|
|
|
@ -509,6 +509,7 @@ static const sd_bus_vtable link_dbus_vtable[] = {
|
|||
link_dbus_set_name,
|
||||
0,
|
||||
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_SIGNAL("ScanStopped", NULL, 0),
|
||||
SD_BUS_VTABLE_END
|
||||
};
|
||||
|
||||
|
@ -553,6 +554,24 @@ void link_dbus_properties_changed(struct link *l, const char *prop, ...)
|
|||
log_vERR(r);
|
||||
}
|
||||
|
||||
void link_dbus_scan_stopped(struct link *l)
|
||||
{
|
||||
_cleanup_free_ char *path = NULL;
|
||||
int r;
|
||||
|
||||
path = shl_strcat("/org/freedesktop/miracle/link/", l->name);
|
||||
if (!path)
|
||||
return log_vENOMEM();
|
||||
|
||||
r = sd_bus_emit_signal(l->m->bus,
|
||||
path,
|
||||
"org.freedesktop.miracle.Link",
|
||||
"ScanStopped",
|
||||
NULL);
|
||||
if (r < 0)
|
||||
log_vERR(r);
|
||||
}
|
||||
|
||||
void link_dbus_added(struct link *l)
|
||||
{
|
||||
_cleanup_free_ char *path = NULL;
|
||||
|
|
|
@ -110,6 +110,9 @@ static void link_wifi_event_fn(struct wifi *w, void *data,
|
|||
/* destroy this link */
|
||||
link_free(l);
|
||||
break;
|
||||
case WIFI_SCAN_STOPPED:
|
||||
link_dbus_scan_stopped(l);
|
||||
break;
|
||||
case WIFI_DEV_FOUND:
|
||||
peer_new_wifi(l, ev->dev_found.dev, NULL);
|
||||
break;
|
||||
|
|
|
@ -172,6 +172,14 @@ static void wifi_hup(struct wifi *w)
|
|||
wifi_raise(w, &wev);
|
||||
}
|
||||
|
||||
static void wifi_scan_stopped(struct wifi *w)
|
||||
{
|
||||
struct wifi_event wev = { };
|
||||
|
||||
wev.type = WIFI_SCAN_STOPPED;
|
||||
wifi_raise(w, &wev);
|
||||
}
|
||||
|
||||
static void wifi_show_dev(struct wifi *w, struct wifi_dev *d)
|
||||
{
|
||||
struct wifi_event wev = { };
|
||||
|
@ -419,6 +427,7 @@ static void wifi_event_p2p_find_stopped(struct wifi *w, char *msg,
|
|||
return;
|
||||
|
||||
w->discoverable = false;
|
||||
wifi_scan_stopped(w);
|
||||
}
|
||||
|
||||
static void wifi_event_p2p_device_found(struct wifi *w, char *msg,
|
||||
|
|
|
@ -42,6 +42,7 @@ struct wifi_dev;
|
|||
|
||||
enum wifi_event_type {
|
||||
WIFI_HUP,
|
||||
WIFI_SCAN_STOPPED,
|
||||
WIFI_DEV_FOUND,
|
||||
WIFI_DEV_LOST,
|
||||
WIFI_DEV_PROVISION,
|
||||
|
|
|
@ -158,6 +158,7 @@ void peer_dbus_removed(struct peer *p);
|
|||
|
||||
_shl_sentinel_
|
||||
void link_dbus_properties_changed(struct link *l, const char *prop, ...);
|
||||
void link_dbus_scan_stopped(struct link *l);
|
||||
void link_dbus_added(struct link *l);
|
||||
void link_dbus_removed(struct link *l);
|
||||
|
||||
|
|
Loading…
Reference in a new issue