Browse Source

application: monitor network changes, announce oneself when network becomes available

bboozzoo/self-announce
Maciek Borzecki 7 years ago
parent
commit
e8a2bd4001
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      src/mconnect/application.vala

+ 11
- 0
src/mconnect/application.vala View File

@ -39,6 +39,7 @@ namespace Mconn {
private DiscoveryDBusProxy bus_discovery = null; private DiscoveryDBusProxy bus_discovery = null;
private DeviceManager manager = null; private DeviceManager manager = null;
private DeviceManagerDBusProxy bus_manager = null; private DeviceManagerDBusProxy bus_manager = null;
private NetworkMonitor net_monitor = null;
public Application() { public Application() {
Object(application_id: "org.mconnect"); Object(application_id: "org.mconnect");
@ -46,6 +47,7 @@ namespace Mconn {
discovery = new Discovery(); discovery = new Discovery();
manager = new DeviceManager(); manager = new DeviceManager();
net_monitor = NetworkMonitor.get_default();
} }
protected override void startup() { protected override void startup() {
@ -83,6 +85,8 @@ namespace Mconn {
debug("activate"); debug("activate");
// reload devices from cache // reload devices from cache
manager.load_cache(); manager.load_cache();
net_monitor.network_changed.connect(this.network_changed);
hold(); hold();
} }
@ -109,5 +113,12 @@ namespace Mconn {
base.dbus_unregister(conn, object_path); base.dbus_unregister(conn, object_path);
debug("dbus unregister, path %s", object_path); debug("dbus unregister, path %s", object_path);
} }
private void network_changed(Object? monitor, bool available) {
debug("network connectivity changed: %s", available.to_string());
if (available == true) {
this.bus_discovery.announce();
}
}
} }
} }

Loading…
Cancel
Save