Changeset 97a62fe in mainline for uspace/lib/drv/generic/driver.c


Ignore:
Timestamp:
2011-02-14T21:41:50Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cd0684d
Parents:
7df0477e
Message:

Refactor create_function(), delete_function() and register_function() into
ddf_fun_create(), ddf_fun_destroy() and ddf_fun_bind(). This is not just
a rename.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/driver.c

    r7df0477e r97a62fe  
    477477 * @return              The device structure.
    478478 */
    479 function_t *create_function(void)
     479static function_t *create_function(void)
    480480{
    481481        function_t *fun;
    482482
    483         fun = malloc(sizeof(function_t));
     483        fun = calloc(1, sizeof(function_t));
    484484        if (fun == NULL)
    485485                return NULL;
    486486
    487         memset(fun, 0, sizeof(device_t));
    488 
    489487        init_match_ids(&fun->match_ids);
    490488        link_initialize(&fun->link);
     
    506504 * @param dev           The device structure.
    507505 */
    508 void delete_function(function_t *fun)
     506static void delete_function(function_t *fun)
    509507{
    510508        clean_match_ids(&fun->match_ids);
     
    514512}
    515513
     514/** Create a DDF function node.
     515 *
     516 * Create a DDF function (in memory). Both child devices and external clients
     517 * communicate with a device via its functions.
     518 *
     519 * The created function node is fully formed, but only exists in the memory
     520 * of the client task. In order to be visible to the system, the function
     521 * must be bound using ddf_fun_bind().
     522 *
     523 * This function should only fail if there is not enough free memory.
     524 * Specifically, this function succeeds even if @a dev already has
     525 * a (bound) function with the same name.
     526 *
     527 * Type: A function of type fun_inner indicates that DDF should attempt
     528 * to attach child devices to the function. fun_exposed means that
     529 * the function should be exported to external clients (applications).
     530 *
     531 * @param dev           Device to which we are adding function
     532 * @param ftype         Type of function (fun_inner or fun_exposed)
     533 * @param name          Name of function
     534 *
     535 * @return              New function or @c NULL if memory is not available
     536 */
     537function_t *ddf_fun_create(device_t *dev, fun_type_t ftype, const char *name)
     538{
     539        function_t *fun;
     540
     541        fun = create_function();
     542        if (fun == NULL)
     543                return NULL;
     544
     545        fun->bound = false;
     546        fun->dev = dev;
     547        fun->ftype = ftype;
     548
     549        fun->name = str_dup(name);
     550        if (fun->name == NULL) {
     551                delete_function(fun);
     552                return NULL;
     553        }
     554
     555        return fun;
     556}
     557
     558/** Destroy DDF function node.
     559 *
     560 * Destroy a function previously created with ddf_fun_create(). The function
     561 * must not be bound.
     562 *
     563 * @param fun           Function to destroy
     564 */
     565void ddf_fun_destroy(function_t *fun)
     566{
     567        assert(fun->bound == false);
     568        delete_function(fun);
     569}
     570
    516571void *function_get_ops(function_t *fun, dev_inferface_idx_t idx)
    517572{
     
    522577}
    523578
    524 int register_function(function_t *fun, device_t *dev)
     579/** Bind a function node.
     580 *
     581 * Bind the specified function to the system. This effectively makes
     582 * the function visible to the system (uploads it to the server).
     583 *
     584 * This function can fail for several reasons. Specifically,
     585 * it will fail if the device already has a bound function of
     586 * the same name.
     587 *
     588 * @param fun           Function to bind
     589 * @return              EOK on success or negative error code
     590 */
     591int ddf_fun_bind(function_t *fun)
    525592{
    526593        assert(fun->name != NULL);
    527594       
    528595        int res;
    529        
    530         fun->dev = dev;
    531596       
    532597        add_to_functions_list(fun);
    533598        res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
    534             dev->handle, &fun->handle);
     599            fun->dev->handle, &fun->handle);
    535600        if (res != EOK) {
    536601                remove_from_functions_list(fun);
     
    538603        }
    539604       
     605        fun->bound = true;
    540606        return res;
    541607}
     
    556622        int rc;
    557623       
    558         fun = create_function();
     624        fun = ddf_fun_create(dev, fun_inner, fun_name);
    559625        if (fun == NULL) {
    560626                rc = ENOMEM;
    561627                goto failure;
    562628        }
    563        
    564         fun->dev = dev;
    565         fun->name = fun_name;
    566         fun->ftype = fun_inner;
    567629       
    568630        m_id = create_match_id();
     
    576638        add_match_id(&fun->match_ids, m_id);
    577639       
    578         rc = register_function(fun, dev);
     640        rc = ddf_fun_bind(fun);
    579641        if (rc != EOK)
    580642                goto failure;
Note: See TracChangeset for help on using the changeset viewer.