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
|
||||
// Written by Jérôme Duval
|
||||
//
|
||||
// devlist.c
|
||||
//
|
||||
// Copyright (c) 2004 Haiku Project
|
||||
//
|
||||
// Some portions of code are copyrighted by
|
||||
// USB Joystick driver for BeOS R5
|
||||
// Copyright 2000 (C) ITO, Takayuki
|
||||
// All rights reserved
|
||||
//
|
||||
// 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.
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Jérôme Duval
|
||||
*
|
||||
* Some portions of code are copyrighted by
|
||||
* USB Joystick driver for BeOS R5
|
||||
* Copyright 2000 (C) ITO, Takayuki. All rights reserved
|
||||
*/
|
||||
|
||||
|
||||
#include "hid.h"
|
||||
|
||||
#include <stdlib.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;
|
||||
sem_id gDeviceListLock = -1;
|
||||
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);
|
||||
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);
|
||||
assert(device != NULL);
|
||||
|
||||
acquire_sem(gDeviceListLock);
|
||||
device->next = sDeviceList;
|
||||
sDeviceList = device;
|
||||
sDeviceCount++;
|
||||
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);
|
||||
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;
|
||||
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 (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);
|
||||
for (my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next)
|
||||
{
|
||||
if (strcmp(my_dev->name, name) == 0)
|
||||
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 (my_device_list_lock);
|
||||
return my_dev;
|
||||
|
||||
release_sem(gDeviceListLock);
|
||||
return device;
|
||||
}
|
||||
|
||||
/*
|
||||
device names
|
||||
*/
|
||||
|
||||
/* dynamically generated */
|
||||
char **my_device_names = NULL;
|
||||
// #pragma mark - device names
|
||||
|
||||
void alloc_device_names (void)
|
||||
|
||||
void
|
||||
alloc_device_names(void)
|
||||
{
|
||||
assert (my_device_names == NULL);
|
||||
my_device_names = malloc (sizeof (char *) * (my_device_count + 1));
|
||||
assert(gDeviceNames == NULL);
|
||||
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;
|
||||
for (i = 0; my_device_names [i] != NULL; i++)
|
||||
free (my_device_names [i]);
|
||||
free (my_device_names);
|
||||
my_device_names = NULL;
|
||||
for (i = 0; gDeviceNames [i] != NULL; i++) {
|
||||
free(gDeviceNames[i]);
|
||||
}
|
||||
|
||||
free(gDeviceNames);
|
||||
gDeviceNames = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void rebuild_device_names (void)
|
||||
|
||||
void
|
||||
rebuild_device_names(void)
|
||||
{
|
||||
int i;
|
||||
my_device_info *my_dev;
|
||||
hid_device_info *device;
|
||||
|
||||
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));
|
||||
assert(gDeviceNames != 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));
|
||||
}
|
||||
my_device_names [i] = NULL;
|
||||
release_sem (my_device_list_lock);
|
||||
gDeviceNames[i] = NULL;
|
||||
release_sem(gDeviceListLock);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +1,16 @@
|
||||
/*****************************************************************************/
|
||||
// HID usb driver
|
||||
// Written by Jérôme Duval
|
||||
//
|
||||
// hid.h
|
||||
//
|
||||
// Copyright (c) 2004 Haiku Project
|
||||
//
|
||||
// Some portions of code are copyrighted by
|
||||
// USB Joystick driver for BeOS R5
|
||||
// Copyright 2000 (C) ITO, Takayuki
|
||||
// All rights reserved
|
||||
//
|
||||
// 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.
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
* Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Jérôme Duval
|
||||
*
|
||||
* Some portions of code are copyrighted by
|
||||
* USB Joystick driver for BeOS R5
|
||||
* Copyright 2000 (C) ITO, Takayuki. All rights reserved
|
||||
*/
|
||||
#ifndef _HID_H_
|
||||
#define _HID_H_
|
||||
|
||||
#include "hidparse.h"
|
||||
|
||||
@@ -84,10 +66,9 @@ void cbuf_unlock(cbuffer *, cpu_status);
|
||||
|
||||
struct driver_cookie;
|
||||
|
||||
typedef struct my_device_info
|
||||
{
|
||||
typedef struct hid_device_info {
|
||||
/* list structure */
|
||||
struct my_device_info *next;
|
||||
struct hid_device_info *next;
|
||||
|
||||
/* maintain device */
|
||||
sem_id sem_cb;
|
||||
@@ -118,7 +99,7 @@ typedef struct my_device_info
|
||||
bigtime_t timestamp;
|
||||
uint flags;
|
||||
bool is_keyboard;
|
||||
} my_device_info;
|
||||
} hid_device_info;
|
||||
|
||||
/* hid.c */
|
||||
|
||||
@@ -127,23 +108,23 @@ extern const char *my_driver_name;
|
||||
extern const char *keyboard_base_name;
|
||||
extern const char *mouse_base_name;
|
||||
|
||||
my_device_info *
|
||||
create_device (const usb_device *dev, const usb_interface_info *ii, uint16 ifno, bool is_keyboard);
|
||||
|
||||
void
|
||||
remove_device (my_device_info *my_dev);
|
||||
hid_device_info *create_device(const usb_device *dev, const usb_interface_info *ii,
|
||||
uint16 ifno, bool is_keyboard);
|
||||
void remove_device(hid_device_info *device);
|
||||
|
||||
/* devlist.c */
|
||||
|
||||
extern sem_id my_device_list_lock;
|
||||
extern bool my_device_list_changed;
|
||||
extern sem_id gDeviceListLock;
|
||||
extern bool gDeviceListChanged;
|
||||
|
||||
void add_device_info (my_device_info *my_dev);
|
||||
void remove_device_info (my_device_info *my_dev);
|
||||
my_device_info *search_device_info (const char *name);
|
||||
void add_device_info(hid_device_info *device);
|
||||
void remove_device_info(hid_device_info *device);
|
||||
hid_device_info *search_device_info(const char *name);
|
||||
|
||||
extern char **my_device_names;
|
||||
extern char **gDeviceNames;
|
||||
|
||||
void alloc_device_names (void);
|
||||
void free_device_names (void);
|
||||
void rebuild_device_names (void);
|
||||
void alloc_device_names(void);
|
||||
void free_device_names(void);
|
||||
void rebuild_device_names(void);
|
||||
|
||||
#endif // _HID_H_
|
||||
|
||||
Reference in New Issue
Block a user