Cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18257 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -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;
|
|
||||||
static int my_device_count = 0;
|
|
||||||
|
|
||||||
void add_device_info (my_device_info *my_dev)
|
|
||||||
{
|
|
||||||
assert (my_dev != NULL);
|
|
||||||
acquire_sem (my_device_list_lock);
|
|
||||||
my_dev->next = my_device_list;
|
|
||||||
my_device_list = my_dev;
|
|
||||||
my_device_count++;
|
|
||||||
my_device_list_changed = true;
|
|
||||||
release_sem (my_device_list_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove_device_info (my_device_info *my_dev)
|
|
||||||
{
|
|
||||||
assert (my_dev != NULL);
|
|
||||||
acquire_sem (my_device_list_lock);
|
|
||||||
if (my_device_list == my_dev)
|
|
||||||
my_device_list = my_dev->next;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
my_device_info *d;
|
|
||||||
for (d = my_device_list; d != NULL; d = d->next)
|
|
||||||
{
|
|
||||||
if (d->next == my_dev)
|
|
||||||
{
|
|
||||||
d->next = my_dev->next;
|
|
||||||
--my_device_count;
|
|
||||||
my_device_list_changed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert (d != NULL);
|
|
||||||
}
|
|
||||||
release_sem (my_device_list_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
my_device_info *search_device_info (const char* name)
|
|
||||||
{
|
|
||||||
my_device_info *my_dev;
|
|
||||||
|
|
||||||
acquire_sem (my_device_list_lock);
|
|
||||||
for (my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next)
|
|
||||||
{
|
|
||||||
if (strcmp(my_dev->name, name) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
release_sem (my_device_list_lock);
|
|
||||||
return my_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
device names
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
sem_id gDeviceListLock = -1;
|
||||||
|
bool gDeviceListChanged = true; /* added or removed */
|
||||||
/* dynamically generated */
|
/* dynamically generated */
|
||||||
char **my_device_names = NULL;
|
char **gDeviceNames = NULL;
|
||||||
|
|
||||||
void alloc_device_names (void)
|
|
||||||
|
static hid_device_info *sDeviceList = NULL;
|
||||||
|
static int sDeviceCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
add_device_info(hid_device_info *device)
|
||||||
{
|
{
|
||||||
assert (my_device_names == NULL);
|
assert(device != NULL);
|
||||||
my_device_names = malloc (sizeof (char *) * (my_device_count + 1));
|
|
||||||
|
acquire_sem(gDeviceListLock);
|
||||||
|
device->next = sDeviceList;
|
||||||
|
sDeviceList = device;
|
||||||
|
sDeviceCount++;
|
||||||
|
gDeviceListChanged = true;
|
||||||
|
release_sem(gDeviceListLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_device_names (void)
|
|
||||||
|
void
|
||||||
|
remove_device_info(hid_device_info *device)
|
||||||
{
|
{
|
||||||
if (my_device_names != NULL)
|
assert(device != NULL);
|
||||||
|
|
||||||
|
acquire_sem(gDeviceListLock);
|
||||||
|
|
||||||
|
if (sDeviceList == device)
|
||||||
|
sDeviceList = device->next;
|
||||||
|
else {
|
||||||
|
hid_device_info *previous;
|
||||||
|
for (previous = sDeviceList; previous != NULL; previous = previous->next) {
|
||||||
|
if (previous->next == device) {
|
||||||
|
previous->next = device->next;
|
||||||
|
--sDeviceCount;
|
||||||
|
gDeviceListChanged = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(previous != NULL);
|
||||||
|
}
|
||||||
|
release_sem(gDeviceListLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hid_device_info *
|
||||||
|
search_device_info(const char* name)
|
||||||
|
{
|
||||||
|
hid_device_info *device;
|
||||||
|
|
||||||
|
acquire_sem(gDeviceListLock);
|
||||||
|
for (device = sDeviceList; device != NULL; device = device->next) {
|
||||||
|
if (strcmp(device->name, name) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
release_sem(gDeviceListLock);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - device names
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
alloc_device_names(void)
|
||||||
|
{
|
||||||
|
assert(gDeviceNames == NULL);
|
||||||
|
gDeviceNames = malloc(sizeof(char *) * (sDeviceCount + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
free_device_names(void)
|
||||||
|
{
|
||||||
|
if (gDeviceNames != NULL) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; gDeviceNames [i] != NULL; i++) {
|
||||||
|
free(gDeviceNames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(gDeviceNames);
|
||||||
|
gDeviceNames = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
rebuild_device_names(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; my_device_names [i] != NULL; i++)
|
hid_device_info *device;
|
||||||
free (my_device_names [i]);
|
|
||||||
free (my_device_names);
|
assert(gDeviceNames != NULL);
|
||||||
my_device_names = NULL;
|
acquire_sem(gDeviceListLock);
|
||||||
|
for (i = 0, device = sDeviceList; device != NULL; device = device->next) {
|
||||||
|
gDeviceNames[i++] = strdup(device->name);
|
||||||
|
DPRINTF_INFO((MY_ID "publishing %s\n", device->name));
|
||||||
}
|
}
|
||||||
}
|
gDeviceNames[i] = NULL;
|
||||||
|
release_sem(gDeviceListLock);
|
||||||
void rebuild_device_names (void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
my_device_info *my_dev;
|
|
||||||
|
|
||||||
assert (my_device_names != NULL);
|
|
||||||
acquire_sem (my_device_list_lock);
|
|
||||||
for (i = 0, my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next)
|
|
||||||
{
|
|
||||||
my_device_names [i++] = strdup(my_dev->name);
|
|
||||||
DPRINTF_INFO ((MY_ID "publishing %s\n", my_dev->name));
|
|
||||||
}
|
|
||||||
my_device_names [i] = NULL;
|
|
||||||
release_sem (my_device_list_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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_
|
||||||
|
|||||||
Reference in New Issue
Block a user