Changeset cd83f25 in mainline for uspace/lib/usbhid/src/hidpath.c
- Timestamp:
- 2011-05-27T09:58:08Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e89bb50
- Parents:
- 63d4d4fd (diff), 848dafc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidpath.c
r63d4d4fd rcd83f25 41 41 #include <assert.h> 42 42 43 44 #define USB_HID_SAME_USAGE(usage1, usage2) ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0)) 45 #define USB_HID_SAME_USAGE_PAGE(page1, page2) ((page1 == page2) || (page1 == 0) || (page2 == 0)) 46 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 /*---------------------------------------------------------------------------*/ 47 66 /** 48 67 * Appends one item (couple of usage_path and usage) into the usage path … … 73 92 } 74 93 94 /*---------------------------------------------------------------------------*/ 75 95 /** 76 96 * Removes last item from the usage path structure … … 91 111 } 92 112 113 /*---------------------------------------------------------------------------*/ 93 114 /** 94 115 * Nulls last item of the usage path structure. … … 102 123 103 124 if(!list_empty(&usage_path->head)){ 104 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 105 128 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); 106 129 } 107 130 } 108 131 132 /*---------------------------------------------------------------------------*/ 109 133 /** 110 134 * Modifies last item of usage path structure by given usage page or usage … … 137 161 } 138 162 139 163 /*---------------------------------------------------------------------------*/ 164 /** 165 * 166 * 167 * 168 * 169 */ 140 170 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 141 171 { … … 147 177 while(item != &path->head) { 148 178 149 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 150 182 usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page); 151 183 usb_log_debug("\tUSAGE: %X\n", path_item->usage); 152 184 usb_log_debug("\tFLAGS: %d\n", path_item->flags); 153 185 154 item = item->next; 155 } 156 } 157 186 item = item->next; 187 } 188 } 189 190 /*---------------------------------------------------------------------------*/ 158 191 /** 159 192 * Compares two usage paths structures … … 192 225 193 226 switch(flags){ 194 /* path is somewhere in report_path */ 195 case USB_HID_PATH_COMPARE_ANYWHERE: 196 if(path->depth != 1){ 197 return 1; 198 } 199 200 // projit skrz cestu a kdyz nekde sedi tak vratim EOK 201 // dojduli az za konec tak nnesedi 202 report_link = report_path->head.next; 203 path_link = path->head.next; 204 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link); 205 206 while(report_link != &report_path->head) { 207 report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link); 208 if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){ 209 if(only_page == 0){ 210 if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) { 211 return EOK; 212 } 213 } 214 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 215 250 return EOK; 216 251 } 217 252 } 218 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 { 219 293 report_link = report_link->next; 294 path_link = path_link->next; 220 295 } 221 222 return 1;223 break;224 /* the paths must be identical */225 case USB_HID_PATH_COMPARE_STRICT:226 if(report_path->depth != path->depth){227 return 1;228 }229 230 /* path is prefix of the report_path */231 case USB_HID_PATH_COMPARE_BEGIN:232 233 report_link = report_path->head.next;234 path_link = path->head.next;235 236 while((report_link != &report_path->head) &&237 (path_link != &path->head)) {238 239 report_item = list_get_instance(report_link,240 usb_hid_report_usage_path_t,241 link);242 243 path_item = list_get_instance(path_link,244 usb_hid_report_usage_path_t,245 link);246 247 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||248 ((only_page == 0) &&249 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {250 251 return 1;252 } else {253 report_link = report_link->next;254 path_link = path_link->next;255 }256 296 257 297 } 258 298 259 if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) || 260 ((report_link == &report_path->head) && (path_link == &path->head))) { 261 return EOK; 262 } 263 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 264 335 return 1; 265 } 266 break; 267 268 /* path is suffix of report_path */ 269 case USB_HID_PATH_COMPARE_END: 270 271 report_link = report_path->head.prev; 272 path_link = path->head.prev; 273 274 if(list_empty(&path->head)){ 275 return EOK; 276 } 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 } 277 349 278 while((report_link != &report_path->head) && 279 (path_link != &path->head)) { 280 281 report_item = list_get_instance(report_link, 282 usb_hid_report_usage_path_t, 283 link); 284 path_item = list_get_instance(path_link, 285 usb_hid_report_usage_path_t, 286 link); 287 288 if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) || 289 ((only_page == 0) && 290 !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) { 291 return 1; 292 } else { 293 report_link = report_link->prev; 294 path_link = path_link->prev; 295 } 296 297 } 298 299 if(path_link == &path->head) { 300 return EOK; 301 } 302 else { 303 return 1; 304 } 305 306 break; 307 308 default: 309 return EINVAL; 310 } 311 } 312 350 break; 351 352 default: 353 return EINVAL; 354 } 355 } 356 357 /*---------------------------------------------------------------------------*/ 313 358 /** 314 359 * Allocates and initializes new usage path structure. … … 332 377 } 333 378 379 /*---------------------------------------------------------------------------*/ 334 380 /** 335 381 * Releases given usage path structure. … … 348 394 } 349 395 350 396 /*---------------------------------------------------------------------------*/ 351 397 /** 352 398 * Clone content of given usage path to the new one … … 355 401 * @return New copy of given usage path structure 356 402 */ 357 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) 358 405 { 359 406 link_t *path_link; … … 374 421 path_link = usage_path->head.next; 375 422 while(path_link != &usage_path->head) { 376 path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, 377 link); 423 path_item = list_get_instance(path_link, 424 usb_hid_report_usage_path_t, link); 425 378 426 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 379 427 if(new_path_item == NULL) { … … 395 443 } 396 444 397 445 /*---------------------------------------------------------------------------*/ 398 446 /** 399 447 * Sets report id in usage path structure … … 403 451 * @return Error code 404 452 */ 405 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) 406 455 { 407 456 if(path == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.