~ubuntu-branches/ubuntu/raring/wacom-tools/raring

« back to all changes in this revision

Viewing changes to linuxwacom/src/util/hal-setup-wacom.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-05-22 12:04:32 UTC
  • mfrom: (1.12.2 upstream) (2.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090522120432-00suvwukj864ipib
Tags: 1:0.8.3.2-1ubuntu1
* Merge with Debian unstable, remaining changes:
  - Bump the epoch because of old Ubuntu packaging.
  - debian/control:
    - Change the Maintainer address.
    - Bump the epoch on Replaces/Conflicts.
    - Don't build wacom-kernel-source anymore (#71944).
  - debian/wacom.postinst:
    Remove old files.
  - debian/rules: Disable the scaling quirk.
  - Enable patch system (quilt).
    - Import debian/xsfbs/*
    - Add quilt to build-deps.
  - Include wacomcpl so the stylus can be calibrated. (#216347)
    - debian/rules: --enable-libwacomxi
    - debian/control: Add tcl-dev, tk-dev to Build-Depends, and tcl,
      tk to wacom-tools Depends.
  - Modify 10-linuxwacom.fdi to support WALTOP and N-Trig.
  - Add 104_revert-check.diff: Don't check the serial number, it breaks
    some devices. Disabled for now, needs testing because part of it
    is upstream now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed under the GNU General Public License Version 2
 
3
 *
 
4
 * Copyright (C) 2009 Red Hat <mjg@redhat.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
19
 * 02110-1301, USA.
 
20
 */
 
21
 
 
22
#define _GNU_SOURCE
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <errno.h>
 
26
#include <string.h>
 
27
#include <fcntl.h>
 
28
#include <unistd.h>
 
29
#include <sys/ioctl.h>
 
30
 
 
31
#include <hal/libhal.h>
 
32
 
 
33
static LibHalContext *ctx = NULL;
 
34
static char* udi;
 
35
 
 
36
int
 
37
main (int argc, char **argv)
 
38
{
 
39
        char *device;
 
40
        char *newudi;
 
41
        char *forcedev;
 
42
        char *name;
 
43
        char *subname;
 
44
        char **types;
 
45
        int i;
 
46
        DBusError error;
 
47
 
 
48
        udi = getenv ("UDI");
 
49
        if (udi == NULL) {
 
50
                fprintf (stderr, "hal-setup-wacom: Failed to get UDI\n");
 
51
                return 1;
 
52
        }
 
53
 
 
54
        asprintf (&newudi, "%s_subdev", udi);
 
55
 
 
56
        dbus_error_init (&error);
 
57
        if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
 
58
                fprintf (stderr, "hal-setup-wacom: Unable to initialise libhal context: %s\n", error.message);
 
59
                return 1;
 
60
        }
 
61
 
 
62
        dbus_error_init (&error);
 
63
        if (!libhal_device_addon_is_ready (ctx, udi, &error)) {
 
64
                return 1;
 
65
        }
 
66
 
 
67
        dbus_error_init (&error);
 
68
 
 
69
        /* get the device */
 
70
        device = libhal_device_get_property_string (ctx, udi, "input.device",
 
71
                                                    &error);
 
72
        if (dbus_error_is_set (&error) == TRUE) {
 
73
                fprintf (stderr,
 
74
                         "hal-setup-wacom: Failed to get input device: '%s'\n",
 
75
                         error.message);
 
76
                return 1;
 
77
        }
 
78
 
 
79
        /* Is there a forcedevice? */
 
80
        dbus_error_init (&error);
 
81
        forcedev = libhal_device_get_property_string
 
82
                (ctx, udi, "input.x11_options.ForceDevice", &error);
 
83
 
 
84
        dbus_error_init (&error);
 
85
        name = libhal_device_get_property_string (ctx, udi, "info.product",
 
86
                                                  &error);
 
87
 
 
88
        dbus_error_init (&error);
 
89
        types = libhal_device_get_property_strlist (ctx, udi, "wacom.types",
 
90
                                                    &error);
 
91
 
 
92
        if (dbus_error_is_set (&error) == TRUE) {
 
93
                fprintf (stderr,
 
94
                         "hal-setup-wacom: Failed to get wacom types: '%s'\n",
 
95
                         error.message);
 
96
                return 1;
 
97
        }
 
98
 
 
99
        /* Set up the extra devices */
 
100
        for (i=0; types[i] != NULL; i++) {
 
101
                char *tmpdev;
 
102
 
 
103
                dbus_error_init (&error);
 
104
                tmpdev = libhal_new_device(ctx, &error);
 
105
                if (dbus_error_is_set (&error) == TRUE) {
 
106
                        fprintf (stderr,
 
107
                                 "hal-setup-wacom: Failed to create input device: '%s'\n",
 
108
                                 error.message);
 
109
                        return 1;
 
110
                }
 
111
                dbus_error_init (&error);
 
112
                libhal_device_set_property_string (ctx, tmpdev, "input.device",
 
113
                                                   device, &error);
 
114
                dbus_error_init (&error);
 
115
                libhal_device_set_property_string (ctx, tmpdev,
 
116
                                                   "input.x11_driver", "wacom",
 
117
                                                   &error);
 
118
                dbus_error_init (&error);
 
119
                libhal_device_set_property_string (ctx, tmpdev,
 
120
                                                   "input.x11_options.Type",
 
121
                                                   types[i], &error);
 
122
                dbus_error_init (&error);
 
123
                libhal_device_set_property_string (ctx, tmpdev, "info.parent",
 
124
                                                   udi, &error);
 
125
                dbus_error_init (&error);
 
126
                libhal_device_property_strlist_append (ctx, tmpdev,
 
127
                                                       "info.capabilities",
 
128
                                                       "input", &error);
 
129
                if (forcedev) {
 
130
                        dbus_error_init (&error);
 
131
                        libhal_device_set_property_string (ctx, tmpdev,
 
132
                                                           "input.x11_options.ForceDevice",
 
133
                                                           forcedev, &error);
 
134
                }
 
135
                if (name) {
 
136
                        dbus_error_init (&error);
 
137
                        asprintf (&subname, "%s %s", name, types[i]);
 
138
                        libhal_device_set_property_string (ctx, tmpdev,
 
139
                                                           "info.product",
 
140
                                                           subname, &error);
 
141
                        free (subname);
 
142
                }
 
143
                dbus_error_init (&error);
 
144
                libhal_device_commit_to_gdl (ctx, tmpdev, newudi, &error);
 
145
 
 
146
                if (dbus_error_is_set (&error) == TRUE) {
 
147
                        fprintf (stderr,
 
148
                                 "hal-setup-wacom: Failed to add input device: '%s'\n",
 
149
                                 error.message);
 
150
                        return 1;
 
151
                }
 
152
        }
 
153
 
 
154
        return 0;
 
155
}
 
156