git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18257 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-07-24 23:37:00 +00:00
parent 92c6f0417b
commit 1526fa19b6
3 changed files with 482 additions and 554 deletions
@@ -1,132 +1,126 @@
/*****************************************************************************/ /*
// HID usb driver * Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
// Written by Jérôme Duval * Distributed under the terms of the MIT License.
// *
// devlist.c * Authors:
// * Jérôme Duval
// Copyright (c) 2004 Haiku Project *
// * Some portions of code are copyrighted by
// Some portions of code are copyrighted by * USB Joystick driver for BeOS R5
// USB Joystick driver for BeOS R5 * Copyright 2000 (C) ITO, Takayuki. All rights reserved
// Copyright 2000 (C) ITO, Takayuki */
// All rights reserved
//
// Permission is hereby granted, free of charge, to any person obtaining a #include "hid.h"
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "hid.h"
sem_id my_device_list_lock = -1;
bool my_device_list_changed = true; /* added or removed */
static my_device_info *my_device_list = NULL; sem_id gDeviceListLock = -1;
static int my_device_count = 0; bool gDeviceListChanged = true; /* added or removed */
/* dynamically generated */
char **gDeviceNames = NULL;
void add_device_info (my_device_info *my_dev)
static hid_device_info *sDeviceList = NULL;
static int sDeviceCount = 0;
void
add_device_info(hid_device_info *device)
{ {
assert (my_dev != NULL); assert(device != NULL);
acquire_sem (my_device_list_lock);
my_dev->next = my_device_list; acquire_sem(gDeviceListLock);
my_device_list = my_dev; device->next = sDeviceList;
my_device_count++; sDeviceList = device;
my_device_list_changed = true; sDeviceCount++;
release_sem (my_device_list_lock); gDeviceListChanged = true;
release_sem(gDeviceListLock);
} }
void remove_device_info (my_device_info *my_dev)
void
remove_device_info(hid_device_info *device)
{ {
assert (my_dev != NULL); assert(device != NULL);
acquire_sem (my_device_list_lock);
if (my_device_list == my_dev) acquire_sem(gDeviceListLock);
my_device_list = my_dev->next;
else if (sDeviceList == device)
{ sDeviceList = device->next;
my_device_info *d; else {
for (d = my_device_list; d != NULL; d = d->next) hid_device_info *previous;
{ for (previous = sDeviceList; previous != NULL; previous = previous->next) {
if (d->next == my_dev) if (previous->next == device) {
{ previous->next = device->next;
d->next = my_dev->next; --sDeviceCount;
--my_device_count; gDeviceListChanged = true;
my_device_list_changed = true;
break; break;
} }
} }
assert (d != NULL); assert(previous != NULL);
} }
release_sem (my_device_list_lock); release_sem(gDeviceListLock);
} }
my_device_info *search_device_info (const char* name)
{
my_device_info *my_dev;
acquire_sem (my_device_list_lock); hid_device_info *
for (my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next) search_device_info(const char* name)
{ {
if (strcmp(my_dev->name, name) == 0) hid_device_info *device;
acquire_sem(gDeviceListLock);
for (device = sDeviceList; device != NULL; device = device->next) {
if (strcmp(device->name, name) == 0)
break; break;
} }
release_sem (my_device_list_lock);
return my_dev; release_sem(gDeviceListLock);
return device;
} }
/*
device names
*/
/* dynamically generated */ // #pragma mark - device names
char **my_device_names = NULL;
void alloc_device_names (void)
void
alloc_device_names(void)
{ {
assert (my_device_names == NULL); assert(gDeviceNames == NULL);
my_device_names = malloc (sizeof (char *) * (my_device_count + 1)); gDeviceNames = malloc(sizeof(char *) * (sDeviceCount + 1));
} }
void free_device_names (void)
void
free_device_names(void)
{ {
if (my_device_names != NULL) if (gDeviceNames != NULL) {
{
int i; int i;
for (i = 0; my_device_names [i] != NULL; i++) for (i = 0; gDeviceNames [i] != NULL; i++) {
free (my_device_names [i]); free(gDeviceNames[i]);
free (my_device_names); }
my_device_names = NULL;
free(gDeviceNames);
gDeviceNames = NULL;
} }
} }
void rebuild_device_names (void)
void
rebuild_device_names(void)
{ {
int i; int i;
my_device_info *my_dev; hid_device_info *device;
assert (my_device_names != NULL); assert(gDeviceNames != NULL);
acquire_sem (my_device_list_lock); acquire_sem(gDeviceListLock);
for (i = 0, my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next) for (i = 0, device = sDeviceList; device != NULL; device = device->next) {
{ gDeviceNames[i++] = strdup(device->name);
my_device_names [i++] = strdup(my_dev->name); DPRINTF_INFO((MY_ID "publishing %s\n", device->name));
DPRINTF_INFO ((MY_ID "publishing %s\n", my_dev->name));
} }
my_device_names [i] = NULL; gDeviceNames[i] = NULL;
release_sem (my_device_list_lock); release_sem(gDeviceListLock);
} }
File diff suppressed because it is too large Load Diff
+30 -49
View File
@@ -1,34 +1,16 @@
/*****************************************************************************/ /*
// HID usb driver * Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
// Written by Jérôme Duval * Distributed under the terms of the MIT License.
// *
// hid.h * Authors:
// * Jérôme Duval
// Copyright (c) 2004 Haiku Project *
// * Some portions of code are copyrighted by
// Some portions of code are copyrighted by * USB Joystick driver for BeOS R5
// USB Joystick driver for BeOS R5 * Copyright 2000 (C) ITO, Takayuki. All rights reserved
// Copyright 2000 (C) ITO, Takayuki */
// All rights reserved #ifndef _HID_H_
// #define _HID_H_
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
/*****************************************************************************/
#include "hidparse.h" #include "hidparse.h"
@@ -84,10 +66,9 @@ void cbuf_unlock(cbuffer *, cpu_status);
struct driver_cookie; struct driver_cookie;
typedef struct my_device_info typedef struct hid_device_info {
{
/* list structure */ /* list structure */
struct my_device_info *next; struct hid_device_info *next;
/* maintain device */ /* maintain device */
sem_id sem_cb; sem_id sem_cb;
@@ -118,7 +99,7 @@ typedef struct my_device_info
bigtime_t timestamp; bigtime_t timestamp;
uint flags; uint flags;
bool is_keyboard; bool is_keyboard;
} my_device_info; } hid_device_info;
/* hid.c */ /* hid.c */
@@ -127,23 +108,23 @@ extern const char *my_driver_name;
extern const char *keyboard_base_name; extern const char *keyboard_base_name;
extern const char *mouse_base_name; extern const char *mouse_base_name;
my_device_info * hid_device_info *create_device(const usb_device *dev, const usb_interface_info *ii,
create_device (const usb_device *dev, const usb_interface_info *ii, uint16 ifno, bool is_keyboard); uint16 ifno, bool is_keyboard);
void remove_device(hid_device_info *device);
void
remove_device (my_device_info *my_dev);
/* devlist.c */ /* devlist.c */
extern sem_id my_device_list_lock; extern sem_id gDeviceListLock;
extern bool my_device_list_changed; extern bool gDeviceListChanged;
void add_device_info (my_device_info *my_dev); void add_device_info(hid_device_info *device);
void remove_device_info (my_device_info *my_dev); void remove_device_info(hid_device_info *device);
my_device_info *search_device_info (const char *name); hid_device_info *search_device_info(const char *name);
extern char **my_device_names; extern char **gDeviceNames;
void alloc_device_names (void); void alloc_device_names(void);
void free_device_names (void); void free_device_names(void);
void rebuild_device_names (void); void rebuild_device_names(void);
#endif // _HID_H_