Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset cc70d57 in mainline


Ignore:
Timestamp:
2010-11-26T13:23:47Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
0d6915f
Parents:
8b3bff5
Message:

Better match_id matching

Previously, ids were matched in descending score order which lead to
unexpected behaviour.

Now, all ids are compared and the best score is returned.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/match.c

    r8b3bff5 rcc70d57  
    3535#include "devman.h"
    3636
     37/** Compute compound score of driver and device.
     38 *
     39 * @param driver Match id of the driver.
     40 * @param device Match id of the device.
     41 * @return Compound score.
     42 * @retval 0 No match at all.
     43 */
     44static int compute_match_score(match_id_t *driver, match_id_t *device)
     45{
     46        if (str_cmp(driver->id, device->id) == 0) {
     47                /*
     48                 * The strings matches, return their score multiplied.
     49                 */
     50                return driver->score * device->score;
     51        } else {
     52                /*
     53                 * Different strings, return zero.
     54                 */
     55                return 0;
     56        }
     57}
     58
    3759int get_match_score(driver_t *drv, node_t *dev)
    3860{
     
    4365                return 0;
    4466       
     67        /*
     68         * Go through all pairs, return the highest score obtainetd.
     69         */
     70        int highest_score = 0;
     71       
    4572        link_t *drv_link = drv->match_ids.ids.next;
    46         link_t *dev_link = dev->match_ids.ids.next;
    47        
    48         match_id_t *drv_id = list_get_instance(drv_link, match_id_t, link);
    49         match_id_t *dev_id = list_get_instance(dev_link, match_id_t, link);
    50        
    51         int score_next_drv = 0;
    52         int score_next_dev = 0;
    53        
    54         do {
    55                 match_id_t *tmp_ma_id;
    56        
    57                 if (str_cmp(drv_id->id, dev_id->id) == 0) {
    58                         /*
    59                          * We found a match.
    60                          * Return the score of the match.
    61                          */
    62                         return drv_id->score * dev_id->score;
     73        while (drv_link != drv_head) {
     74                link_t *dev_link = dev_head->next;
     75                while (dev_link != dev_head) {
     76                        match_id_t *drv_id = list_get_instance(drv_link, match_id_t, link);
     77                        match_id_t *dev_id = list_get_instance(dev_link, match_id_t, link);
     78                       
     79                        int score = compute_match_score(drv_id, dev_id);
     80                        if (score > highest_score) {
     81                                highest_score = score;
     82                        }
     83
     84                        dev_link = dev_link->next;
    6385                }
    6486               
    65                 /*
    66                  * Compute the next score we get, if we advance in the driver's
    67                  * list of match ids.
    68                  */
    69                 if (drv_link->next != drv_head) {
    70                         tmp_ma_id = list_get_instance(drv_link->next,
    71                             match_id_t, link);
    72                         score_next_drv = dev_id->score * tmp_ma_id->score;
    73                 } else {
    74                         score_next_drv = 0;
    75                 }
    76                
    77                 /*
    78                  * Compute the next score we get, if we advance in the device's
    79                  * list of match ids.
    80                  */
    81                 if (dev_link->next != dev_head) {
    82                         tmp_ma_id = list_get_instance(dev_link->next,
    83                             match_id_t, link);
    84                         score_next_dev = drv_id->score * tmp_ma_id->score;
    85                 } else {
    86                         score_next_dev = 0;
    87                 }
    88                
    89                 /*
    90                  * Advance in one of the two lists, so we get the next highest
    91                  * score.
    92                  */
    93                 if (score_next_drv > score_next_dev) {
    94                         drv_link = drv_link->next;
    95                         drv_id = list_get_instance(drv_link, match_id_t, link);
    96                 } else {
    97                         dev_link = dev_link->next;
    98                         dev_id = list_get_instance(dev_link, match_id_t, link);
    99                 }
    100                
    101         } while (drv_link->next != drv_head && dev_link->next != dev_head);
     87                drv_link = drv_link->next;
     88        }
    10289       
    103         return 0;
     90        return highest_score;
    10491}
    10592
Note: See TracChangeset for help on using the changeset viewer.