Changes in uspace/lib/usbhid/src/hidpath.c [160b75e:f3b39b4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidpath.c
r160b75e rf3b39b4 41 41 #include <assert.h> 42 42 43 43 /*---------------------------------------------------------------------------*/ 44 /** 45 * Compares two usages if they are same or not or one of the usages is not 46 * set. 47 * 48 * @param usage1 49 * @param usage2 50 * @return boolean 51 */ 52 #define USB_HID_SAME_USAGE(usage1, usage2) \ 53 ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 54 55 /** 56 * Compares two usage pages if they are same or not or one of them is not set. 57 * 58 * @param page1 59 * @param page2 60 * @return boolean 61 */ 62 #define USB_HID_SAME_USAGE_PAGE(page1, page2) \ 63 ((page1 == page2) || (page1 == 0) || (page2 == 0)) 64 65 /*---------------------------------------------------------------------------*/ 44 66 /** 45 67 * Appends one item (couple of usage_path and usage) into the usage path … … 70 92 } 71 93 94 /*---------------------------------------------------------------------------*/ 72 95 /** 73 96 * Removes last item from the usage path structure … … 88 111 } 89 112 113 /*---------------------------------------------------------------------------*/ 90 114 /** 91 115 * Nulls last item of the usage path structure. … … 99 123 100 124 if(!list_empty(&usage_path->head)){ 101 item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 125 item = list_get_instance(usage_path->head.prev, 126 usb_hid_report_usage_path_t, link); 127 102 128 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); 103 129 } 104 130 } 105 131 132 /*---------------------------------------------------------------------------*/ 106 133 /** 107 134 * Modifies last item of usage path structure by given usage page or usage … … 134 161 } 135 162 136 163 /*---------------------------------------------------------------------------*/ 164 /** 165 * 166 * 167 * 168 * 169 */ 137 170 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 138 171 { … … 144 177 while(item != &path->head) { 145 178 146 path_item = list_get_instance(item, usb_hid_report_usage_path_t, link); 179 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 180 link); 181 147 182 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 148 183 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 149 184 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 150 185 151 item = item->next; 152 } 153 } 154 186 item = item->next; 187 } 188 } 189 190 /*---------------------------------------------------------------------------*/ 155 191 /** 156 192 * Compares two usage paths structures … … 189 225 190 226 switch(flags){ 191 /* path is somewhere in report_path */ 192 case USB_HID_PATH_COMPARE_ANYWHERE: 193 if(path->depth != 1){ 194 return 1; 195 } 196 197 // projit skrz cestu a kdyz nekde sedi tak vratim EOK 198 // dojduli az za konec tak nnesedi 199 report_link = report_path->head.next; 200 path_link = path->head.next; 201 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 202 203 while(report_link != &report_path->head) { 204 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 205 if(report_item->usage_page == path_item->usage_page){ 206 if(only_page == 0){ 207 if(report_item->usage == path_item->usage) { 208 return EOK; 209 } 210 } 211 else { 227 /* path is somewhere in report_path */ 228 case USB_HID_PATH_COMPARE_ANYWHERE: 229 if(path->depth != 1){ 230 return 1; 231 } 232 233 report_link = report_path->head.next; 234 path_link = path->head.next; 235 path_item = list_get_instance(path_link, 236 usb_hid_report_usage_path_t, link); 237 238 while(report_link != &report_path->head) { 239 report_item = list_get_instance(report_link, 240 usb_hid_report_usage_path_t, link); 241 242 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 243 path_item->usage_page)){ 244 245 if(only_page == 0){ 246 if(USB_HID_SAME_USAGE( 247 report_item->usage, 248 path_item->usage)) { 249 212 250 return EOK; 213 251 } 214 252 } 215 253 else { 254 return EOK; 255 } 256 } 257 258 report_link = report_link->next; 259 } 260 261 return 1; 262 break; 263 264 /* the paths must be identical */ 265 case USB_HID_PATH_COMPARE_STRICT: 266 if(report_path->depth != path->depth){ 267 return 1; 268 } 269 270 /* path is prefix of the report_path */ 271 case USB_HID_PATH_COMPARE_BEGIN: 272 273 report_link = report_path->head.next; 274 path_link = path->head.next; 275 276 while((report_link != &report_path->head) && 277 (path_link != &path->head)) { 278 279 report_item = list_get_instance(report_link, 280 usb_hid_report_usage_path_t, link); 281 282 path_item = list_get_instance(path_link, 283 usb_hid_report_usage_path_t, link); 284 285 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 286 path_item->usage_page) || ((only_page == 0) && 287 !USB_HID_SAME_USAGE(report_item->usage, 288 path_item->usage))) { 289 290 return 1; 291 } 292 else { 216 293 report_link = report_link->next; 294 path_link = path_link->next; 217 295 } 218 219 return 1;220 break;221 /* the paths must be identical */222 case USB_HID_PATH_COMPARE_STRICT:223 if(report_path->depth != path->depth){224 return 1;225 }226 227 /* path is prefix of the report_path */228 case USB_HID_PATH_COMPARE_BEGIN:229 230 report_link = report_path->head.next;231 path_link = path->head.next;232 233 while((report_link != &report_path->head) &&234 (path_link != &path->head)) {235 236 report_item = list_get_instance(report_link,237 usb_hid_report_usage_path_t,238 link);239 240 path_item = list_get_instance(path_link,241 usb_hid_report_usage_path_t,242 link);243 244 if((report_item->usage_page != path_item->usage_page) ||245 ((only_page == 0) &&246 (report_item->usage != path_item->usage))) {247 248 return 1;249 } else {250 report_link = report_link->next;251 path_link = path_link->next;252 }253 296 254 297 } 255 298 256 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 257 ((report_link == &report_path->head) && (path_link == &path->head))) { 258 return EOK; 259 } 260 else { 299 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 300 (path_link == &path->head)) || 301 ((report_link == &report_path->head) && 302 (path_link == &path->head))) { 303 304 return EOK; 305 } 306 else { 307 return 1; 308 } 309 break; 310 311 /* path is suffix of report_path */ 312 case USB_HID_PATH_COMPARE_END: 313 314 report_link = report_path->head.prev; 315 path_link = path->head.prev; 316 317 if(list_empty(&path->head)){ 318 return EOK; 319 } 320 321 while((report_link != &report_path->head) && 322 (path_link != &path->head)) { 323 324 report_item = list_get_instance(report_link, 325 usb_hid_report_usage_path_t, link); 326 327 path_item = list_get_instance(path_link, 328 usb_hid_report_usage_path_t, link); 329 330 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 331 path_item->usage_page) || ((only_page == 0) && 332 !USB_HID_SAME_USAGE(report_item->usage, 333 path_item->usage))) { 334 261 335 return 1; 262 } 263 break; 264 265 /* path is suffix of report_path */ 266 case USB_HID_PATH_COMPARE_END: 267 268 report_link = report_path->head.prev; 269 path_link = path->head.prev; 270 271 if(list_empty(&path->head)){ 272 return EOK; 273 } 336 } else { 337 report_link = report_link->prev; 338 path_link = path_link->prev; 339 } 340 341 } 342 343 if(path_link == &path->head) { 344 return EOK; 345 } 346 else { 347 return 1; 348 } 274 349 275 while((report_link != &report_path->head) && 276 (path_link != &path->head)) { 277 278 report_item = list_get_instance(report_link, 279 usb_hid_report_usage_path_t, 280 link); 281 path_item = list_get_instance(path_link, 282 usb_hid_report_usage_path_t, 283 link); 284 285 if((report_item->usage_page != path_item->usage_page) || 286 ((only_page == 0) && 287 (report_item->usage != path_item->usage))) { 288 return 1; 289 } else { 290 report_link = report_link->prev; 291 path_link = path_link->prev; 292 } 293 294 } 295 296 if(path_link == &path->head) { 297 return EOK; 298 } 299 else { 300 return 1; 301 } 302 303 break; 304 305 default: 306 return EINVAL; 307 } 308 } 309 350 break; 351 352 default: 353 return EINVAL; 354 } 355 } 356 357 /*---------------------------------------------------------------------------*/ 310 358 /** 311 359 * Allocates and initializes new usage path structure. … … 329 377 } 330 378 379 /*---------------------------------------------------------------------------*/ 331 380 /** 332 381 * Releases given usage path structure. … … 345 394 } 346 395 347 396 /*---------------------------------------------------------------------------*/ 348 397 /** 349 398 * Clone content of given usage path to the new one … … 352 401 * @return New copy of given usage path structure 353 402 */ 354 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path) 403 usb_hid_report_path_t *usb_hid_report_path_clone( 404 usb_hid_report_path_t *usage_path) 355 405 { 356 406 link_t *path_link; … … 371 421 path_link = usage_path->head.next; 372 422 while(path_link != &usage_path->head) { 373 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 374 link); 423 path_item = list_get_instance(path_link, 424 usb_hid_report_usage_path_t, link); 425 375 426 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 376 427 if(new_path_item == NULL) { … … 392 443 } 393 444 394 445 /*---------------------------------------------------------------------------*/ 395 446 /** 396 447 * Sets report id in usage path structure … … 400 451 * @return Error code 401 452 */ 402 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id) 453 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 454 uint8_t report_id) 403 455 { 404 456 if(path == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.