Changes in uspace/lib/usbhid/src/hidpath.c [ae3a941:b7fd2a0] in mainline
- File:
-
- 1 edited
-
uspace/lib/usbhid/src/hidpath.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidpath.c
rae3a941 rb7fd2a0 73 73 * @return Error code 74 74 */ 75 errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 76 int32_t usage_page, int32_t usage)77 { 78 usb_hid_report_usage_path_t *item =79 malloc(sizeof(usb_hid_report_usage_path_t));75 errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 76 int32_t usage_page, int32_t usage) 77 { 78 usb_hid_report_usage_path_t *item 79 = malloc(sizeof(usb_hid_report_usage_path_t)); 80 80 81 81 if (item == NULL) { … … 87 87 item->usage_page = usage_page; 88 88 item->flags = 0; 89 89 90 90 list_append (&item->rpath_items_link, &usage_path->items); 91 91 usage_path->depth++; … … 96 96 /** 97 97 * Removes last item from the usage path structure 98 * @param usage_path 98 * @param usage_path 99 99 * @return void 100 100 */ … … 103 103 link_t *item_link; 104 104 usb_hid_report_usage_path_t *item; 105 106 if (!list_empty(&usage_path->items)){105 106 if(!list_empty(&usage_path->items)){ 107 107 item_link = list_last(&usage_path->items); 108 108 item = list_get_instance(item_link, … … 124 124 { 125 125 usb_hid_report_usage_path_t *item; 126 127 if (!list_empty(&usage_path->items)){126 127 if(!list_empty(&usage_path->items)){ 128 128 item = list_get_instance(list_last(&usage_path->items), 129 usb_hid_report_usage_path_t, rpath_items_link);129 usb_hid_report_usage_path_t, rpath_items_link); 130 130 131 131 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); … … 143 143 * @return void 144 144 */ 145 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 146 int32_t tag, int32_t data)145 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 146 int32_t tag, int32_t data) 147 147 { 148 148 usb_hid_report_usage_path_t *item; 149 150 if (!list_empty(&usage_path->items)){149 150 if(!list_empty(&usage_path->items)){ 151 151 item = list_get_instance(list_last(&usage_path->items), 152 152 usb_hid_report_usage_path_t, rpath_items_link); 153 153 154 switch (tag) { 155 case USB_HID_TAG_CLASS_GLOBAL: 156 item->usage_page = data; 157 break; 158 case USB_HID_TAG_CLASS_LOCAL: 159 item->usage = data; 160 break; 161 } 162 } 163 } 164 154 switch(tag) { 155 case USB_HID_TAG_CLASS_GLOBAL: 156 item->usage_page = data; 157 break; 158 case USB_HID_TAG_CLASS_LOCAL: 159 item->usage = data; 160 break; 161 } 162 } 163 164 } 165 166 167 /** 168 * 169 * 170 * 171 * 172 */ 165 173 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 166 174 { 167 usb_log_debug("USAGE_PATH FOR RId(%d): ", path->report_id);168 usb_log_debug("\tLENGTH: %d ", path->depth);175 usb_log_debug("USAGE_PATH FOR RId(%d):\n", path->report_id); 176 usb_log_debug("\tLENGTH: %d\n", path->depth); 169 177 170 178 list_foreach(path->items, rpath_items_link, 171 179 usb_hid_report_usage_path_t, path_item) { 172 180 173 usb_log_debug("\tUSAGE_PAGE: %X ", path_item->usage_page);174 usb_log_debug("\tUSAGE: %X ", path_item->usage);175 usb_log_debug("\tFLAGS: %d ", path_item->flags);181 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 182 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 183 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 176 184 } 177 185 } … … 191 199 usb_hid_report_usage_path_t *report_item; 192 200 usb_hid_report_usage_path_t *path_item; 193 201 194 202 link_t *report_link; 195 203 link_t *path_link; 196 204 197 205 int only_page; 198 206 199 207 if (report_path->report_id != path->report_id) { 200 208 if (path->report_id != 0) { … … 202 210 } 203 211 } 204 212 205 213 // Empty path match all others 206 214 if (path->depth == 0) { 207 215 return 0; 208 216 } 209 217 210 218 if ((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0) { 211 219 flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY; 212 220 } 213 221 214 222 switch (flags) { 215 223 /* Path is somewhere in report_path */ … … 218 226 return 1; 219 227 } 220 228 221 229 path_link = list_first(&path->items); 222 230 path_item = list_get_instance(path_link, 223 231 usb_hid_report_usage_path_t, rpath_items_link); 224 232 225 233 list_foreach(report_path->items, rpath_items_link, 226 234 usb_hid_report_usage_path_t, report_item) { 227 235 if (USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 228 236 path_item->usage_page)) { 229 237 230 238 if (only_page == 0) { 231 239 if (USB_HID_SAME_USAGE(report_item->usage, … … 237 245 } 238 246 } 239 247 240 248 return 1; 241 249 break; 242 250 243 251 /* The paths must be identical */ 244 252 case USB_HID_PATH_COMPARE_STRICT: … … 247 255 } 248 256 /* Fallthrough */ 249 257 250 258 /* Path is prefix of the report_path */ 251 259 case USB_HID_PATH_COMPARE_BEGIN: 252 260 report_link = report_path->items.head.next; 253 261 path_link = path->items.head.next; 254 262 255 263 while ((report_link != &report_path->items.head) && 256 264 (path_link != &path->items.head)) { 257 265 258 266 report_item = list_get_instance(report_link, 259 267 usb_hid_report_usage_path_t, rpath_items_link); 260 268 261 269 path_item = list_get_instance(path_link, 262 270 usb_hid_report_usage_path_t, rpath_items_link); 263 271 264 272 if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 265 273 path_item->usage_page) || ((only_page == 0) && … … 272 280 } 273 281 } 274 282 275 283 if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 276 284 (path_link == &path->items.head)) || … … 282 290 } 283 291 break; 284 292 285 293 /* Path is suffix of report_path */ 286 294 case USB_HID_PATH_COMPARE_END: 287 295 report_link = report_path->items.head.prev; 288 296 path_link = path->items.head.prev; 289 297 290 298 if (list_empty(&path->items)) { 291 299 return 0; 292 300 } 293 301 294 302 while ((report_link != &report_path->items.head) && 295 303 (path_link != &path->items.head)) { 296 304 report_item = list_get_instance(report_link, 297 305 usb_hid_report_usage_path_t, rpath_items_link); 298 306 299 307 path_item = list_get_instance(path_link, 300 308 usb_hid_report_usage_path_t, rpath_items_link); 301 309 302 310 if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 303 311 path_item->usage_page) || ((only_page == 0) && … … 310 318 } 311 319 } 312 320 313 321 if (path_link == &path->items.head) { 314 322 return 0; … … 317 325 } 318 326 break; 319 327 320 328 default: 321 329 return -1; … … 332 340 usb_hid_report_path_t *path; 333 341 path = malloc(sizeof(usb_hid_report_path_t)); 334 if (path == NULL){342 if(path == NULL){ 335 343 return NULL; 336 344 } … … 355 363 if (path == NULL) 356 364 return; 357 while (!list_empty(&path->items)){365 while(!list_empty(&path->items)){ 358 366 usb_hid_report_remove_last_item(path); 359 367 } … … 371 379 */ 372 380 usb_hid_report_path_t *usb_hid_report_path_clone( 373 usb_hid_report_path_t *usage_path)381 usb_hid_report_path_t *usage_path) 374 382 { 375 383 usb_hid_report_usage_path_t *new_path_item; 376 384 usb_hid_report_path_t *new_usage_path = usb_hid_report_path (); 377 385 378 if (new_usage_path == NULL){386 if(new_usage_path == NULL){ 379 387 return NULL; 380 388 } 381 389 382 390 new_usage_path->report_id = usage_path->report_id; 383 384 if (list_empty(&usage_path->items)){391 392 if(list_empty(&usage_path->items)){ 385 393 return new_usage_path; 386 394 } … … 390 398 391 399 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 392 if (new_path_item == NULL) {400 if(new_path_item == NULL) { 393 401 return NULL; 394 402 } 395 403 396 404 link_initialize(&new_path_item->rpath_items_link); 397 405 new_path_item->usage_page = path_item->usage_page; 398 new_path_item->usage = path_item->usage; 399 new_path_item->flags = path_item->flags; 400 406 new_path_item->usage = path_item->usage; 407 new_path_item->flags = path_item->flags; 408 401 409 list_append(&new_path_item->rpath_items_link, 402 410 &new_usage_path->items); … … 415 423 * @return Error code 416 424 */ 417 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 418 uint8_t report_id)419 { 420 if (path == NULL){425 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 426 uint8_t report_id) 427 { 428 if(path == NULL){ 421 429 return EINVAL; 422 430 }
Note:
See TracChangeset
for help on using the changeset viewer.
