void mm_manager_start (MMManager *manager) { GList *devices, *iter; g_return_if_fail (manager != NULL); g_return_if_fail (MM_IS_MANAGER (manager)); mm_dbg ("Starting device scan..."); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data)); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data)); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); mm_dbg ("Finished device scan..."); }
void mm_manager_start (MMManager *manager) { GList *devices, *iter; g_return_if_fail (manager != NULL); g_return_if_fail (MM_IS_MANAGER (manager)); mm_dbg ("Starting device scan..."); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net"); for (iter = devices; iter; iter = g_list_next (iter)) { device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usb"); for (iter = devices; iter; iter = g_list_next (iter)) { const gchar *name; name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data)); if (name && g_str_has_prefix (name, "cdc-wdm")) device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); /* Newer kernels report 'usbmisc' subsystem */ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usbmisc"); for (iter = devices; iter; iter = g_list_next (iter)) { const gchar *name; name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data)); if (name && g_str_has_prefix (name, "cdc-wdm")) device_added (manager, G_UDEV_DEVICE (iter->data), FALSE); g_object_unref (G_OBJECT (iter->data)); } g_list_free (devices); mm_dbg ("Finished device scan..."); }
static void handle_uevent (GUdevClient *client, const char *action, GUdevDevice *device, gpointer user_data) { MMBaseManager *self = MM_BASE_MANAGER (user_data); const gchar *subsys; const gchar *name; g_return_if_fail (action != NULL); /* A bit paranoid */ subsys = g_udev_device_get_subsystem (device); g_return_if_fail (subsys != NULL); g_return_if_fail (g_str_equal (subsys, "tty") || g_str_equal (subsys, "net") || g_str_has_prefix (subsys, "usb")); /* We only care about tty/net and usb/cdc-wdm devices when adding modem ports, * but for remove, also handle usb parent device remove events */ name = g_udev_device_get_name (device); if ( (g_str_equal (action, "add") || g_str_equal (action, "move") || g_str_equal (action, "change")) && (!g_str_has_prefix (subsys, "usb") || (name && g_str_has_prefix (name, "cdc-wdm")))) device_added (self, device, TRUE, FALSE); else if (g_str_equal (action, "remove")) device_removed (self, device); }
static int udev_input_add_devices(struct udev_input *input, struct udev *udev) { struct udev_enumerate *e; struct udev_list_entry *entry; struct udev_device *device; const char *path, *sysname; struct udev_seat *seat; int devices_found = 0; e = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(e, "input"); udev_enumerate_scan_devices(e); udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { path = udev_list_entry_get_name(entry); device = udev_device_new_from_syspath(udev, path); sysname = udev_device_get_sysname(device); if (strncmp("event", sysname, 5) != 0) { udev_device_unref(device); continue; } if (device_added(device, input) < 0) { udev_device_unref(device); udev_enumerate_unref(e); return -1; } udev_device_unref(device); }
static void handle_uevent (GUdevClient *client, const char *action, GUdevDevice *device, gpointer user_data) { MMManager *self = MM_MANAGER (user_data); const char *subsys; g_return_if_fail (action != NULL); /* A bit paranoid */ subsys = g_udev_device_get_subsystem (device); g_return_if_fail (subsys != NULL); g_return_if_fail (!strcmp (subsys, "tty") || !strcmp (subsys, "net") || !strcmp (subsys, "usb")); /* We only care about tty/net devices when adding modem ports, * but for remove, also handle usb parent device remove events */ if ( (!strcmp (action, "add") || !strcmp (action, "move") || !strcmp (action, "change")) && (strcmp (subsys, "usb") != 0)) device_added (self, device); else if (!strcmp (action, "remove")) device_removed (self, device); }
static void get_managed_objects_cb (GDBusProxy *proxy, GAsyncResult *res, NMBluez5Manager *self) { GVariant *variant, *ifaces; GVariantIter i; GError *error = NULL; const char *path; variant = _nm_dbus_proxy_call_finish (proxy, res, G_VARIANT_TYPE ("(a{oa{sa{sv}}})"), &error); if (!variant) { if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) nm_log_warn (LOGD_BT, "Couldn't get managed objects: not running Bluez5?"); else { g_dbus_error_strip_remote_error (error); nm_log_warn (LOGD_BT, "Couldn't get managed objects: %s", error->message); } g_clear_error (&error); return; } g_variant_iter_init (&i, g_variant_get_child_value (variant, 0)); while ((g_variant_iter_next (&i, "{&o*}", &path, &ifaces))) { if (g_variant_lookup_value (ifaces, BLUEZ5_DEVICE_INTERFACE, G_VARIANT_TYPE_DICTIONARY)) { device_added (proxy, path, self); } g_variant_unref (ifaces); } g_variant_unref (variant); }
static gboolean start_device_added_idle (StartDeviceAdded *ctx) { device_added (ctx->self, ctx->device, FALSE, ctx->manual_scan); g_object_unref (ctx->self); g_object_unref (ctx->device); g_slice_free (StartDeviceAdded, ctx); return G_SOURCE_REMOVE; }
static void object_manager_interfaces_added (GDBusProxy *proxy, const char *path, GVariant *dict, NMBluez5Manager *self) { if (g_variant_lookup (dict, BLUEZ5_DEVICE_INTERFACE, "a{sv}", NULL)) device_added (proxy, path, self); }
static gboolean monitor_watch(GIOChannel *source, GIOCondition condition, gpointer data) { struct udev_device *udevice; udevice = udev_monitor_receive_device(monitor); if (!udevice) return TRUE; if (!g_strcmp0(udev_device_get_action(udevice), "add")) device_added(udevice); udev_device_unref(udevice); return TRUE; }
static BOOL connect_and_register(DBusConnection *connection, struct config_hal_info *info) { DBusError error; char **devices; int num_devices, i; if (info->hal_ctx) return TRUE; /* already registered, pretend we did something */ info->system_bus = connection; dbus_error_init(&error); info->hal_ctx = libhal_ctx_new(); if (!info->hal_ctx) { LogMessage(X_ERROR, "config/hal: couldn't create HAL context\n"); goto out_err; } if (!libhal_ctx_set_dbus_connection(info->hal_ctx, info->system_bus)) { LogMessage(X_ERROR, "config/hal: couldn't associate HAL context with bus\n"); goto out_err; } if (!libhal_ctx_init(info->hal_ctx, &error)) { LogMessage(X_ERROR, "config/hal: couldn't initialise context: %s (%s)\n", error.name ? error.name : "unknown error", error.message ? error.message : "null"); goto out_err; } if (!libhal_device_property_watch_all(info->hal_ctx, &error)) { LogMessage(X_ERROR, "config/hal: couldn't watch all properties: %s (%s)\n", error.name ? error.name : "unknown error", error.message ? error.message : "null"); goto out_ctx; } libhal_ctx_set_device_added(info->hal_ctx, device_added); libhal_ctx_set_device_removed(info->hal_ctx, device_removed); devices = libhal_find_device_by_capability(info->hal_ctx, "input", &num_devices, &error); /* FIXME: Get default devices if error is set. */ if (dbus_error_is_set(&error)) { LogMessage(X_ERROR, "config/hal: couldn't find input device: %s (%s)\n", error.name ? error.name : "unknown error", error.message ? error.message : "null"); goto out_ctx; } for (i = 0; i < num_devices; i++) device_added(info->hal_ctx, devices[i]); libhal_free_string_array(devices); dbus_error_free(&error); return TRUE; out_ctx: dbus_error_free(&error); if (!libhal_ctx_shutdown(info->hal_ctx, &error)) { LogMessage(X_WARNING, "config/hal: couldn't shut down context: %s (%s)\n", error.name ? error.name : "unknown error", error.message ? error.message : "null"); dbus_error_free(&error); } out_err: dbus_error_free(&error); if (info->hal_ctx) { libhal_ctx_free(info->hal_ctx); } info->hal_ctx = NULL; info->system_bus = NULL; return FALSE; }
static void connect_hook(DBusConnection *connection, void *data) { DBusError error; struct config_hal_info *info = data; char **devices; int num_devices, i; info->system_bus = connection; dbus_error_init(&error); if (!info->hal_ctx) info->hal_ctx = libhal_ctx_new(); if (!info->hal_ctx) { ErrorF("[config/hal] couldn't create HAL context\n"); goto out_err; } if (!libhal_ctx_set_dbus_connection(info->hal_ctx, info->system_bus)) { ErrorF("[config/hal] couldn't associate HAL context with bus\n"); goto out_ctx; } if (!libhal_ctx_init(info->hal_ctx, &error)) { ErrorF("[config/hal] couldn't initialise context: %s (%s)\n", error.name, error.message); goto out_ctx; } libhal_ctx_set_device_added(info->hal_ctx, device_added); libhal_ctx_set_device_removed(info->hal_ctx, device_removed); if (!libhal_device_property_watch_all(info->hal_ctx, &error)) { ErrorF("[config/hal] couldn't watch all properties: %s (%s)\n", error.name, error.message); goto out_ctx2; } devices = libhal_find_device_by_capability(info->hal_ctx, "input", &num_devices, &error); /* FIXME: Get default devices if error is set. */ for (i = 0; i < num_devices; i++) device_added(info->hal_ctx, devices[i]); libhal_free_string_array(devices); dbus_error_free(&error); return; out_ctx2: if (!libhal_ctx_shutdown(info->hal_ctx, &error)) DebugF("[config/hal] couldn't shut down context: %s (%s)\n", error.name, error.message); out_ctx: libhal_ctx_free(info->hal_ctx); out_err: dbus_error_free(&error); info->hal_ctx = NULL; info->system_bus = NULL; return; }