Changeset 8b655705 in mainline for uspace/drv/test2/test2.c


Ignore:
Timestamp:
2011-04-15T19:38:07Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9dd730d1
Parents:
6b9e85b (diff), b2fb47f (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 mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/test2/test2.c

    r6b9e85b r8b655705  
    3131
    3232#include <assert.h>
     33#include <async.h>
    3334#include <stdio.h>
    3435#include <errno.h>
    3536#include <str_error.h>
    36 #include <driver.h>
     37#include <ddf/driver.h>
     38#include <ddf/log.h>
    3739
    3840#define NAME "test2"
    3941
    40 static int add_device(device_t *dev);
     42static int test2_add_device(ddf_dev_t *dev);
    4143
    4244static driver_ops_t driver_ops = {
    43         .add_device = &add_device
     45        .add_device = &test2_add_device
    4446};
    4547
    46 static driver_t the_driver = {
     48static driver_t test2_driver = {
    4749        .name = NAME,
    4850        .driver_ops = &driver_ops
     
    5759 * @param score Device match score.
    5860 */
    59 static void register_child_verbose(device_t *parent, const char *message,
     61static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    6062    const char *name, const char *match_id, int match_score)
    6163{
    62         printf(NAME ": registering child device `%s': %s.\n",
    63            name, message);
     64        ddf_fun_t *fun;
     65        int rc;
    6466
    65         int rc = child_device_register_wrapper(parent, name,
    66             match_id, match_score);
     67        ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
    6768
    68         if (rc == EOK) {
    69                 printf(NAME ": registered child device `%s'.\n", name);
    70         } else {
    71                 printf(NAME ": failed to register child `%s' (%s).\n",
    72                     name, str_error(rc));
     69        fun = ddf_fun_create(parent, fun_inner, name);
     70        if (fun == NULL) {
     71                ddf_msg(LVL_ERROR, "Failed creating function %s", name);
     72                return ENOMEM;
    7373        }
     74
     75        rc = ddf_fun_add_match_id(fun, match_id, match_score);
     76        if (rc != EOK) {
     77                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     78                    name);
     79                ddf_fun_destroy(fun);
     80                return rc;
     81        }
     82
     83        rc = ddf_fun_bind(fun);
     84        if (rc != EOK) {
     85                ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
     86                    str_error(rc));
     87                ddf_fun_destroy(fun);
     88                return rc;
     89        }
     90
     91        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
     92        return EOK;
    7493}
    7594
    7695/** Add child devices after some sleep.
    7796 *
    78  * @param arg Parent device structure (device_t *).
     97 * @param arg Parent device structure (ddf_dev_t *).
    7998 * @return Always EOK.
    8099 */
    81100static int postponed_birth(void *arg)
    82101{
    83         device_t *dev = (device_t *) arg;
     102        ddf_dev_t *dev = (ddf_dev_t *) arg;
     103        ddf_fun_t *fun_a;
     104        int rc;
    84105
    85106        async_usleep(1000);
    86107
    87         register_child_verbose(dev, "child driven by the same task",
     108        (void) register_fun_verbose(dev, "child driven by the same task",
    88109            "child", "virtual&test2", 10);
    89         register_child_verbose(dev, "child driven by test1",
     110        (void) register_fun_verbose(dev, "child driven by test1",
    90111            "test1", "virtual&test1", 10);
    91112
    92         add_device_to_class(dev, "virtual");
     113        fun_a = ddf_fun_create(dev, fun_exposed, "a");
     114        if (fun_a == NULL) {
     115                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
     116                return ENOMEM;
     117        }
     118
     119        rc = ddf_fun_bind(fun_a);
     120        if (rc != EOK) {
     121                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
     122                return rc;
     123        }
     124
     125        ddf_fun_add_to_class(fun_a, "virtual");
    93126
    94127        return EOK;
    95128}
    96129
    97 
    98 static int add_device(device_t *dev)
     130static int test2_add_device(ddf_dev_t *dev)
    99131{
    100         printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
     132        ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",
    101133            dev->name, (int) dev->handle);
    102134
    103         if (dev->parent == NULL) {
     135        if (str_cmp(dev->name, "child") != 0) {
    104136                fid_t postpone = fibril_create(postponed_birth, dev);
     137                if (postpone == 0) {
     138                        ddf_msg(LVL_ERROR, "fibril_create() failed.");
     139                        return ENOMEM;
     140                }
    105141                fibril_add_ready(postpone);
    106142        } else {
    107                 register_child_verbose(dev, "child without available driver",
     143                (void) register_fun_verbose(dev, "child without available driver",
    108144                    "ERROR", "non-existent.match.id", 10);
    109145        }
     
    115151{
    116152        printf(NAME ": HelenOS test2 virtual device driver\n");
    117         return driver_main(&the_driver);
     153        ddf_log_init(NAME, LVL_ERROR);
     154        return ddf_driver_main(&test2_driver);
    118155}
    119156
Note: See TracChangeset for help on using the changeset viewer.