2 * Copyright (c) 2009 Ryan Huffman
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * Ryan Huffman (ryanhuffman@gmail.com)
28 #include <xf86Xinput.h>
30 #include <xf86_OSlib.h>
38 /* InputInfoPtr for main tuio device */
39 static InputInfoPtr g_pInfo
;
40 static int pipefd
[2] = {-1, -1};
42 /* Module Functions */
44 TuioPlug(pointer
, pointer
, int *, int *);
49 /* Driver Functions */
51 TuioPreInit(InputDriverPtr
, IDevPtr
, int);
54 TuioUnInit(InputDriverPtr
, InputInfoPtr
, int);
57 TuioObjReadInput(InputInfoPtr pInfo
);
60 TuioReadInput(InputInfoPtr
);
63 TuioControl(DeviceIntPtr
, int);
65 /* Internal Functions */
67 _hal_create_devices(InputInfoPtr pInfo
, int num
);
70 _init_buttons(DeviceIntPtr device
);
73 _init_axes(DeviceIntPtr device
);
76 _tuio_lo_2dcur_handle(const char *path
,
84 _free_tuiodev(TuioDevicePtr pTuio
);
91 /* Object and Subdev list manipulation functions */
93 _object_get(ObjectPtr head
, int id
);
99 _object_add(ObjectPtr
*obj_list
, ObjectPtr obj
);
102 _object_remove(ObjectPtr
*obj_list
, int id
);
105 _subdev_add(InputInfoPtr pInfo
, SubDevicePtr subdev
);
108 _subdev_remove(InputInfoPtr pInfo
, InputInfoPtr sub_pInfo
);
111 _subdev_get(InputInfoPtr pInfo
, SubDevicePtr
*subdev_list
);
114 _hal_remove_device(InputInfoPtr pInfo
);
116 /* Driver information */
117 static XF86ModuleVersionInfo TuioVersionRec
=
123 XORG_VERSION_CURRENT
,
124 PACKAGE_VERSION_MAJOR
, PACKAGE_VERSION_MINOR
, PACKAGE_VERSION_PATCHLEVEL
,
131 _X_EXPORT InputDriverRec TUIO
=
142 _X_EXPORT XF86ModuleData tuioModuleData
=
150 TuioPlug(pointer module
,
155 xf86AddInputDriver(&TUIO
, module
, 0);
163 TuioUnplug(pointer p
)
168 * Pre-initialization of new device
169 * This can be entered by either a "core" tuio device
170 * or an extension "Object" device that is used for routing individual object
174 TuioPreInit(InputDriverPtr drv
,
179 TuioDevicePtr pTuio
= NULL
;
182 int num_subdev
, tuio_port
;
184 if (!(pInfo
= xf86AllocateInput(drv
, 0)))
187 /* If Type == Object, this is a device for an object to use */
188 type
= xf86CheckStrOption(dev
->commonOptions
, "Type", NULL
);
190 if (type
!= NULL
&& strcmp(type
, "Object") == 0) {
191 xf86Msg(X_INFO
, "%s: TUIO subdevice found\n", dev
->identifier
);
195 if (!(pTuio
= xcalloc(1, sizeof(TuioDeviceRec
)))) {
196 xf86DeleteInput(pInfo
, 0);
201 pInfo
->private = pTuio
;
203 pTuio
->num_subdev
= 0;
205 /* Get the number of subdevices we need to create */
206 num_subdev
= xf86CheckIntOption(dev
->commonOptions
, "SubDevices",
208 if (num_subdev
> MAX_SUBDEVICES
) {
209 num_subdev
= MAX_SUBDEVICES
;
210 } else if (num_subdev
< MIN_SUBDEVICES
) {
211 num_subdev
= MIN_SUBDEVICES
;
213 pTuio
->init_num_subdev
= num_subdev
;
215 /* Get the TUIO port number to use */
216 tuio_port
= xf86CheckIntOption(dev
->commonOptions
, "Port", DEFAULT_PORT
);
217 if (tuio_port
< 0 || tuio_port
> 65535) {
218 xf86Msg(X_INFO
, "%s: Invalid port number (%i), defaulting to %i\n",
219 dev
->identifier
, tuio_port
, DEFAULT_PORT
);
220 tuio_port
= DEFAULT_PORT
;
222 xf86Msg(X_INFO
, "%s: TUIO UDP Port set to %i\n",
223 dev
->identifier
, tuio_port
);
224 pTuio
->tuio_port
= tuio_port
;
226 /* Get setting for checking fseq numbers in TUIO packets */
227 pTuio
->fseq_threshold
= xf86CheckIntOption(dev
->commonOptions
,
228 "FseqThreshold", 100);
229 if (pTuio
->fseq_threshold
< 0) {
230 pTuio
->fseq_threshold
= 0;
232 xf86Msg(X_INFO
, "%s: FseqThreshold set to %i\n",
233 dev
->identifier
, pTuio
->fseq_threshold
);
235 /* Get setting for whether to send button events or not with
236 * object add & remove */
237 pTuio
->post_button_events
= xf86CheckBoolOption(dev
->commonOptions
,
238 "PostButtonEvents", True
);
241 /* Set up InputInfoPtr */
242 pInfo
->name
= xstrdup(dev
->identifier
);
244 pInfo
->type_name
= XI_TOUCHSCREEN
; /* FIXME: Correct type? */
245 pInfo
->conf_idev
= dev
;
246 pInfo
->read_input
= pTuio
? TuioReadInput
: TuioObjReadInput
; /* Set callback */
247 pInfo
->device_control
= TuioControl
; /* Set callback */
248 pInfo
->switch_mode
= NULL
;
250 /* Process common device options */
251 xf86CollectInputOptions(pInfo
, NULL
, NULL
);
252 xf86ProcessCommonOptions(pInfo
, pInfo
->options
);
254 pInfo
->flags
|= XI86_OPEN_ON_INIT
;
255 pInfo
->flags
|= XI86_CONFIGURED
;
264 TuioUnInit(InputDriverPtr drv
,
268 xf86DeleteInput(pInfo
, 0);
272 * Empty callback for object device.
275 TuioObjReadInput(InputInfoPtr pInfo
) {
280 * Handle new TUIO data on the socket
283 TuioReadInput(InputInfoPtr pInfo
)
285 TuioDevicePtr pTuio
= pInfo
->private;
286 ObjectPtr
*obj_list
= &pTuio
->obj_list
;
287 ObjectPtr obj
= pTuio
->obj_list
;
288 SubDevicePtr
*subdev_list
= &pTuio
->subdev_list
;
292 while (xf86WaitForInput(pInfo
->fd
, 0) > 0)
294 /* The liblo handler will set this flag if anything was processed */
295 pTuio
->processed
= 0;
297 /* liblo will receive a message and call the appropriate
298 * handlers (i.e. _tuio_lo_cur2d_hande()) */
299 lo_server_recv_noblock(pTuio
->server
, 0);
301 /* During the processing of the previous message/bundle,
302 * any "active" messages will be handled by flagging
303 * the listed object ids. Now that processing is done,
304 * remove any dead object ids and set any pending changes.
305 * Also check to make sure the processed data was newer than
306 * the last processed data */
307 if (pTuio
->processed
&&
308 (pTuio
->fseq_new
> pTuio
->fseq_old
||
309 pTuio
->fseq_old
- pTuio
->fseq_new
> pTuio
->fseq_threshold
)) {
311 while (obj
!= NULL
) {
313 if (obj
->subdev
&& pTuio
->post_button_events
) {
314 /* Post button "up" event */
315 xf86PostButtonEvent(obj
->subdev
->pInfo
->dev
, TRUE
, 1, FALSE
, 0, 0);
318 obj
= _object_remove(obj_list
, obj
->id
);
319 _subdev_add(pInfo
, obj
->subdev
);
324 /* Object is alive. Check to see if an update has been set.
325 * If it has been updated and it has a subdevice to send
326 * events on, send the event) */
327 if (obj
->pending
.set
&& obj
->subdev
) {
328 obj
->x
= obj
->pending
.x
;
329 obj
->y
= obj
->pending
.y
;
330 obj
->pending
.set
= False
;
332 /* OKAY FOR NOW, maybe update with a better range? */
333 /* TODO: Add more valuators with additional information */
334 valuators
[0] = obj
->x
* 0x7FFFFFFF;
335 valuators
[1] = obj
->y
* 0x7FFFFFFF;
337 xf86PostMotionEventP(obj
->subdev
->pInfo
->dev
,
338 TRUE
, /* is_absolute */
339 0, /* first_valuator */
340 2, /* num_valuators */
343 if (obj
->pending
.button
) {
344 xf86PostButtonEvent(obj
->subdev
->pInfo
->dev
, TRUE
, 1, TRUE
, 0, 0);
345 obj
->pending
.button
= False
;
348 obj
->alive
= 0; /* Reset for next message */
352 pTuio
->fseq_old
= pTuio
->fseq_new
;
358 * Handle device state changes
361 TuioControl(DeviceIntPtr device
,
364 InputInfoPtr pInfo
= device
->public.devicePrivate
;
365 TuioDevicePtr pTuio
= pInfo
->private;
373 xf86Msg(X_INFO
, "%s: Init\n", pInfo
->name
);
374 _init_buttons(device
);
377 /* If this is a "core" device, create object devices */
379 _hal_create_devices(pInfo
, pTuio
->init_num_subdev
);
383 case DEVICE_ON
: /* Open socket and start listening! */
384 xf86Msg(X_INFO
, "%s: On.\n", pInfo
->name
);
385 if (device
->public.on
)
388 /* If this is an object device, use a dummy pipe,
389 * and add device to subdev list */
391 if (pipefd
[0] == -1) {
392 SYSCALL(res
= pipe(pipefd
));
394 xf86Msg(X_ERROR
, "%s: failed to open pipe\n",
400 pInfo
->fd
= pipefd
[0];
406 asprintf(&tuio_port
, "%i", pTuio
->tuio_port
);
407 pTuio
->server
= lo_server_new_with_proto(tuio_port
, LO_UDP
, _lo_error
);
408 if (pTuio
->server
== NULL
) {
409 xf86Msg(X_ERROR
, "%s: Error allocating new lo_server\n",
414 /* Register to receive all /tuio/2Dcur messages */
415 lo_server_add_method(pTuio
->server
, "/tuio/2Dcur", NULL
,
416 _tuio_lo_2dcur_handle
, pInfo
);
418 pInfo
->fd
= lo_server_get_socket_fd(pTuio
->server
);
420 xf86FlushInput(pInfo
->fd
);
422 finish
: xf86AddEnabledDevice(pInfo
);
423 device
->public.on
= TRUE
;
425 /* Allocate device storage and add to device list */
426 subdev
= xcalloc(1, sizeof(SubDeviceRec
));
427 subdev
->pInfo
= pInfo
;
428 _subdev_add(g_pInfo
, subdev
);
432 xf86Msg(X_INFO
, "%s: Off\n", pInfo
->name
);
433 if (!device
->public.on
)
436 xf86RemoveEnabledDevice(pInfo
);
439 lo_server_free(pTuio
->server
);
442 /* Remove subdev from list - This applies for both subdevices
443 * and the "core" device */
444 _subdev_remove(g_pInfo
, pInfo
);
446 device
->public.on
= FALSE
;
450 xf86Msg(X_INFO
, "%s: Close\n", pInfo
->name
);
451 _hal_remove_device(pInfo
);
459 * Initialize the device properties
466 * Free a TuioDeviceRec
469 _free_tuiodev(TuioDevicePtr pTuio
) {
470 ObjectPtr obj
= pTuio
->obj_list
;
473 while (obj
!= NULL
) {
483 * Handles OSC messages in the /tuio/2Dcur address space
486 _tuio_lo_2dcur_handle(const char *path
,
492 InputInfoPtr pInfo
= user_data
;
493 TuioDevicePtr pTuio
= pInfo
->private;
494 ObjectPtr
*obj_list
= &pTuio
->obj_list
;
495 ObjectPtr obj
, objtemp
;
500 xf86Msg(X_ERROR
, "%s: Error in /tuio/cur2d (argc == 0)\n",
503 } else if(*types
!= 's') {
504 xf86Msg(X_ERROR
, "%s: Error in /tuio/cur2d (types[0] != 's')\n",
509 /* Flag as being processed, used in TuioReadInput() */
510 pTuio
->processed
= 1;
512 /* Parse message type */
513 /* Set message type: */
514 if (strcmp((char *)argv
[0], "set") == 0) {
516 /* Simple type check */
517 if (strcmp(types
, "sifffff")) {
518 xf86Msg(X_ERROR
, "%s: Error in /tuio/cur2d set msg (types == %s)\n",
523 obj
= _object_get(*obj_list
, argv
[1]->i
);
525 /* If not found, create a new object */
527 obj
= _object_new(argv
[1]->i
);
528 _object_add(obj_list
, obj
);
529 obj
->subdev
= _subdev_get(pInfo
, &pTuio
->subdev_list
);
530 if (obj
->subdev
&& pTuio
->post_button_events
)
531 obj
->pending
.button
= True
;
534 obj
->pending
.x
= argv
[2]->f
;
535 obj
->pending
.y
= argv
[3]->f
;
536 obj
->pending
.set
= True
;
538 } else if (strcmp((char *)argv
[0], "alive") == 0) {
539 /* Mark all objects that are still alive */
541 while (obj
!= NULL
) {
542 for (i
=1; i
<argc
; i
++) {
543 if (argv
[i
]->i
== obj
->id
) {
551 } else if (strcmp((char *)argv
[0], "fseq") == 0) {
552 /* Simple type check */
553 if (strcmp(types
, "si")) {
554 xf86Msg(X_ERROR
, "%s: Error in /tuio/cur2d fseq msg (types == %s)\n",
558 pTuio
->fseq_new
= argv
[1]->i
;
565 * liblo error handler
572 xf86Msg(X_ERROR
, "liblo: %s\n", msg
);
576 * Retrieves an object from a list based on its id.
578 * @return NULL if not found.
581 _object_get(ObjectPtr head
, int id
) {
582 ObjectPtr obj
= head
;
584 while (obj
!= NULL
&& obj
->id
!= id
) {
592 * Allocates and inserts a new object at the beginning of a list.
593 * Pointer to the new object is returned.
594 * Doesn't check for duplicate ids, so call _object_get() beforehand
595 * to make sure it doesn't exist already!!
597 * @return ptr to newly inserted object
600 _object_new(int id
) {
601 ObjectPtr new_obj
= xcalloc(1, sizeof(ObjectRec
));
604 new_obj
->alive
= True
;
610 * Adds a SubDevice to the beginning of the subdev_list list
613 _object_add(ObjectPtr
*obj_list
, ObjectPtr obj
) {
615 if (obj_list
== NULL
|| obj
== NULL
)
618 if (*obj_list
!= NULL
) {
619 obj
->next
= *obj_list
;
626 * Removes an Object with a specific id from a list.
629 _object_remove(ObjectPtr
*obj_list
, int id
) {
630 ObjectPtr obj
= *obj_list
;
633 if (obj
== NULL
) return; /* Empty list */
635 if (obj
->id
== id
) { /* Remove from head */
636 *obj_list
= obj
->next
;
638 while (obj
->next
!= NULL
) {
639 if (obj
->next
->id
== id
) {
641 obj
->next
= objtmp
->next
;
655 * Adds a SubDevice to the beginning of the subdev_list list
658 _subdev_add(InputInfoPtr pInfo
, SubDevicePtr subdev
) {
659 TuioDevicePtr pTuio
= pInfo
->private;
660 SubDevicePtr
*subdev_list
= &pTuio
->subdev_list
;
661 ObjectPtr obj
= pTuio
->obj_list
;
663 if (subdev_list
== NULL
|| subdev
== NULL
)
666 /* First check to see if there are any objects that don't have a
667 * subdevice that we can assign this subdevice to */
668 while (obj
!= NULL
) {
669 if (obj
->subdev
== NULL
) {
670 obj
->subdev
= subdev
;
671 if (pTuio
->post_button_events
)
672 obj
->pending
.button
= True
;
673 obj
->pending
.set
= True
;
679 /* No subdevice-less objects, add to front of subdev list */
680 if (*subdev_list
!= NULL
) {
681 subdev
->next
= *subdev_list
;
683 *subdev_list
= subdev
;
687 * Gets any available subdevice
690 _subdev_get(InputInfoPtr pInfo
, SubDevicePtr
*subdev_list
) {
693 if (subdev_list
== NULL
|| *subdev_list
== NULL
) {
694 _hal_create_devices(pInfo
, 1); /* Create one new subdevice */
698 subdev
= *subdev_list
;
699 *subdev_list
= subdev
->next
;
706 _subdev_remove(InputInfoPtr pInfo
, InputInfoPtr sub_pInfo
)
708 TuioDevicePtr pTuio
= pInfo
->private;
709 SubDevicePtr
*subdev_list
= &pTuio
->subdev_list
;
710 SubDevicePtr subdev
= *subdev_list
, last
;
711 ObjectPtr obj
= pTuio
->obj_list
;
714 /* First try to find it in the list of subdevices */
715 if (subdev
!= NULL
&& subdev
->pInfo
== sub_pInfo
) {
717 *subdev_list
= subdev
->next
;
719 } else if (subdev
!= NULL
) {
721 subdev
= subdev
->next
;
722 while (subdev
!= NULL
) {
723 if (subdev
->pInfo
== sub_pInfo
) {
724 last
->next
= subdev
->next
;
730 subdev
= subdev
->next
;
734 /* If it still hasn't been found, find the object that is holding
737 while (obj
!= NULL
) {
738 if (obj
->subdev
!= NULL
&& obj
->subdev
->pInfo
== sub_pInfo
) {
750 * Init the button map device. We only use one button.
753 _init_buttons(DeviceIntPtr device
)
755 InputInfoPtr pInfo
= device
->public.devicePrivate
;
762 map
= xcalloc(numbuttons
, sizeof(CARD8
));
763 labels
= xcalloc(numbuttons
, sizeof(Atom
));
764 for (i
=0; i
<numbuttons
; i
++)
767 if (!InitButtonClassDeviceStruct(device
, numbuttons
/* 1 button */,
768 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
772 xf86Msg(X_ERROR
, "%s: Failed to register buttons.\n", pInfo
->name
);
781 * Init valuators for device, use x/y coordinates.
784 _init_axes(DeviceIntPtr device
)
786 InputInfoPtr pInfo
= device
->public.devicePrivate
;
788 const int num_axes
= 2;
791 atoms
= xcalloc(num_axes
, sizeof(Atom
));
793 if (!InitValuatorClassDeviceStruct(device
,
795 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
798 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
801 GetMotionHistorySize(),
805 for (i
= 0; i
< num_axes
; i
++)
807 xf86InitValuatorAxisStruct(device
, i
,
808 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
811 0, 0x7FFFFFFF, 1, 1, 1);
812 xf86InitValuatorDefaults(device
, i
);
815 /* Use absolute mode. Currently, TUIO coords are mapped to the
816 * full screen area */
817 pInfo
->dev
->valuator
->mode
= Absolute
;
818 if (!InitAbsoluteClassDeviceStruct(device
))
825 * New device creation through hal
826 * I referenced the wacom hal-setup patch while writing this:
827 * http://cvs.fedoraproject.org/viewvc/rpms/linuxwacom/devel/linuxwacom-0.8.2.2-hal-setup.patch?revision=1.1&view=markup
829 * @return 0 if successful, 1 if failure
832 _hal_create_devices(InputInfoPtr pInfo
, int num
) {
833 TuioDevicePtr pTuio
= pInfo
->private;
835 DBusConnection
*conn
;
841 /* We need a new device to send motion/button events through.
842 * There isn't a great way to do this right now without native
843 * blob events, so just hack it out for now. Woot. */
845 /* Open connection to dbus and create contex */
846 dbus_error_init(&error
);
847 if ((conn
= dbus_bus_get(DBUS_BUS_SYSTEM
, &error
)) == NULL
) {
848 xf86Msg(X_ERROR
, "%s: Failed to open dbus connection: %s\n",
849 pInfo
->name
, error
.message
);
853 if ((ctx
= libhal_ctx_new()) == NULL
) {
854 xf86Msg(X_ERROR
, "%s: Failed to obtain hal context\n",
859 dbus_error_init(&error
);
860 libhal_ctx_set_dbus_connection(ctx
, conn
);
861 if (!libhal_ctx_init(ctx
, &error
)) {
862 xf86Msg(X_ERROR
, "%s: Failed to initialize hal context: %s\n",
863 pInfo
->name
, error
.message
);
867 /* Create new devices through hal */
868 for (i
=0; i
<num
; i
++) {
870 dbus_error_init(&error
);
871 newdev
= libhal_new_device(ctx
, &error
);
872 if (dbus_error_is_set(&error
) == TRUE
) {
873 xf86Msg(X_ERROR
, "%s: Failed to create input device: %s\n",
874 pInfo
->name
, error
.message
);
878 dbus_error_init(&error
);
879 libhal_device_set_property_string(ctx
, newdev
, "input.device",
880 "tuio_subdevice", &error
);
881 if (dbus_error_is_set(&error
) == TRUE
) {
882 xf86Msg(X_ERROR
, "%s: Failed to set hal property: %s\n",
883 pInfo
->name
, error
.message
);
887 dbus_error_init(&error
);
888 libhal_device_set_property_bool(ctx
, newdev
, "RequireEnable",
890 if (dbus_error_is_set(&error
) == TRUE
) {
891 xf86Msg(X_ERROR
, "%s: Failed to set hal property: %s\n",
892 pInfo
->name
, error
.message
);
896 dbus_error_init(&error
);
897 libhal_device_set_property_string(ctx
, newdev
,
898 "input.x11_driver", "tuio",
900 if (dbus_error_is_set(&error
) == TRUE
) {
901 xf86Msg(X_ERROR
, "%s: Failed to set hal property: %s\n",
902 pInfo
->name
, error
.message
);
906 /* Set "Type" property. This will be used in TuioPreInit to determine
907 * whether the new device is a subdev or not */
908 dbus_error_init(&error
);
909 libhal_device_set_property_string(ctx
, newdev
,
910 "input.x11_options.Type",
912 if (dbus_error_is_set(&error
) == TRUE
) {
913 xf86Msg(X_ERROR
, "%s: Failed to set hal property: %s\n",
914 pInfo
->name
, error
.message
);
918 asprintf(&name
, "%s subdev %i", pInfo
->name
, pTuio
->num_subdev
);
921 dbus_error_init(&error
);
922 libhal_device_set_property_string(ctx
, newdev
,
923 "info.product", name
,
925 if (dbus_error_is_set(&error
) == TRUE
) {
926 xf86Msg(X_ERROR
, "%s: Failed to set hal property: %s\n",
927 pInfo
->name
, error
.message
);
931 /* Finalize creation of new device */
932 dbus_error_init(&error
);
933 libhal_device_commit_to_gdl(ctx
, newdev
, "/org/freedesktop/Hal/devices/tuio_subdev", &error
);
934 if (dbus_error_is_set (&error
) == TRUE
) {
935 xf86Msg(X_ERROR
, "%s: Failed to add input device: %s\n",
936 pInfo
->name
, error
.message
);
944 if (!libhal_ctx_shutdown(ctx
, &error
)) {
945 xf86Msg(X_ERROR
, "%s: Unable to shutdown hal context: %s\n",
946 pInfo
->name
, error
.message
);
949 libhal_ctx_free(ctx
);
955 _hal_remove_device(InputInfoPtr pInfo
) {
957 DBusConnection
*conn
;
962 xf86Msg(X_INFO
, "%s: Removing subdevice\n",
965 /* Open connection to dbus and create contex */
966 dbus_error_init(&error
);
967 if ((conn
= dbus_bus_get(DBUS_BUS_SYSTEM
, &error
)) == NULL
) {
968 xf86Msg(X_ERROR
, "%s: Failed to open dbus connection: %s\n",
969 pInfo
->name
, error
.message
);
973 if ((ctx
= libhal_ctx_new()) == NULL
) {
974 xf86Msg(X_ERROR
, "%s: Failed to obtain hal context\n",
979 dbus_error_init(&error
);
980 libhal_ctx_set_dbus_connection(ctx
, conn
);
981 if (!libhal_ctx_init(ctx
, &error
)) {
982 xf86Msg(X_ERROR
, "%s: Failed to initialize hal context: %s\n",
983 pInfo
->name
, error
.message
);
987 devices
= libhal_manager_find_device_string_match(ctx
, "info.product",
991 if (dbus_error_is_set(&error
) == TRUE
) {
992 xf86Msg(X_ERROR
, "%s: Failed when trying to find device: %s\n",
993 pInfo
->name
, error
.message
);
997 if (num_devices
== 0) {
998 xf86Msg(X_ERROR
, "%s: Unable to find subdevice in HAL GDL\n",
1001 for (i
=0; i
<num_devices
; i
++) {
1002 xf86Msg(X_INFO
, "%s: Removing subdevice with udi '%s'\n",
1003 pInfo
->name
, devices
[i
]);
1004 if (!libhal_remove_device(ctx
, devices
[i
], &error
)) {
1005 xf86Msg(X_ERROR
, "%s: Unable to remove subdevice: %s\n",
1006 pInfo
->name
, error
.message
);
1011 if (!libhal_ctx_shutdown(ctx
, &error
)) {
1012 xf86Msg(X_ERROR
, "%s: Unable to shutdown hal context: %s\n",
1013 pInfo
->name
, error
.message
);
1016 libhal_ctx_free(ctx
);