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


Ignore:
Timestamp:
2017-05-04T22:17:36Z (7 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
31a30fa
Parents:
dc12262
Message:

cstyle (no change in functionality)

File:
1 edited

Legend:

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

    rdc12262 re141281  
    185185}
    186186
    187 
    188 /**
    189  * Compares two usage paths structures
    190  *
    191  *
    192  * @param report_path usage path structure to compare with @path
    193  * @param path usage patrh structure to compare
    194  * @param flags Flags determining the mode of comparison
     187/** Compare two usage paths structures
     188 *
     189 * @param report_path Usage path structure to compare with @path
     190 * @param path        Usage patrh structure to compare
     191 * @param flags       Flags determining the mode of comparison
     192 *
    195193 * @return EOK if both paths are identical, non zero number otherwise
    196  */
    197 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
    198                                       usb_hid_report_path_t *path,
    199                                       int flags)
     194 *
     195 */
     196int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
     197    usb_hid_report_path_t *path, int flags)
    200198{
    201199        usb_hid_report_usage_path_t *report_item;
    202200        usb_hid_report_usage_path_t *path_item;
    203 
     201       
    204202        link_t *report_link;
    205203        link_t *path_link;
    206 
     204       
    207205        int only_page;
    208 
    209         if(report_path->report_id != path->report_id) {
    210                 if(path->report_id != 0) {
     206       
     207        if (report_path->report_id != path->report_id) {
     208                if (path->report_id != 0) {
    211209                        return 1;
    212210                }
    213211        }
    214 
     212       
    215213        // Empty path match all others
    216         if(path->depth == 0){
     214        if (path->depth == 0) {
    217215                return EOK;
    218216        }
    219 
    220 
    221         if((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0){
     217       
     218        if ((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0) {
    222219                flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY;
    223220        }
    224221       
    225         switch(flags){
    226         /* path is somewhere in report_path */
     222        switch (flags) {
     223        /* Path is somewhere in report_path */
    227224        case USB_HID_PATH_COMPARE_ANYWHERE:
    228                 if(path->depth != 1){
     225                if (path->depth != 1) {
    229226                        return 1;
    230227                }
    231 
     228               
    232229                path_link = list_first(&path->items);
    233230                path_item = list_get_instance(path_link,
    234                         usb_hid_report_usage_path_t, rpath_items_link);
    235 
     231                    usb_hid_report_usage_path_t, rpath_items_link);
     232               
    236233                list_foreach(report_path->items, rpath_items_link,
    237234                    usb_hid_report_usage_path_t, report_item) {
    238 
    239235                        if (USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    240                                 path_item->usage_page)) {
     236                            path_item->usage_page)) {
    241237                               
    242238                                if (only_page == 0) {
     
    244240                                            path_item->usage))
    245241                                                return EOK;
    246                                 }
    247                                 else {
     242                                } else {
    248243                                        return EOK;
    249244                                }
    250245                        }
    251246                }
    252 
     247               
    253248                return 1;
    254249                break;
    255 
    256         /* the paths must be identical */
     250       
     251        /* The paths must be identical */
    257252        case USB_HID_PATH_COMPARE_STRICT:
    258                 if(report_path->depth != path->depth){
     253                if (report_path->depth != path->depth) {
    259254                        return 1;
    260255                }
    261256                /* Fallthrough */
    262 
    263         /* path is prefix of the report_path */
     257       
     258        /* Path is prefix of the report_path */
    264259        case USB_HID_PATH_COMPARE_BEGIN:
    265 
    266260                report_link = report_path->items.head.next;
    267261                path_link = path->items.head.next;
     
    270264                    (path_link != &path->items.head)) {
    271265                       
    272                         report_item = list_get_instance(report_link, 
     266                        report_item = list_get_instance(report_link,
    273267                            usb_hid_report_usage_path_t, rpath_items_link);
    274268                       
    275269                        path_item = list_get_instance(path_link,
    276                                 usb_hid_report_usage_path_t, rpath_items_link);
    277 
    278                         if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 
    279                             path_item->usage_page) || ((only_page == 0) && 
    280                             !USB_HID_SAME_USAGE(report_item->usage, 
     270                            usb_hid_report_usage_path_t, rpath_items_link);
     271                       
     272                        if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     273                            path_item->usage_page) || ((only_page == 0) &&
     274                            !USB_HID_SAME_USAGE(report_item->usage,
    281275                            path_item->usage))) {
    282276                                return 1;
     
    286280                        }
    287281                }
    288 
    289                 if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 
    290                     (path_link == &path->items.head)) || 
    291                     ((report_link == &report_path->items.head) && 
     282               
     283                if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
     284                    (path_link == &path->items.head)) ||
     285                    ((report_link == &report_path->items.head) &&
    292286                    (path_link == &path->items.head))) {
    293287                        return EOK;
     
    296290                }
    297291                break;
    298 
    299         /* path is suffix of report_path */
     292       
     293        /* Path is suffix of report_path */
    300294        case USB_HID_PATH_COMPARE_END:
    301 
    302295                report_link = report_path->items.head.prev;
    303296                path_link = path->items.head.prev;
    304 
    305                 if(list_empty(&path->items)){
     297               
     298                if (list_empty(&path->items)) {
    306299                        return EOK;
    307300                }
     301               
     302                while ((report_link != &report_path->items.head) &&
     303                      (path_link != &path->items.head)) {
     304                        report_item = list_get_instance(report_link,
     305                            usb_hid_report_usage_path_t, rpath_items_link);
    308306                       
    309                 while((report_link != &report_path->items.head) &&
    310                       (path_link != &path->items.head)) {
    311                                                  
    312                         report_item = list_get_instance(report_link,
    313                                 usb_hid_report_usage_path_t, rpath_items_link);
    314 
    315                         path_item = list_get_instance(path_link,
    316                                 usb_hid_report_usage_path_t, rpath_items_link);
    317                                                  
    318                         if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    319                                 path_item->usage_page) || ((only_page == 0) &&
    320                             !USB_HID_SAME_USAGE(report_item->usage,
    321                                 path_item->usage))) {
    322                                                
    323                                         return 1;
     307                        path_item = list_get_instance(path_link,
     308                            usb_hid_report_usage_path_t, rpath_items_link);
     309                       
     310                        if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
     311                            path_item->usage_page) || ((only_page == 0) &&
     312                            !USB_HID_SAME_USAGE(report_item->usage,
     313                            path_item->usage))) {
     314                                return 1;
    324315                        } else {
    325316                                report_link = report_link->prev;
    326                                 path_link = path_link->prev;                   
     317                                path_link = path_link->prev;
    327318                        }
    328 
    329                 }
    330 
    331                 if(path_link == &path->items.head) {
     319                }
     320               
     321                if (path_link == &path->items.head) {
    332322                        return EOK;
    333                 }
    334                 else {
     323                } else {
    335324                        return 1;
    336                 }                                               
    337                        
     325                }
    338326                break;
    339 
     327       
    340328        default:
    341329                return EINVAL;
    342330        }
    343331}
    344 
    345332
    346333/**
Note: See TracChangeset for help on using the changeset viewer.