hid_initialisation.c

Go to the documentation of this file.
00001 
00004 #define HID_INTERNAL
00005 
00006 #include "config.h"
00007 #include <hid.h>
00008 #include <hid_helpers.h>
00009 
00010 #include <debug.h>
00011 #include <assert.h>
00012 
00015 static bool initialised = false;
00016 
00017 HIDInterface* hid_new_HIDInterface()
00018 {
00019   TRACE("creating a new HIDInterface instance...");
00020 
00021   HIDInterface* ret = (HIDInterface*)malloc(sizeof(HIDInterface));
00022   if (!ret) {
00023     ERROR("could not allocate memory for HIDInterface instance.");
00024     return 0;
00025   }
00026 
00027   hid_reset_HIDInterface(ret);
00028   return ret;
00029 }
00030 
00031 void hid_delete_HIDInterface(HIDInterface** const ixs)
00032 {
00033   if (!ixs || !*ixs) {
00034     ERROR("cannot delete NULL HIDInterface.");
00035     return;
00036   }
00037 
00038   free(*ixs);
00039   *ixs = 0;
00040 }
00041 
00042 void hid_reset_HIDInterface(HIDInterface* const hidif)
00043 {
00044   if (!hidif) {
00045     ERROR("cannot reset NULL HIDInterface.");
00046     return;
00047   }
00048 
00049   hidif->dev_handle = NULL;
00050   hidif->device = NULL;
00051   hidif->interface = -1;
00052   hidif->id[0] = '\0';
00053   hidif->hid_data = NULL;
00054   hidif->hid_parser = NULL;
00055 }
00056 
00063 hid_return hid_init()
00064 {
00065   if (hid_is_initialised()) {
00066     ERROR("cannot initialised already initialised HID library");
00067     return HID_RET_ALREADY_INITIALISED;
00068   }
00069 
00070   /* Include version to make deciphering logfiles easier: */
00071   NOTICE(PACKAGE_STRING " is being initialized.");
00072   
00073   TRACE("initialising USB subsystem...");
00074   usb_init();
00075 
00076   TRACE("scanning for USB busses...");
00077   if (usb_find_busses() < 0) {
00078     ERROR("failed to scan for USB busses");
00079     return HID_RET_FAIL_FIND_BUSSES;
00080   }
00081 
00082   TRACE("scanning for USB devices...");
00083   if (usb_find_devices() < 0) {
00084     ERROR("failed to scan for USB devices");
00085     return HID_RET_FAIL_FIND_DEVICES;
00086   }
00087 
00088   initialised = true;
00089 
00090   NOTICE("successfully initialised HID library.");
00091   return HID_RET_SUCCESS;
00092 }
00093 
00096 hid_return hid_cleanup()
00097 {
00098   if (!hid_is_initialised()) {
00099     ERROR("cannot cleanup uninitialised HID library.");
00100     return HID_RET_NOT_INITIALISED;
00101   }
00102 
00103   initialised = false;
00104   NOTICE("successfully deinitialised HID library.");
00105   return HID_RET_SUCCESS;
00106 }
00107 
00111 bool hid_is_initialised()
00112 {
00113   return initialised;
00114 }
00115 
00116 /* COPYRIGHT --
00117  *
00118  * This file is part of libhid, a user-space HID access library.
00119  * libhid is (c) 2003-2005
00120  *   Martin F. Krafft <libhid@pobox.madduck.net>
00121  *   Charles Lepple <clepple@ghz.cc>
00122  *   Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
00123  * and distributed under the terms of the GNU General Public License.
00124  * See the file ./COPYING in the source distribution for more information.
00125  *
00126  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00127  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
00128  * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00129  */

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