source: proiecte/PPPP/gdm/daemon/test-hal-seats.c @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

File size: 5.4 KB
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of the
6 * License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 * 02111-1307, USA.
17 *
18 * cc -o test-hal-seats `pkg-config --cflags --libs glib-2.0 dbus-glib-1` test-hal-seats.c
19 */
20
21#include <stdlib.h>
22#include <stdio.h>
23
24#include <glib.h>
25#define DBUS_API_SUBJECT_TO_CHANGE
26#include <dbus/dbus-glib.h>
27#include <dbus/dbus-glib-lowlevel.h>
28
29#define HAL_DBUS_NAME                           "org.freedesktop.Hal"
30#define HAL_DBUS_MANAGER_PATH                   "/org/freedesktop/Hal/Manager"
31#define HAL_DBUS_MANAGER_INTERFACE              "org.freedesktop.Hal.Manager"
32#define HAL_DBUS_DEVICE_INTERFACE               "org.freedesktop.Hal.Device"
33#define SEAT_PCI_DEVICE_CLASS                   3
34
35static GMainLoop *loop;
36
37static void
38get_pci_seats (DBusGConnection *bus,
39               DBusGProxy      *proxy,
40               GList           *seats)
41{
42        char      **devices;
43        const char *key;
44        const char *value;
45        GError     *error;
46        gboolean    res;
47        int         i;
48
49        g_message ("Getting PCI seats");
50
51        key = "info.bus";
52        value = "pci";
53
54        devices = NULL;
55        error = NULL;
56        res = dbus_g_proxy_call (proxy,
57                                 "FindDeviceStringMatch",
58                                 &error,
59                                 G_TYPE_STRING, key,
60                                 G_TYPE_STRING, value,
61                                 G_TYPE_INVALID,
62                                 G_TYPE_STRV, &devices,
63                                 G_TYPE_INVALID);
64        if (! res) {
65                g_warning ("Unable to query HAL: %s", error->message);
66                g_error_free (error);
67        }
68
69        /* now look for pci class 3 */
70        key = "pci.device_class";
71        for (i = 0; devices [i] != NULL; i++) {
72                DBusGProxy *device_proxy;
73                int         class_val;
74
75                device_proxy = dbus_g_proxy_new_for_name (bus,
76                                                          HAL_DBUS_NAME,
77                                                          devices [i],
78                                                          HAL_DBUS_DEVICE_INTERFACE);
79                if (device_proxy == NULL) {
80                        continue;
81                }
82
83                error = NULL;
84                res = dbus_g_proxy_call (device_proxy,
85                                         "GetPropertyInteger",
86                                         &error,
87                                         G_TYPE_STRING, key,
88                                         G_TYPE_INVALID,
89                                         G_TYPE_INT, &class_val,
90                                         G_TYPE_INVALID);
91                if (! res) {
92                        g_warning ("Unable to query HAL: %s", error->message);
93                        g_error_free (error);
94                }
95
96                if (class_val == SEAT_PCI_DEVICE_CLASS) {
97                        g_message ("Found device: %s", devices [i]);
98                        seats = g_list_prepend (seats, devices [i]);
99                }
100
101                g_object_unref (device_proxy);
102        }
103
104        g_strfreev (devices);
105}
106
107static void
108list_seats (GList *seats)
109{
110        GList *l;
111        for (l = seats; l != NULL; l = l->next) {
112                g_message ("Found device: %s", (char *)l->data);
113        }
114}
115
116static gboolean
117test_hal_seats (void)
118{
119        GError          *error;
120        DBusGConnection *bus;
121        DBusGProxy      *proxy;
122        GList           *seats;
123
124        proxy = NULL;
125
126        error = NULL;
127        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
128        if (bus == NULL) {
129                g_warning ("Couldn't connect to system bus: %s",
130                           error->message);
131                g_error_free (error);
132                goto out;
133        }
134
135        proxy = dbus_g_proxy_new_for_name (bus,
136                                           HAL_DBUS_NAME,
137                                           HAL_DBUS_MANAGER_PATH,
138                                           HAL_DBUS_MANAGER_INTERFACE);
139        if (proxy == NULL) {
140                g_warning ("Couldn't create proxy for HAL Manager");
141                goto out;
142        }
143
144        seats = NULL;
145
146        get_pci_seats (bus, proxy, seats);
147
148        list_seats (seats);
149
150 out:
151        if (proxy != NULL) {
152                g_object_unref (proxy);
153        }
154
155        return FALSE;
156}
157
158int
159main (int   argc,
160      char *argv[])
161{
162        g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
163
164        g_type_init ();
165
166        g_idle_add ((GSourceFunc)test_hal_seats, NULL);
167
168        loop = g_main_loop_new (NULL, FALSE);
169        g_main_loop_run (loop);
170        g_main_loop_unref (loop);
171
172        return 0;
173}
Note: See TracBrowser for help on using the repository browser.