linux.c

Go to the documentation of this file.
00001 
00004 #define HID_INTERNAL
00005 
00006 #include <hid.h>
00007 #include <os.h>
00008 
00009 #include <debug.h>
00010 #include <assert.h>
00011 
00025 hid_return hid_os_force_claim(HIDInterface* const hidif, int const interface,
00026     HIDInterfaceMatcher const* const matcher, unsigned short retries)
00027 {
00028   if (!hidif) {
00029     ERROR("cannot open NULL HIDInterface.");
00030     return HID_RET_INVALID_PARAMETER;
00031   }
00032 
00033   if (!hid_is_opened(hidif)) {
00034     ERROR("cannot force claim interface of unopened HIDInterface.");
00035     return HID_RET_DEVICE_ALREADY_OPENED;
00036   }
00037 
00038   if (!matcher) {
00039     ERROR("cannot match against NULL HIDInterfaceMatcher.");
00040     return HID_RET_INVALID_PARAMETER;
00041   }
00042 
00043   int ret;
00044 
00045   while ((ret = usb_claim_interface(hidif->dev_handle, interface)) != 0
00046             && retries-- > 0) {
00047 
00048     TRACE("failed to claim USB device %s, trying %d more time(s)...",
00049         hidif->id, retries);
00050     
00051     TRACE("detaching kernel driver from USB device %s...", hidif->id);
00052     if (usb_detach_kernel_driver_np(hidif->dev_handle, interface) < 0) {
00053       WARNING("failed to detach kernel driver from USB device %s...",
00054           hidif->id);
00055       return HID_RET_FAIL_DETACH_DRIVER;
00056     }
00057 
00058     TRACE("trying again to claim USB device %s...", hidif->id);
00059   }
00060 
00061   if (ret == 0) return HID_RET_SUCCESS;
00062   return HID_RET_FAIL_CLAIM_IFACE;
00063 }
00064 
00065 /* COPYRIGHT --
00066  *
00067  * This file is part of libhid, a user-space HID access library.
00068  * libhid is (c) 2003-2005
00069  *   Martin F. Krafft <libhid@pobox.madduck.net>
00070  *   Charles Lepple <clepple@ghz.cc>
00071  *   Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
00072  * and distributed under the terms of the GNU General Public License.
00073  * See the file ./COPYING in the source distribution for more information.
00074  *
00075  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00076  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
00077  * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00078  */

Generated on Sun Mar 30 15:28:24 2008 for libhid by  doxygen 1.5.1