Changeset 08bc23d in mainline


Ignore:
Timestamp:
2013-09-10T20:26:27Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d80d7a8
Parents:
07525cd (diff), a60e90b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge breaking devman.c apart.

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

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/Makefile

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

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

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

    r07525cd r08bc23d  
    3131 */
    3232
     33#include <fcntl.h>
     34#include <io/log.h>
    3335#include <str.h>
     36#include <str_error.h>
     37#include <sys/types.h>
     38#include <sys/stat.h>
    3439
    3540#include "devman.h"
     41#include "match.h"
    3642
    3743/** Compute compound score of driver and device.
     
    9399}
    94100
     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 */
     107char *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 */
     136bool 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 */
     186bool 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       
     229cleanup:
     230        free(buf);
     231       
     232        if (opened)
     233                close(fd);
     234       
     235        return suc;
     236}
     237
    95238/** @}
    96239 */
Note: See TracChangeset for help on using the changeset viewer.