Imported Upstream version 1.15.1
[deb_xorg-server.git] / config / config.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright © 2006-2007 Daniel Stone
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Daniel Stone <daniel@fooishbar.org>
24 */
25
26#ifdef HAVE_DIX_CONFIG_H
27#include <dix-config.h>
28#endif
29
30#include "os.h"
31#include "inputstr.h"
32#include "hotplug.h"
33#include "config-backends.h"
34
35void
36config_pre_init(void)
37{
38#ifdef CONFIG_UDEV
39 if (!config_udev_pre_init())
40 ErrorF("[config] failed to pre-init udev\n");
41#endif
42}
43
44void
45config_init(void)
46{
47#ifdef CONFIG_UDEV
48 if (!config_udev_init())
49 ErrorF("[config] failed to initialise udev\n");
50#elif defined(CONFIG_NEED_DBUS)
51 if (config_dbus_core_init()) {
52#ifdef CONFIG_DBUS_API
53 if (!config_dbus_init())
54 ErrorF("[config] failed to initialise D-Bus API\n");
55#endif
56#ifdef CONFIG_HAL
57 if (!config_hal_init())
58 ErrorF("[config] failed to initialise HAL\n");
59#endif
60 }
61 else {
62 ErrorF("[config] failed to initialise D-Bus core\n");
63 }
64#elif defined(CONFIG_WSCONS)
65 if (!config_wscons_init())
66 ErrorF("[config] failed to initialise wscons\n");
67#endif
68}
69
70void
71config_fini(void)
72{
73#if defined(CONFIG_UDEV)
74 config_udev_fini();
75#elif defined(CONFIG_NEED_DBUS)
76#ifdef CONFIG_HAL
77 config_hal_fini();
78#endif
79#ifdef CONFIG_DBUS_API
80 config_dbus_fini();
81#endif
82 config_dbus_core_fini();
83#elif defined(CONFIG_WSCONS)
84 config_wscons_fini();
85#endif
86}
87
88void
89config_odev_probe(config_odev_probe_proc_ptr probe_callback)
90{
91#if defined(CONFIG_UDEV_KMS)
92 config_udev_odev_probe(probe_callback);
93#endif
94}
95
96static void
97remove_device(const char *backend, DeviceIntPtr dev)
98{
99 /* this only gets called for devices that have already been added */
100 LogMessage(X_INFO, "config/%s: removing device %s\n", backend, dev->name);
101
102 /* Call PIE here so we don't try to dereference a device that's
103 * already been removed. */
104 OsBlockSignals();
105 ProcessInputEvents();
106 DeleteInputDeviceRequest(dev);
107 OsReleaseSignals();
108}
109
110void
111remove_devices(const char *backend, const char *config_info)
112{
113 DeviceIntPtr dev, next;
114
115 for (dev = inputInfo.devices; dev; dev = next) {
116 next = dev->next;
117 if (dev->config_info && strcmp(dev->config_info, config_info) == 0)
118 remove_device(backend, dev);
119 }
120 for (dev = inputInfo.off_devices; dev; dev = next) {
121 next = dev->next;
122 if (dev->config_info && strcmp(dev->config_info, config_info) == 0)
123 remove_device(backend, dev);
124 }
125}
126
127BOOL
128device_is_duplicate(const char *config_info)
129{
130 DeviceIntPtr dev;
131
132 for (dev = inputInfo.devices; dev; dev = dev->next) {
133 if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
134 return TRUE;
135 }
136
137 for (dev = inputInfo.off_devices; dev; dev = dev->next) {
138 if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
139 return TRUE;
140 }
141
142 return FALSE;
143}
144
145struct OdevAttributes *
146config_odev_allocate_attribute_list(void)
147{
148 struct OdevAttributes *attriblist;
149
150 attriblist = malloc(sizeof(struct OdevAttributes));
151 if (!attriblist)
152 return NULL;
153
154 xorg_list_init(&attriblist->list);
155 return attriblist;
156}
157
158void
159config_odev_free_attribute_list(struct OdevAttributes *attribs)
160{
161 config_odev_free_attributes(attribs);
162 free(attribs);
163}
164
165Bool
166config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
167 const char *attrib_name)
168{
169 struct OdevAttribute *oa;
170
171 oa = malloc(sizeof(struct OdevAttribute));
172 if (!oa)
173 return FALSE;
174
175 oa->attrib_id = attrib;
176 oa->attrib_name = strdup(attrib_name);
177 xorg_list_append(&oa->member, &attribs->list);
178 return TRUE;
179}
180
181void
182config_odev_free_attributes(struct OdevAttributes *attribs)
183{
184 struct OdevAttribute *iter, *safe;
185
186 xorg_list_for_each_entry_safe(iter, safe, &attribs->list, member) {
187 xorg_list_del(&iter->member);
188 free(iter->attrib_name);
189 free(iter);
190 }
191}