static void device_initialized (NMBluezDevice *device, gboolean success, NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); nm_log_dbg (LOGD_BT, "(%s): bluez device %s", nm_bluez_device_get_path (device), success ? "initialized" : "failed to initialize"); if (!success) g_hash_table_remove (priv->devices, nm_bluez_device_get_path (device)); }
static void device_initialized (NMBluezDevice *device, gboolean success, gpointer user_data) { NMBluezAdapter *self = NM_BLUEZ_ADAPTER (user_data); NMBluezAdapterPrivate *priv = NM_BLUEZ_ADAPTER_GET_PRIVATE (self); nm_log_dbg (LOGD_BT, "(%s): bluez device %s", nm_bluez_device_get_path (device), success ? "initialized" : "failed to initialize"); if (!success) g_hash_table_remove (priv->devices, nm_bluez_device_get_path (device)); }
static void device_usable (NMBluezDevice *device, GParamSpec *pspec, NMBluez5Manager *self) { gboolean usable = nm_bluez_device_get_usable (device); nm_log_dbg (LOGD_BT, "(%s): bluez device now %s", nm_bluez_device_get_path (device), usable ? "usable" : "unusable"); if (usable) { nm_log_dbg (LOGD_BT, "(%s): bluez device address %s", nm_bluez_device_get_path (device), nm_bluez_device_get_address (device)); emit_bdaddr_added (self, device); } else g_signal_emit_by_name (device, NM_BLUEZ_DEVICE_REMOVED); }
static void device_usable (NMBluezDevice *device, GParamSpec *pspec, gpointer user_data) { NMBluezAdapter *self = NM_BLUEZ_ADAPTER (user_data); gboolean usable = nm_bluez_device_get_usable (device); nm_log_dbg (LOGD_BT, "(%s): bluez device now %s", nm_bluez_device_get_path (device), usable ? "usable" : "unusable"); if (usable) { nm_log_dbg (LOGD_BT, "(%s): bluez device address %s", nm_bluez_device_get_path (device), nm_bluez_device_get_address (device)); g_signal_emit (self, signals[DEVICE_ADDED], 0, device); } else g_signal_emit (self, signals[DEVICE_REMOVED], 0, device); }
static void device_removed (NMBluezAdapter *adapter, NMBluezDevice *device, gpointer user_data) { NMBluezManager *self = NM_BLUEZ_MANAGER (user_data); g_signal_emit (self, signals[BDADDR_REMOVED], 0, nm_bluez_device_get_address (device), nm_bluez_device_get_path (device)); }
static void emit_bdaddr_added (NMBluezManager *self, NMBluezDevice *device) { g_signal_emit (self, signals[BDADDR_ADDED], 0, nm_bluez_device_get_address (device), nm_bluez_device_get_name (device), nm_bluez_device_get_path (device), nm_bluez_device_get_capabilities (device)); }
static void device_added (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NMBluezDevice *device; device = nm_bluez_device_new (path, NULL, priv->provider, 5); g_signal_connect (device, "initialized", G_CALLBACK (device_initialized), self); g_signal_connect (device, "notify::usable", G_CALLBACK (device_usable), self); g_hash_table_insert (priv->devices, (gpointer) nm_bluez_device_get_path (device), device); nm_log_dbg (LOGD_BT, "(%s): new bluez device found", path); }
static void device_created (DBusGProxy *proxy, const char *path, gpointer user_data) { NMBluezAdapter *self = NM_BLUEZ_ADAPTER (user_data); NMBluezAdapterPrivate *priv = NM_BLUEZ_ADAPTER_GET_PRIVATE (self); NMBluezDevice *device; device = nm_bluez_device_new (path, priv->provider); g_signal_connect (device, "initialized", G_CALLBACK (device_initialized), self); g_signal_connect (device, "notify::usable", G_CALLBACK (device_usable), self); g_hash_table_insert (priv->devices, (gpointer) nm_bluez_device_get_path (device), device); nm_log_dbg (LOGD_BT, "(%s): new bluez device found", path); }
static void device_removed (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NMBluezDevice *device; nm_log_dbg (LOGD_BT, "(%s): bluez device removed", path); device = g_hash_table_lookup (priv->devices, path); if (device) { g_hash_table_steal (priv->devices, nm_bluez_device_get_path (device)); remove_device (NM_BLUEZ5_MANAGER (self), device); g_object_unref (device); } }
static void device_removed (DBusGProxy *proxy, const char *path, gpointer user_data) { NMBluezAdapter *self = NM_BLUEZ_ADAPTER (user_data); NMBluezAdapterPrivate *priv = NM_BLUEZ_ADAPTER_GET_PRIVATE (self); NMBluezDevice *device; nm_log_dbg (LOGD_BT, "(%s): bluez device removed", path); device = g_hash_table_lookup (priv->devices, path); if (device) { g_object_ref (device); g_hash_table_remove (priv->devices, nm_bluez_device_get_path (device)); g_signal_emit (self, signals[DEVICE_REMOVED], 0, device); g_object_unref (device); } }
static void adapter_removed (DBusGProxy *proxy, const char *path, NMBluezManager *self) { NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE (self); if (priv->adapter && !strcmp (path, nm_bluez_adapter_get_path (priv->adapter))) { if (nm_bluez_adapter_get_initialized (priv->adapter)) { GSList *devices, *iter; devices = nm_bluez_adapter_get_devices (priv->adapter); for (iter = devices; iter; iter = g_slist_next (iter)) { NMBluezDevice *device = NM_BLUEZ_DEVICE (iter->data); g_signal_emit (self, signals[BDADDR_REMOVED], 0, nm_bluez_device_get_address (device), nm_bluez_device_get_path (device)); } g_slist_free (devices); } g_object_unref (priv->adapter); priv->adapter = NULL; } }