47
47
* dkp_device_list_lookup:
49
* Convert a %DevkitDevice into a %DkpDevice -- we use the native path
49
* Convert a %DevkitDevice into a %GObject -- we use the native path
50
50
* to look these up as it's the only thing they share.
53
dkp_device_list_lookup (DkpDeviceList *list, DevkitDevice *d)
53
dkp_device_list_lookup (DkpDeviceList *list, DevkitDevice *device)
56
56
const gchar *native_path;
58
58
g_return_val_if_fail (DKP_IS_DEVICE_LIST (list), NULL);
60
60
/* does device exist in db? */
61
native_path = devkit_device_get_native_path (d);
62
device = g_hash_table_lookup (list->priv->map_native_path_to_device, native_path);
61
native_path = devkit_device_get_native_path (device);
62
object = g_hash_table_lookup (list->priv->map_native_path_to_object, native_path);
67
67
* dkp_device_list_insert:
69
* Insert a %DevkitDevice device and it's mapping to a %DkpDevice device
69
* Insert a %DevkitDevice device and it's mapping to a backing %GObject
70
70
* into a list of devices.
73
dkp_device_list_insert (DkpDeviceList *list, DevkitDevice *d, DkpDevice *device)
73
dkp_device_list_insert (DkpDeviceList *list, DevkitDevice *device, GObject *object)
75
75
const gchar *native_path;
77
77
g_return_val_if_fail (DKP_IS_DEVICE_LIST (list), FALSE);
78
g_return_val_if_fail (d != NULL, FALSE);
79
78
g_return_val_if_fail (device != NULL, FALSE);
79
g_return_val_if_fail (object != NULL, FALSE);
81
native_path = devkit_device_get_native_path (d);
82
g_hash_table_insert (list->priv->map_native_path_to_device,
83
g_strdup (native_path), device);
84
g_ptr_array_add (list->priv->array, device);
81
native_path = devkit_device_get_native_path (device);
82
g_hash_table_insert (list->priv->map_native_path_to_object,
83
g_strdup (native_path), object);
84
g_ptr_array_add (list->priv->array, g_object_ref (object));
85
85
egg_debug ("added %s", native_path);
103
103
* dkp_device_list_remove:
106
dkp_device_list_remove (DkpDeviceList *list, DkpDevice *device)
106
dkp_device_list_remove (DkpDeviceList *list, GObject *object)
108
108
g_return_val_if_fail (DKP_IS_DEVICE_LIST (list), FALSE);
109
g_return_val_if_fail (device != NULL, FALSE);
109
g_return_val_if_fail (object != NULL, FALSE);
111
111
/* remove the device from the db */
112
g_hash_table_foreach_remove (list->priv->map_native_path_to_device,
113
dkp_device_list_remove_cb, device);
114
g_ptr_array_remove (list->priv->array, device);
112
g_hash_table_foreach_remove (list->priv->map_native_path_to_object,
113
dkp_device_list_remove_cb, object);
114
g_ptr_array_remove (list->priv->array, object);
115
g_object_unref (object);
149
150
list->priv = DKP_DEVICE_LIST_GET_PRIVATE (list);
150
151
list->priv->array = g_ptr_array_new ();
151
list->priv->map_native_path_to_device = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
152
list->priv->map_native_path_to_object = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
163
164
g_return_if_fail (DKP_IS_DEVICE_LIST (object));
165
166
list = DKP_DEVICE_LIST (object);
168
g_ptr_array_foreach (list->priv->array, (GFunc) g_object_unref, NULL);
166
169
g_ptr_array_free (list->priv->array, TRUE);
167
g_hash_table_unref (list->priv->map_native_path_to_device);
170
g_hash_table_unref (list->priv->map_native_path_to_object);
169
172
G_OBJECT_CLASS (dkp_device_list_parent_class)->finalize (object);