Exemplo n.º 1
0
static void
add_device_from_path (char                *device_path,
                      GUPnPNetworkManager *manager)
{
        NMDevice *nm_device;

        nm_device = nm_device_new (manager, device_path);

        manager->priv->nm_devices = g_list_append (manager->priv->nm_devices,
                                                   nm_device);

        dbus_g_proxy_add_signal (nm_device->device_proxy,
                                 "StateChanged",
                                 G_TYPE_UINT,
                                 G_TYPE_UINT,
                                 G_TYPE_UINT,
                                 G_TYPE_INVALID);

        dbus_g_proxy_connect_signal (nm_device->device_proxy,
                                     "StateChanged",
                                     G_CALLBACK (on_device_state_changed),
                                     nm_device,
                                     NULL);

        dbus_g_proxy_begin_call (nm_device->prop_proxy,
                                 "Get",
                                 get_device_state_cb,
                                 nm_device,
                                 NULL,
                                 G_TYPE_STRING, DEVICE_INTERFACE,
                                 G_TYPE_STRING, "State",
                                 G_TYPE_INVALID);
}
static void
device_proxy_new_cb (GObject      *source_object,
                     GAsyncResult *res,
                     gpointer      user_data) {
        GUPnPNetworkManager *manager;
        GDBusProxy *device_proxy;
        NMDevice *nm_device = NULL;
        NMDeviceType type;
        GVariant *value;
        GError *error;

        error = NULL;

        device_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
        if (G_UNLIKELY (error != NULL)) {
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
                        g_message ("Failed to create D-Bus proxy: %s", error->message);
                g_error_free (error);

                goto done;
        }

        manager = GUPNP_NETWORK_MANAGER (user_data);

        value = g_dbus_proxy_get_cached_property (device_proxy, "DeviceType");
        if (G_UNLIKELY (value == NULL)) {
                goto done;
        }

        if (G_UNLIKELY (!g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32))) {
                g_variant_unref (value);

                goto done;
        }

        type = g_variant_get_uint32 (value);
        g_variant_unref (value);

        nm_device = nm_device_new (manager, device_proxy);

        if (type == NM_DEVICE_TYPE_WIFI) {
                const char *path;

                path = g_dbus_proxy_get_object_path (nm_device->proxy);
                g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
                                          G_DBUS_PROXY_FLAGS_NONE,
                                          NULL,
                                          DBUS_SERVICE_NM,
                                          path,
                                          WIFI_INTERFACE,
                                          manager->priv->cancellable,
                                          wifi_proxy_new_cb,
                                          nm_device_ref (nm_device));
        } else
                use_new_device (manager, nm_device);

done:
        g_clear_pointer (&nm_device, (GDestroyNotify) nm_device_unref);
        g_clear_object (&device_proxy);
}