~ubuntu-branches/ubuntu/maverick/devicekit-power/maverick

« back to all changes in this revision

Viewing changes to src/dkp-device-list.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-06 19:12:49 UTC
  • mfrom: (1.1.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20090706191249-hr0a9c2ti5u0b5lc
Tags: 009-1
* New upstream release.   
* debian/control: Add myself to uploaders (discussed with Michael).
* debian/devicekit-power.install: Upstream installs udev rules into
  /lib/udev/rules.d now, update accordingly.
* Add 0001-Add-a-notify-flag-to-set_lid_is_closed.patch: Properly fix the
  silencing of the coldplug lid event, so that the first real lid event
  actually works. Thanks to Loïc Minier! (fd.o #22574)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
2
 *
3
 
 * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
 
3
 * Copyright (C) 2008-2009 Richard Hughes <richard@hughsie.com>
4
4
 *
5
5
 * Licensed under the GNU General Public License Version 2
6
6
 *
26
26
#include <glib.h>
27
27
 
28
28
#include "egg-debug.h"
29
 
#include "dkp-device.h"
 
29
 
30
30
#include "dkp-device-list.h"
31
31
 
32
32
static void     dkp_device_list_class_init      (DkpDeviceListClass     *klass);
38
38
struct DkpDeviceListPrivate
39
39
{
40
40
        GPtrArray               *array;
41
 
        GHashTable              *map_native_path_to_device;
 
41
        GHashTable              *map_native_path_to_object;
42
42
};
43
43
 
44
44
G_DEFINE_TYPE (DkpDeviceList, dkp_device_list, G_TYPE_OBJECT)
46
46
/**
47
47
 * dkp_device_list_lookup:
48
48
 *
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.
51
51
 **/
52
 
DkpDevice *
53
 
dkp_device_list_lookup (DkpDeviceList *list, DevkitDevice *d)
 
52
GObject *
 
53
dkp_device_list_lookup (DkpDeviceList *list, DevkitDevice *device)
54
54
{
55
 
        DkpDevice *device;
 
55
        GObject *object;
56
56
        const gchar *native_path;
57
57
 
58
58
        g_return_val_if_fail (DKP_IS_DEVICE_LIST (list), NULL);
59
59
 
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);
63
 
        return device;
 
61
        native_path = devkit_device_get_native_path (device);
 
62
        object = g_hash_table_lookup (list->priv->map_native_path_to_object, native_path);
 
63
        return object;
64
64
}
65
65
 
66
66
/**
67
67
 * dkp_device_list_insert:
68
68
 *
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.
71
71
 **/
72
72
gboolean
73
 
dkp_device_list_insert (DkpDeviceList *list, DevkitDevice *d, DkpDevice *device)
 
73
dkp_device_list_insert (DkpDeviceList *list, DevkitDevice *device, GObject *object)
74
74
{
75
75
        const gchar *native_path;
76
76
 
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);
80
80
 
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);
86
86
        return TRUE;
87
87
}
103
103
 * dkp_device_list_remove:
104
104
 **/
105
105
gboolean
106
 
dkp_device_list_remove (DkpDeviceList *list, DkpDevice *device)
 
106
dkp_device_list_remove (DkpDeviceList *list, GObject *object)
107
107
{
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);
110
110
 
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);
115
116
        return TRUE;
116
117
}
117
118
 
148
149
{
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);
152
153
}
153
154
 
154
155
/**
163
164
        g_return_if_fail (DKP_IS_DEVICE_LIST (object));
164
165
 
165
166
        list = DKP_DEVICE_LIST (object);
 
167
 
 
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);
168
171
 
169
172
        G_OBJECT_CLASS (dkp_device_list_parent_class)->finalize (object);
170
173
}