Changes in uspace/lib/usbhid/src/hidpath.c [f3b39b4:160b75e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidpath.c
rf3b39b4 r160b75e 41 41 #include <assert.h> 42 42 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 /*---------------------------------------------------------------------------*/ 43 66 44 /** 67 45 * Appends one item (couple of usage_path and usage) into the usage path … … 92 70 } 93 71 94 /*---------------------------------------------------------------------------*/95 72 /** 96 73 * Removes last item from the usage path structure … … 111 88 } 112 89 113 /*---------------------------------------------------------------------------*/114 90 /** 115 91 * Nulls last item of the usage path structure. … … 123 99 124 100 if(!list_empty(&usage_path->head)){ 125 item = list_get_instance(usage_path->head.prev, 126 usb_hid_report_usage_path_t, link); 127 101 item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link); 128 102 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); 129 103 } 130 104 } 131 105 132 /*---------------------------------------------------------------------------*/133 106 /** 134 107 * Modifies last item of usage path structure by given usage page or usage … … 161 134 } 162 135 163 /*---------------------------------------------------------------------------*/ 164 /** 165 * 166 * 167 * 168 * 169 */ 136 170 137 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 171 138 { … … 177 144 while(item != &path->head) { 178 145 179 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 180 link); 181 146 path_item = list_get_instance(item, usb_hid_report_usage_path_t, link); 182 147 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 183 148 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 184 149 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 185 150 186 item = item->next; 187 } 188 } 189 190 /*---------------------------------------------------------------------------*/ 151 item = item->next; 152 } 153 } 154 191 155 /** 192 156 * Compares two usage paths structures … … 225 189 226 190 switch(flags){ 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 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 { 250 212 return EOK; 251 213 } 252 214 } 215 216 report_link = report_link->next; 217 } 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 254 } 255 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 } 253 260 else { 261 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)){ 254 272 return EOK; 255 273 } 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 274 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))) { 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 } 289 293 290 return 1; 291 } 292 else { 293 report_link = report_link->next; 294 path_link = path_link->next; 295 } 294 } 295 296 if(path_link == &path->head) { 297 return EOK; 298 } 299 else { 300 return 1; 301 } 296 302 297 } 298 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 335 return 1; 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 } 349 350 break; 351 352 default: 353 return EINVAL; 354 } 355 } 356 357 /*---------------------------------------------------------------------------*/ 303 break; 304 305 default: 306 return EINVAL; 307 } 308 } 309 358 310 /** 359 311 * Allocates and initializes new usage path structure. … … 377 329 } 378 330 379 /*---------------------------------------------------------------------------*/380 331 /** 381 332 * Releases given usage path structure. … … 394 345 } 395 346 396 /*---------------------------------------------------------------------------*/ 347 397 348 /** 398 349 * Clone content of given usage path to the new one … … 401 352 * @return New copy of given usage path structure 402 353 */ 403 usb_hid_report_path_t *usb_hid_report_path_clone( 404 usb_hid_report_path_t *usage_path) 354 usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path) 405 355 { 406 356 link_t *path_link; … … 421 371 path_link = usage_path->head.next; 422 372 while(path_link != &usage_path->head) { 423 path_item = list_get_instance(path_link, 424 usb_hid_report_usage_path_t, link); 425 373 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 374 link); 426 375 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 427 376 if(new_path_item == NULL) { … … 443 392 } 444 393 445 /*---------------------------------------------------------------------------*/ 394 446 395 /** 447 396 * Sets report id in usage path structure … … 451 400 * @return Error code 452 401 */ 453 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 454 uint8_t report_id) 402 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id) 455 403 { 456 404 if(path == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.