Ignore:
File:
1 edited

Legend:

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

    rae3a941 rb7fd2a0  
    7373 * @return Error code
    7474 */
    75 errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
    76     int32_t usage_page, int32_t usage)
    77 {
    78         usb_hid_report_usage_path_t *item =
    79             malloc(sizeof(usb_hid_report_usage_path_t));
     75errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 
     76                                    int32_t usage_page, int32_t usage)
     77{       
     78        usb_hid_report_usage_path_t *item
     79                = malloc(sizeof(usb_hid_report_usage_path_t));
    8080
    8181        if (item == NULL) {
     
    8787        item->usage_page = usage_page;
    8888        item->flags = 0;
    89 
     89       
    9090        list_append (&item->rpath_items_link, &usage_path->items);
    9191        usage_path->depth++;
     
    9696/**
    9797 * Removes last item from the usage path structure
    98  * @param usage_path
     98 * @param usage_path 
    9999 * @return void
    100100 */
     
    103103        link_t *item_link;
    104104        usb_hid_report_usage_path_t *item;
    105 
    106         if (!list_empty(&usage_path->items)) {
     105       
     106        if(!list_empty(&usage_path->items)){
    107107                item_link = list_last(&usage_path->items);
    108108                item = list_get_instance(item_link,
     
    124124{
    125125        usb_hid_report_usage_path_t *item;
    126 
    127         if (!list_empty(&usage_path->items)) {
     126       
     127        if(!list_empty(&usage_path->items)){
    128128                item = list_get_instance(list_last(&usage_path->items),
    129                     usb_hid_report_usage_path_t, rpath_items_link);
     129                        usb_hid_report_usage_path_t, rpath_items_link);
    130130
    131131                memset(item, 0, sizeof(usb_hid_report_usage_path_t));
     
    143143 * @return void
    144144 */
    145 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path,
    146     int32_t tag, int32_t data)
     145void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 
     146                                  int32_t tag, int32_t data)
    147147{
    148148        usb_hid_report_usage_path_t *item;
    149 
    150         if (!list_empty(&usage_path->items)) {
     149       
     150        if(!list_empty(&usage_path->items)){
    151151                item = list_get_instance(list_last(&usage_path->items),
    152152                     usb_hid_report_usage_path_t, rpath_items_link);
    153153
    154                 switch (tag) {
    155                 case USB_HID_TAG_CLASS_GLOBAL:
    156                         item->usage_page = data;
    157                         break;
    158                 case USB_HID_TAG_CLASS_LOCAL:
    159                         item->usage = data;
    160                         break;
    161                 }
    162         }
    163 }
    164 
     154                switch(tag) {
     155                        case USB_HID_TAG_CLASS_GLOBAL:
     156                                item->usage_page = data;
     157                                break;
     158                        case USB_HID_TAG_CLASS_LOCAL:
     159                                item->usage = data;
     160                                break;
     161                }
     162        }
     163       
     164}
     165
     166
     167/**
     168 *
     169 *
     170 *
     171 *
     172 */
    165173void usb_hid_print_usage_path(usb_hid_report_path_t *path)
    166174{
    167         usb_log_debug("USAGE_PATH FOR RId(%d):", path->report_id);
    168         usb_log_debug("\tLENGTH: %d", path->depth);
     175        usb_log_debug("USAGE_PATH FOR RId(%d):\n", path->report_id);
     176        usb_log_debug("\tLENGTH: %d\n", path->depth);
    169177
    170178        list_foreach(path->items, rpath_items_link,
    171179            usb_hid_report_usage_path_t, path_item) {
    172180
    173                 usb_log_debug("\tUSAGE_PAGE: %X", path_item->usage_page);
    174                 usb_log_debug("\tUSAGE: %X", path_item->usage);
    175                 usb_log_debug("\tFLAGS: %d", path_item->flags);
     181                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
     182                usb_log_debug("\tUSAGE: %X\n", path_item->usage);
     183                usb_log_debug("\tFLAGS: %d\n", path_item->flags);
    176184        }
    177185}
     
    191199        usb_hid_report_usage_path_t *report_item;
    192200        usb_hid_report_usage_path_t *path_item;
    193 
     201       
    194202        link_t *report_link;
    195203        link_t *path_link;
    196 
     204       
    197205        int only_page;
    198 
     206       
    199207        if (report_path->report_id != path->report_id) {
    200208                if (path->report_id != 0) {
     
    202210                }
    203211        }
    204 
     212       
    205213        // Empty path match all others
    206214        if (path->depth == 0) {
    207215                return 0;
    208216        }
    209 
     217       
    210218        if ((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0) {
    211219                flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY;
    212220        }
    213 
     221       
    214222        switch (flags) {
    215223        /* Path is somewhere in report_path */
     
    218226                        return 1;
    219227                }
    220 
     228               
    221229                path_link = list_first(&path->items);
    222230                path_item = list_get_instance(path_link,
    223231                    usb_hid_report_usage_path_t, rpath_items_link);
    224 
     232               
    225233                list_foreach(report_path->items, rpath_items_link,
    226234                    usb_hid_report_usage_path_t, report_item) {
    227235                        if (USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    228236                            path_item->usage_page)) {
    229 
     237                               
    230238                                if (only_page == 0) {
    231239                                        if (USB_HID_SAME_USAGE(report_item->usage,
     
    237245                        }
    238246                }
    239 
     247               
    240248                return 1;
    241249                break;
    242 
     250       
    243251        /* The paths must be identical */
    244252        case USB_HID_PATH_COMPARE_STRICT:
     
    247255                }
    248256                /* Fallthrough */
    249 
     257       
    250258        /* Path is prefix of the report_path */
    251259        case USB_HID_PATH_COMPARE_BEGIN:
    252260                report_link = report_path->items.head.next;
    253261                path_link = path->items.head.next;
    254 
     262               
    255263                while ((report_link != &report_path->items.head) &&
    256264                    (path_link != &path->items.head)) {
    257 
     265                       
    258266                        report_item = list_get_instance(report_link,
    259267                            usb_hid_report_usage_path_t, rpath_items_link);
    260 
     268                       
    261269                        path_item = list_get_instance(path_link,
    262270                            usb_hid_report_usage_path_t, rpath_items_link);
    263 
     271                       
    264272                        if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    265273                            path_item->usage_page) || ((only_page == 0) &&
     
    272280                        }
    273281                }
    274 
     282               
    275283                if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
    276284                    (path_link == &path->items.head)) ||
     
    282290                }
    283291                break;
    284 
     292       
    285293        /* Path is suffix of report_path */
    286294        case USB_HID_PATH_COMPARE_END:
    287295                report_link = report_path->items.head.prev;
    288296                path_link = path->items.head.prev;
    289 
     297               
    290298                if (list_empty(&path->items)) {
    291299                        return 0;
    292300                }
    293 
     301               
    294302                while ((report_link != &report_path->items.head) &&
    295303                      (path_link != &path->items.head)) {
    296304                        report_item = list_get_instance(report_link,
    297305                            usb_hid_report_usage_path_t, rpath_items_link);
    298 
     306                       
    299307                        path_item = list_get_instance(path_link,
    300308                            usb_hid_report_usage_path_t, rpath_items_link);
    301 
     309                       
    302310                        if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    303311                            path_item->usage_page) || ((only_page == 0) &&
     
    310318                        }
    311319                }
    312 
     320               
    313321                if (path_link == &path->items.head) {
    314322                        return 0;
     
    317325                }
    318326                break;
    319 
     327       
    320328        default:
    321329                return -1;
     
    332340        usb_hid_report_path_t *path;
    333341        path = malloc(sizeof(usb_hid_report_path_t));
    334         if (path == NULL) {
     342        if(path == NULL){
    335343                return NULL;
    336344        }
     
    355363        if (path == NULL)
    356364                return;
    357         while (!list_empty(&path->items)) {
     365        while(!list_empty(&path->items)){
    358366                usb_hid_report_remove_last_item(path);
    359367        }
     
    371379 */
    372380usb_hid_report_path_t *usb_hid_report_path_clone(
    373     usb_hid_report_path_t *usage_path)
     381        usb_hid_report_path_t *usage_path)
    374382{
    375383        usb_hid_report_usage_path_t *new_path_item;
    376384        usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
    377385
    378         if (new_usage_path == NULL) {
     386        if(new_usage_path == NULL){
    379387                return NULL;
    380388        }
    381389
    382390        new_usage_path->report_id = usage_path->report_id;
    383 
    384         if (list_empty(&usage_path->items)) {
     391       
     392        if(list_empty(&usage_path->items)){
    385393                return new_usage_path;
    386394        }
     
    390398
    391399                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
    392                 if (new_path_item == NULL) {
     400                if(new_path_item == NULL) {
    393401                        return NULL;
    394402                }
    395 
     403               
    396404                link_initialize(&new_path_item->rpath_items_link);
    397405                new_path_item->usage_page = path_item->usage_page;
    398                 new_path_item->usage = path_item->usage;
    399                 new_path_item->flags = path_item->flags;
    400 
     406                new_path_item->usage = path_item->usage;               
     407                new_path_item->flags = path_item->flags;               
     408               
    401409                list_append(&new_path_item->rpath_items_link,
    402410                    &new_usage_path->items);
     
    415423 * @return Error code
    416424 */
    417 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path,
    418     uint8_t report_id)
    419 {
    420         if (path == NULL) {
     425errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 
     426        uint8_t report_id)
     427{
     428        if(path == NULL){
    421429                return EINVAL;
    422430        }
Note: See TracChangeset for help on using the changeset viewer.