Changeset b72efe8 in mainline for uspace/lib/usbhid/src/hidpath.c


Ignore:
Timestamp:
2011-06-19T14:38:59Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74464e8
Parents:
1d1bb0f
Message:

Separate list_t typedef from link_t (user-space part).

  • list_t represents lists
  • Use list_first(), list_last(), list_empty() where appropriate
  • Use list_foreach() where possible
  • assert_link_not_used()
  • usb_hid_report_path_free() shall not unlink the path, caller must do it
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhid/src/hidpath.c

    r1d1bb0f rb72efe8  
    8181                return ENOMEM;
    8282        }
    83         list_initialize(&item->link);
     83        link_initialize(&item->rpath_items_link);
    8484
    8585        item->usage = usage;
     
    8787        item->flags = 0;
    8888       
    89         list_append (&item->link, &usage_path->head);
     89        list_append (&item->rpath_items_link, &usage_path->items);
    9090        usage_path->depth++;
    9191        return EOK;
     
    100100void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
    101101{
     102        link_t *item_link;
    102103        usb_hid_report_usage_path_t *item;
    103104       
    104         if(!list_empty(&usage_path->head)){
    105                 item = list_get_instance(usage_path->head.prev,
    106                                          usb_hid_report_usage_path_t, link);           
    107                 list_remove(usage_path->head.prev);
     105        if(!list_empty(&usage_path->items)){
     106                item_link = list_last(&usage_path->items);
     107                item = list_get_instance(item_link,
     108                    usb_hid_report_usage_path_t, rpath_items_link);
     109                list_remove(item_link);
    108110                usage_path->depth--;
    109111                free(item);
     
    122124        usb_hid_report_usage_path_t *item;
    123125       
    124         if(!list_empty(&usage_path->head)){     
    125                 item = list_get_instance(usage_path->head.prev,
    126                         usb_hid_report_usage_path_t, link);
     126        if(!list_empty(&usage_path->items)){
     127                item = list_get_instance(list_last(&usage_path->items),
     128                        usb_hid_report_usage_path_t, rpath_items_link);
    127129
    128130                memset(item, 0, sizeof(usb_hid_report_usage_path_t));
     
    145147        usb_hid_report_usage_path_t *item;
    146148       
    147         if(!list_empty(&usage_path->head)){     
    148                 item = list_get_instance(usage_path->head.prev,
    149                                          usb_hid_report_usage_path_t, link);
     149        if(!list_empty(&usage_path->items)){
     150                item = list_get_instance(list_last(&usage_path->items),
     151                     usb_hid_report_usage_path_t, rpath_items_link);
    150152
    151153                switch(tag) {
     
    173175        usb_log_debug("\tLENGTH: %d\n", path->depth);
    174176
    175         link_t *item = path->head.next;
    176177        usb_hid_report_usage_path_t *path_item;
    177         while(item != &path->head) {
    178 
    179                 path_item = list_get_instance(item, usb_hid_report_usage_path_t, 
    180                         link);
     178
     179        list_foreach(path->items, item) {
     180                path_item = list_get_instance(item, usb_hid_report_usage_path_t,
     181                        rpath_items_link);
    181182
    182183                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
    183184                usb_log_debug("\tUSAGE: %X\n", path_item->usage);
    184                 usb_log_debug("\tFLAGS: %d\n", path_item->flags);               
    185                
    186         item = item->next;
     185                usb_log_debug("\tFLAGS: %d\n", path_item->flags);
    187186        }
    188187}
     
    233232                }
    234233
    235                 report_link = report_path->head.next;
    236                 path_link = path->head.next;
    237                 path_item = list_get_instance(path_link,
    238                         usb_hid_report_usage_path_t, link);
    239 
    240                 while(report_link != &report_path->head) {
    241                         report_item = list_get_instance(report_link,
    242                                 usb_hid_report_usage_path_t, link);
     234                path_link = list_first(&path->items);
     235                path_item = list_get_instance(path_link,
     236                        usb_hid_report_usage_path_t, rpath_items_link);
     237
     238                list_foreach(report_path->items, report_link) {
     239                        report_item = list_get_instance(report_link,
     240                                usb_hid_report_usage_path_t, rpath_items_link);
    243241                               
    244                         if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 
     242                        if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    245243                                path_item->usage_page)){
    246244                                       
     
    257255                                }
    258256                        }
    259 
    260                         report_link = report_link->next;
    261257                }
    262258
     
    273269        case USB_HID_PATH_COMPARE_BEGIN:
    274270       
    275                 report_link = report_path->head.next;
    276                 path_link = path->head.next;
     271                report_link = report_path->items.head.next;
     272                path_link = path->items.head.next;
    277273                       
    278                 while((report_link != &report_path->head) &&
    279                       (path_link != &path->head)) {
     274                while((report_link != &report_path->items.head) &&
     275                      (path_link != &path->items.head)) {
    280276                                         
    281277                        report_item = list_get_instance(report_link,
    282                                 usb_hid_report_usage_path_t, link);
     278                                usb_hid_report_usage_path_t, rpath_items_link);
    283279                                         
    284280                        path_item = list_get_instance(path_link,
    285                                 usb_hid_report_usage_path_t, link);
     281                                usb_hid_report_usage_path_t, rpath_items_link);
    286282
    287283                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     
    297293                        }
    298294                       
    299                                 }
     295                }
    300296
    301297                if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
    302                         (path_link == &path->head)) ||
    303                    ((report_link == &report_path->head) &&
    304                         (path_link == &path->head))) {
     298                        (path_link == &path->items.head)) ||
     299                   ((report_link == &report_path->items.head) &&
     300                        (path_link == &path->items.head))) {
    305301                               
    306302                        return EOK;
     
    314310        case USB_HID_PATH_COMPARE_END:
    315311
    316                 report_link = report_path->head.prev;
    317                 path_link = path->head.prev;
    318 
    319                 if(list_empty(&path->head)){
     312                report_link = report_path->items.head.prev;
     313                path_link = path->items.head.prev;
     314
     315                if(list_empty(&path->items)){
    320316                        return EOK;
    321317                }
    322318                       
    323                 while((report_link != &report_path->head) &&
    324                       (path_link != &path->head)) {
     319                while((report_link != &report_path->items.head) &&
     320                      (path_link != &path->items.head)) {
    325321                                                 
    326                         report_item = list_get_instance(report_link, 
    327                                 usb_hid_report_usage_path_t, link);
     322                        report_item = list_get_instance(report_link,
     323                                usb_hid_report_usage_path_t, rpath_items_link);
    328324
    329325                        path_item = list_get_instance(path_link,
    330                                 usb_hid_report_usage_path_t, link);             
     326                                usb_hid_report_usage_path_t, rpath_items_link);
    331327                                                 
    332328                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     
    343339                }
    344340
    345                 if(path_link == &path->head) {
     341                if(path_link == &path->items.head) {
    346342                        return EOK;
    347343                }
     
    373369                path->depth = 0;
    374370                path->report_id = 0;
    375                 list_initialize(&path->link);
    376                 list_initialize(&path->head);
     371                link_initialize(&path->cpath_link);
     372                list_initialize(&path->items);
    377373                return path;
    378374        }
     
    388384void usb_hid_report_path_free(usb_hid_report_path_t *path)
    389385{
    390         while(!list_empty(&path->head)){
     386        while(!list_empty(&path->items)){
    391387                usb_hid_report_remove_last_item(path);
    392388        }
    393389
    394         list_remove(&path->link);
     390        assert_link_not_used(&path->cpath_link);
    395391        free(path);
    396392}
     
    406402        usb_hid_report_path_t *usage_path)
    407403{
    408         link_t *path_link;
    409404        usb_hid_report_usage_path_t *path_item;
    410405        usb_hid_report_usage_path_t *new_path_item;
     
    417412        new_usage_path->report_id = usage_path->report_id;
    418413       
    419         if(list_empty(&usage_path->head)){
     414        if(list_empty(&usage_path->items)){
    420415                return new_usage_path;
    421416        }
    422417
    423         path_link = usage_path->head.next;
    424         while(path_link != &usage_path->head) {
    425                 path_item = list_get_instance(path_link,
    426                         usb_hid_report_usage_path_t, link);
     418        list_foreach(usage_path->items, path_link) {
     419                path_item = list_get_instance(path_link,
     420                        usb_hid_report_usage_path_t, rpath_items_link);
    427421
    428422                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
     
    431425                }
    432426               
    433                 list_initialize (&new_path_item->link);         
     427                link_initialize(&new_path_item->rpath_items_link);
    434428                new_path_item->usage_page = path_item->usage_page;
    435429                new_path_item->usage = path_item->usage;               
    436430                new_path_item->flags = path_item->flags;               
    437431               
    438                 list_append(&new_path_item->link, &new_usage_path->head);
     432                list_append(&new_path_item->rpath_items_link,
     433                    &new_usage_path->items);
    439434                new_usage_path->depth++;
    440 
    441                 path_link = path_link->next;
    442435        }
    443436
Note: See TracChangeset for help on using the changeset viewer.