Changes in / [08bc23d:07525cd] in mainline


Ignore:
Location:
uspace/srv/devman
Files:
1 added
11 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/Makefile

    r08bc23d r07525cd  
    3333
    3434SOURCES = \
    35         dev.c \
    36         devtree.c \
    37         driver.c \
    38         loc.c \
    39         fun.c \
    4035        main.c \
     36        devman.c \
    4137        match.c \
    4238        util.c
  • uspace/srv/devman/devman.h

    r08bc23d r07525cd  
    3535#define DEVMAN_H_
    3636
     37#include <assert.h>
    3738#include <stdbool.h>
     39#include <dirent.h>
     40#include <str.h>
    3841#include <adt/list.h>
    3942#include <adt/hash_table.h>
     
    4750
    4851#define NAME "devman"
     52
     53#define MATCH_EXT ".ma"
    4954
    5055#define LOC_DEVICE_NAMESPACE "devices"
     
    233238} dev_tree_t;
    234239
     240/* Match ids and scores */
     241
     242extern int get_match_score(driver_t *, dev_node_t *);
     243
     244extern bool parse_match_ids(char *, match_id_list_t *);
     245extern bool read_match_ids(const char *, match_id_list_t *);
     246extern char *read_match_id(char **);
     247extern char *read_id(const char **);
     248
     249/* Drivers */
     250
     251extern void init_driver_list(driver_list_t *);
     252extern driver_t *create_driver(void);
     253extern bool get_driver_info(const char *, const char *, driver_t *);
     254extern int lookup_available_drivers(driver_list_t *, const char *);
     255
     256extern driver_t *find_best_match_driver(driver_list_t *, dev_node_t *);
     257extern bool assign_driver(dev_node_t *, driver_list_t *, dev_tree_t *);
     258
     259extern void add_driver(driver_list_t *, driver_t *);
     260extern void attach_driver(dev_tree_t *, dev_node_t *, driver_t *);
     261extern void detach_driver(dev_tree_t *, dev_node_t *);
     262extern void add_device(driver_t *, dev_node_t *, dev_tree_t *);
     263extern bool start_driver(driver_t *);
     264extern int driver_dev_remove(dev_tree_t *, dev_node_t *);
     265extern int driver_dev_gone(dev_tree_t *, dev_node_t *);
     266extern int driver_fun_online(dev_tree_t *, fun_node_t *);
     267extern int driver_fun_offline(dev_tree_t *, fun_node_t *);
     268
     269extern driver_t *find_driver(driver_list_t *, const char *);
     270extern void initialize_running_driver(driver_t *, dev_tree_t *);
     271
     272extern void init_driver(driver_t *);
     273extern void clean_driver(driver_t *);
     274extern void delete_driver(driver_t *);
     275
     276/* Device nodes */
     277
     278extern dev_node_t *create_dev_node(void);
     279extern void delete_dev_node(dev_node_t *node);
     280extern void dev_add_ref(dev_node_t *);
     281extern void dev_del_ref(dev_node_t *);
     282
     283extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree,
     284    devman_handle_t handle);
     285extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle);
     286extern dev_node_t *find_dev_function(dev_node_t *, const char *);
     287extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *,
     288    size_t, size_t *);
     289
     290extern fun_node_t *create_fun_node(void);
     291extern void delete_fun_node(fun_node_t *);
     292extern void fun_add_ref(fun_node_t *);
     293extern void fun_del_ref(fun_node_t *);
     294extern void fun_busy_lock(fun_node_t *);
     295extern void fun_busy_unlock(fun_node_t *);
     296extern fun_node_t *find_fun_node_no_lock(dev_tree_t *tree,
     297    devman_handle_t handle);
     298extern fun_node_t *find_fun_node(dev_tree_t *tree, devman_handle_t handle);
     299extern fun_node_t *find_fun_node_by_path(dev_tree_t *, char *);
     300extern fun_node_t *find_fun_node_in_device(dev_tree_t *tree, dev_node_t *,
     301    const char *);
     302
     303/* Device tree */
     304
     305extern bool init_device_tree(dev_tree_t *, driver_list_t *);
     306extern bool create_root_nodes(dev_tree_t *);
     307extern bool insert_dev_node(dev_tree_t *, dev_node_t *, fun_node_t *);
     308extern void remove_dev_node(dev_tree_t *, dev_node_t *);
     309extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
     310extern void remove_fun_node(dev_tree_t *, fun_node_t *);
     311
     312/* Loc services */
     313
     314extern void loc_register_tree_function(fun_node_t *, dev_tree_t *);
     315
     316extern fun_node_t *find_loc_tree_function(dev_tree_t *, service_id_t);
     317
     318extern void tree_add_loc_function(dev_tree_t *, fun_node_t *);
     319
    235320#endif
    236321
  • uspace/srv/devman/main.c

    r08bc23d r07525cd  
    5858#include <loc.h>
    5959
    60 #include "dev.h"
    6160#include "devman.h"
    62 #include "devtree.h"
    63 #include "driver.h"
    64 #include "fun.h"
    65 #include "loc.h"
    6661
    6762#define DRIVER_DEFAULT_STORE  "/drv"
  • uspace/srv/devman/match.c

    r08bc23d r07525cd  
    3131 */
    3232
    33 #include <fcntl.h>
    34 #include <io/log.h>
    3533#include <str.h>
    36 #include <str_error.h>
    37 #include <sys/types.h>
    38 #include <sys/stat.h>
    3934
    4035#include "devman.h"
    41 #include "match.h"
    4236
    4337/** Compute compound score of driver and device.
     
    9993}
    10094
    101 /** Read match id at the specified position of a string and set the position in
    102  * the string to the first character following the id.
    103  *
    104  * @param buf           The position in the input string.
    105  * @return              The match id.
    106  */
    107 char *read_match_id(char **buf)
    108 {
    109         char *res = NULL;
    110         size_t len = get_nonspace_len(*buf);
    111        
    112         if (len > 0) {
    113                 res = malloc(len + 1);
    114                 if (res != NULL) {
    115                         str_ncpy(res, len + 1, *buf, len);
    116                         *buf += len;
    117                 }
    118         }
    119        
    120         return res;
    121 }
    122 
    123 /**
    124  * Read match ids and associated match scores from a string.
    125  *
    126  * Each match score in the string is followed by its match id.
    127  * The match ids and match scores are separated by whitespaces.
    128  * Neither match ids nor match scores can contain whitespaces.
    129  *
    130  * @param buf           The string from which the match ids are read.
    131  * @param ids           The list of match ids into which the match ids and
    132  *                      scores are added.
    133  * @return              True if at least one match id and associated match score
    134  *                      was successfully read, false otherwise.
    135  */
    136 bool parse_match_ids(char *buf, match_id_list_t *ids)
    137 {
    138         int score = 0;
    139         char *id = NULL;
    140         int ids_read = 0;
    141        
    142         while (true) {
    143                 /* skip spaces */
    144                 if (!skip_spaces(&buf))
    145                         break;
    146                
    147                 /* read score */
    148                 score = strtoul(buf, &buf, 10);
    149                
    150                 /* skip spaces */
    151                 if (!skip_spaces(&buf))
    152                         break;
    153                
    154                 /* read id */
    155                 id = read_match_id(&buf);
    156                 if (NULL == id)
    157                         break;
    158                
    159                 /* create new match_id structure */
    160                 match_id_t *mid = create_match_id();
    161                 mid->id = id;
    162                 mid->score = score;
    163                
    164                 /* add it to the list */
    165                 add_match_id(ids, mid);
    166                
    167                 ids_read++;
    168         }
    169        
    170         return ids_read > 0;
    171 }
    172 
    173 /**
    174  * Read match ids and associated match scores from a file.
    175  *
    176  * Each match score in the file is followed by its match id.
    177  * The match ids and match scores are separated by whitespaces.
    178  * Neither match ids nor match scores can contain whitespaces.
    179  *
    180  * @param buf           The path to the file from which the match ids are read.
    181  * @param ids           The list of match ids into which the match ids and
    182  *                      scores are added.
    183  * @return              True if at least one match id and associated match score
    184  *                      was successfully read, false otherwise.
    185  */
    186 bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    187 {
    188         log_msg(LOG_DEFAULT, LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path);
    189        
    190         bool suc = false;
    191         char *buf = NULL;
    192         bool opened = false;
    193         int fd;
    194         size_t len = 0;
    195        
    196         fd = open(conf_path, O_RDONLY);
    197         if (fd < 0) {
    198                 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.",
    199                     conf_path, str_error(fd));
    200                 goto cleanup;
    201         }
    202         opened = true;
    203        
    204         len = lseek(fd, 0, SEEK_END);
    205         lseek(fd, 0, SEEK_SET);
    206         if (len == 0) {
    207                 log_msg(LOG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.",
    208                     conf_path);
    209                 goto cleanup;
    210         }
    211        
    212         buf = malloc(len + 1);
    213         if (buf == NULL) {
    214                 log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed when parsing file "
    215                     "'%s'.", conf_path);
    216                 goto cleanup;
    217         }
    218        
    219         ssize_t read_bytes = read_all(fd, buf, len);
    220         if (read_bytes <= 0) {
    221                 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
    222                     read_bytes);
    223                 goto cleanup;
    224         }
    225         buf[read_bytes] = 0;
    226        
    227         suc = parse_match_ids(buf, ids);
    228        
    229 cleanup:
    230         free(buf);
    231        
    232         if (opened)
    233                 close(fd);
    234        
    235         return suc;
    236 }
    237 
    23895/** @}
    23996 */
Note: See TracChangeset for help on using the changeset viewer.