2 * Copyright 2004-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
8 * Some portions of code are copyrighted by
9 * USB Joystick driver for BeOS R5
10 * Copyright 2000 (C) ITO, Takayuki. All rights reserved
20 sem_id gDeviceListLock
= -1;
21 bool gDeviceListChanged
= true; /* added or removed */
22 /* dynamically generated */
23 char **gDeviceNames
= NULL
;
26 static pegasus_dev
*sDeviceList
= NULL
;
27 static int sDeviceCount
= 0;
31 add_device_info(pegasus_dev
*device
)
33 ASSERT(device
!= NULL
);
35 acquire_sem(gDeviceListLock
);
36 device
->next
= sDeviceList
;
39 gDeviceListChanged
= true;
40 release_sem(gDeviceListLock
);
45 remove_device_info(pegasus_dev
*device
)
47 ASSERT(device
!= NULL
);
49 acquire_sem(gDeviceListLock
);
51 if (sDeviceList
== device
) {
52 sDeviceList
= device
->next
;
54 gDeviceListChanged
= true;
56 pegasus_dev
*previous
;
57 for (previous
= sDeviceList
; previous
!= NULL
; previous
= previous
->next
) {
58 if (previous
->next
== device
) {
59 previous
->next
= device
->next
;
61 gDeviceListChanged
= true;
65 ASSERT(previous
!= NULL
);
67 release_sem(gDeviceListLock
);
72 search_device_info(const char* name
)
76 acquire_sem(gDeviceListLock
);
77 for (device
= sDeviceList
; device
!= NULL
; device
= device
->next
) {
78 if (strcmp(device
->name
, name
) == 0)
82 release_sem(gDeviceListLock
);
87 // #pragma mark - device names
91 alloc_device_names(void)
93 ASSERT(gDeviceNames
== NULL
);
94 gDeviceNames
= malloc(sizeof(char *) * (sDeviceCount
+ 1));
99 free_device_names(void)
101 if (gDeviceNames
!= NULL
) {
103 for (i
= 0; gDeviceNames
[i
] != NULL
; i
++) {
104 free(gDeviceNames
[i
]);
114 rebuild_device_names(void)
119 ASSERT(gDeviceNames
!= NULL
);
120 acquire_sem(gDeviceListLock
);
121 for (i
= 0, device
= sDeviceList
; device
!= NULL
; device
= device
->next
) {
122 gDeviceNames
[i
++] = strdup(device
->name
);
123 DPRINTF_INFO(MY_ID
"publishing %s\n", device
->name
);
125 gDeviceNames
[i
] = NULL
;
126 release_sem(gDeviceListLock
);