Move DeviceList class to hid_shared.
It was shared among 3 different HID drivers, now there is just one common copy.
This commit is contained in:
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
Generic device list for use in drivers.
|
|
||||||
Copyright (C) 2008 Michael Lotz <[email protected]>
|
|
||||||
Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
#include "DeviceList.h"
|
|
||||||
#include <util/kernel_cpp.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
struct device_list_entry {
|
|
||||||
char * name;
|
|
||||||
void * device;
|
|
||||||
device_list_entry * next;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
DeviceList::DeviceList()
|
|
||||||
: fDeviceList(NULL),
|
|
||||||
fDeviceCount(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DeviceList::~DeviceList()
|
|
||||||
{
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
device_list_entry *next = current->next;
|
|
||||||
free(current->name);
|
|
||||||
delete current;
|
|
||||||
current = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
DeviceList::AddDevice(const char *name, void *device)
|
|
||||||
{
|
|
||||||
device_list_entry *entry = new(std::nothrow) device_list_entry;
|
|
||||||
if (entry == NULL)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
entry->name = strdup(name);
|
|
||||||
if (entry->name == NULL) {
|
|
||||||
delete entry;
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry->device = device;
|
|
||||||
entry->next = NULL;
|
|
||||||
|
|
||||||
if (fDeviceList == NULL)
|
|
||||||
fDeviceList = entry;
|
|
||||||
else {
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if (current->next == NULL) {
|
|
||||||
current->next = entry;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fDeviceCount++;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
DeviceList::RemoveDevice(const char *name, void *device)
|
|
||||||
{
|
|
||||||
if (name == NULL && device == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
device_list_entry *previous = NULL;
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if ((name != NULL && strcmp(current->name, name) == 0)
|
|
||||||
|| (device != NULL && current->device == device)) {
|
|
||||||
if (previous == NULL)
|
|
||||||
fDeviceList = current->next;
|
|
||||||
else
|
|
||||||
previous->next = current->next;
|
|
||||||
|
|
||||||
free(current->name);
|
|
||||||
delete current;
|
|
||||||
fDeviceCount--;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
previous = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *
|
|
||||||
DeviceList::FindDevice(const char *name, void *device)
|
|
||||||
{
|
|
||||||
if (name == NULL && device == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if ((name != NULL && strcmp(current->name, name) == 0)
|
|
||||||
|| (device != NULL && current->device == device))
|
|
||||||
return current->device;
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
|
||||||
DeviceList::CountDevices(const char *baseName)
|
|
||||||
{
|
|
||||||
if (baseName == NULL)
|
|
||||||
return fDeviceCount;
|
|
||||||
|
|
||||||
int32 count = 0;
|
|
||||||
int32 baseNameLength = strlen(baseName);
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if (strncmp(current->name, baseName, baseNameLength) == 0)
|
|
||||||
count++;
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *
|
|
||||||
DeviceList::DeviceAt(int32 index)
|
|
||||||
{
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if (index-- == 0)
|
|
||||||
return current->device;
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
Generic device list for use in drivers.
|
|
||||||
Copyright (C) 2008 Michael Lotz <[email protected]>
|
|
||||||
Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
#ifndef _DEVICE_LIST_H_
|
|
||||||
#define _DEVICE_LIST_H_
|
|
||||||
|
|
||||||
#include <OS.h>
|
|
||||||
|
|
||||||
struct device_list_entry;
|
|
||||||
|
|
||||||
class DeviceList {
|
|
||||||
public:
|
|
||||||
DeviceList();
|
|
||||||
~DeviceList();
|
|
||||||
|
|
||||||
status_t AddDevice(const char *name, void *device);
|
|
||||||
status_t RemoveDevice(const char *name, void *device = NULL);
|
|
||||||
void * FindDevice(const char *name, void *device = NULL);
|
|
||||||
|
|
||||||
int32 CountDevices(const char *baseName = NULL);
|
|
||||||
void * DeviceAt(int32 index);
|
|
||||||
|
|
||||||
private:
|
|
||||||
device_list_entry * fDeviceList;
|
|
||||||
int32 fDeviceCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _DEVICE_LIST_H_
|
|
||||||
@@ -8,6 +8,8 @@ SubDirSysHdrs $(SUBDIR) $(DOTDOT) hid_shared ;
|
|||||||
UsePrivateHeaders [ FDirName kernel util ] input drivers device i2c ;
|
UsePrivateHeaders [ FDirName kernel util ] input drivers device i2c ;
|
||||||
UsePrivateKernelHeaders ;
|
UsePrivateKernelHeaders ;
|
||||||
|
|
||||||
|
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel drivers input hid_shared ] ;
|
||||||
|
|
||||||
KernelAddon i2c_elan :
|
KernelAddon i2c_elan :
|
||||||
DeviceList.cpp
|
DeviceList.cpp
|
||||||
Driver.cpp
|
Driver.cpp
|
||||||
|
|||||||
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
Generic device list for use in drivers.
|
|
||||||
Copyright (C) 2008 Michael Lotz <[email protected]>
|
|
||||||
Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
#include "DeviceList.h"
|
|
||||||
#include <util/kernel_cpp.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
struct device_list_entry {
|
|
||||||
char * name;
|
|
||||||
void * device;
|
|
||||||
device_list_entry * next;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
DeviceList::DeviceList()
|
|
||||||
: fDeviceList(NULL),
|
|
||||||
fDeviceCount(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DeviceList::~DeviceList()
|
|
||||||
{
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
device_list_entry *next = current->next;
|
|
||||||
free(current->name);
|
|
||||||
delete current;
|
|
||||||
current = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
DeviceList::AddDevice(const char *name, void *device)
|
|
||||||
{
|
|
||||||
device_list_entry *entry = new(std::nothrow) device_list_entry;
|
|
||||||
if (entry == NULL)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
entry->name = strdup(name);
|
|
||||||
if (entry->name == NULL) {
|
|
||||||
delete entry;
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry->device = device;
|
|
||||||
entry->next = NULL;
|
|
||||||
|
|
||||||
if (fDeviceList == NULL)
|
|
||||||
fDeviceList = entry;
|
|
||||||
else {
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if (current->next == NULL) {
|
|
||||||
current->next = entry;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fDeviceCount++;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
DeviceList::RemoveDevice(const char *name, void *device)
|
|
||||||
{
|
|
||||||
if (name == NULL && device == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
device_list_entry *previous = NULL;
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if ((name != NULL && strcmp(current->name, name) == 0)
|
|
||||||
|| (device != NULL && current->device == device)) {
|
|
||||||
if (previous == NULL)
|
|
||||||
fDeviceList = current->next;
|
|
||||||
else
|
|
||||||
previous->next = current->next;
|
|
||||||
|
|
||||||
free(current->name);
|
|
||||||
delete current;
|
|
||||||
fDeviceCount--;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
previous = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *
|
|
||||||
DeviceList::FindDevice(const char *name, void *device)
|
|
||||||
{
|
|
||||||
if (name == NULL && device == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if ((name != NULL && strcmp(current->name, name) == 0)
|
|
||||||
|| (device != NULL && current->device == device))
|
|
||||||
return current->device;
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
|
||||||
DeviceList::CountDevices(const char *baseName)
|
|
||||||
{
|
|
||||||
if (baseName == NULL)
|
|
||||||
return fDeviceCount;
|
|
||||||
|
|
||||||
int32 count = 0;
|
|
||||||
int32 baseNameLength = strlen(baseName);
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if (strncmp(current->name, baseName, baseNameLength) == 0)
|
|
||||||
count++;
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *
|
|
||||||
DeviceList::DeviceAt(int32 index)
|
|
||||||
{
|
|
||||||
device_list_entry *current = fDeviceList;
|
|
||||||
while (current) {
|
|
||||||
if (index-- == 0)
|
|
||||||
return current->device;
|
|
||||||
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
Generic device list for use in drivers.
|
|
||||||
Copyright (C) 2008 Michael Lotz <[email protected]>
|
|
||||||
Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
#ifndef _DEVICE_LIST_H_
|
|
||||||
#define _DEVICE_LIST_H_
|
|
||||||
|
|
||||||
#include <OS.h>
|
|
||||||
|
|
||||||
struct device_list_entry;
|
|
||||||
|
|
||||||
class DeviceList {
|
|
||||||
public:
|
|
||||||
DeviceList();
|
|
||||||
~DeviceList();
|
|
||||||
|
|
||||||
status_t AddDevice(const char *name, void *device);
|
|
||||||
status_t RemoveDevice(const char *name, void *device = NULL);
|
|
||||||
void * FindDevice(const char *name, void *device = NULL);
|
|
||||||
|
|
||||||
int32 CountDevices(const char *baseName = NULL);
|
|
||||||
void * DeviceAt(int32 index);
|
|
||||||
|
|
||||||
private:
|
|
||||||
device_list_entry * fDeviceList;
|
|
||||||
int32 fDeviceCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _DEVICE_LIST_H_
|
|
||||||
Reference in New Issue
Block a user