Ignore:
File:
1 edited

Legend:

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

    raf6b5157 r9f6c5ef0  
    3131
    3232#include <assert.h>
    33 #include <async.h>
    3433#include <stdio.h>
    3534#include <errno.h>
    3635#include <str_error.h>
    37 #include <ddf/driver.h>
     36#include <driver.h>
    3837
    3938#define NAME "test2"
    4039
    41 static int test2_add_device(ddf_dev_t *dev);
     40static int add_device(device_t *dev);
    4241
    4342static driver_ops_t driver_ops = {
    44         .add_device = &test2_add_device
     43        .add_device = &add_device
    4544};
    4645
    47 static driver_t test2_driver = {
     46static driver_t the_driver = {
    4847        .name = NAME,
    4948        .driver_ops = &driver_ops
     
    5857 * @param score Device match score.
    5958 */
    60 static int register_fun_verbose(ddf_dev_t *parent, const char *message,
     59static void register_child_verbose(device_t *parent, const char *message,
    6160    const char *name, const char *match_id, int match_score)
    6261{
    63         ddf_fun_t *fun;
    64         int rc;
     62        printf(NAME ": registering child device `%s': %s.\n",
     63           name, message);
    6564
    66         printf(NAME ": registering function `%s': %s.\n", name, message);
     65        int rc = child_device_register_wrapper(parent, name,
     66            match_id, match_score, NULL);
    6767
    68         fun = ddf_fun_create(parent, fun_inner, name);
    69         if (fun == NULL) {
    70                 printf(NAME ": error creating function %s\n", name);
    71                 return ENOMEM;
     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));
    7273        }
    73 
    74         rc = ddf_fun_add_match_id(fun, match_id, match_score);
    75         if (rc != EOK) {
    76                 printf(NAME ": error adding match IDs to function %s\n", name);
    77                 ddf_fun_destroy(fun);
    78                 return rc;
    79         }
    80 
    81         rc = ddf_fun_bind(fun);
    82         if (rc != EOK) {
    83                 printf(NAME ": error binding function %s: %s\n", name,
    84                     str_error(rc));
    85                 ddf_fun_destroy(fun);
    86                 return rc;
    87         }
    88 
    89         printf(NAME ": registered child device `%s'\n", name);
    90         return EOK;
    9174}
    9275
    9376/** Add child devices after some sleep.
    9477 *
    95  * @param arg Parent device structure (ddf_dev_t *).
     78 * @param arg Parent device structure (device_t *).
    9679 * @return Always EOK.
    9780 */
    9881static int postponed_birth(void *arg)
    9982{
    100         ddf_dev_t *dev = (ddf_dev_t *) arg;
    101         ddf_fun_t *fun_a;
    102         int rc;
     83        device_t *dev = (device_t *) arg;
    10384
    10485        async_usleep(1000);
    10586
    106         (void) register_fun_verbose(dev, "child driven by the same task",
     87        register_child_verbose(dev, "child driven by the same task",
    10788            "child", "virtual&test2", 10);
    108         (void) register_fun_verbose(dev, "child driven by test1",
     89        register_child_verbose(dev, "child driven by test1",
    10990            "test1", "virtual&test1", 10);
    11091
    111         fun_a = ddf_fun_create(dev, fun_exposed, "a");
    112         if (fun_a == NULL) {
    113                 printf(NAME ": error creating function 'a'.\n");
    114                 return ENOMEM;
    115         }
    116 
    117         rc = ddf_fun_bind(fun_a);
    118         if (rc != EOK) {
    119                 printf(NAME ": error binding function 'a'.\n");
    120                 return rc;
    121         }
    122 
    123         ddf_fun_add_to_class(fun_a, "virtual");
     92        add_device_to_class(dev, "virtual");
    12493
    12594        return EOK;
    12695}
    12796
    128 static int test2_add_device(ddf_dev_t *dev)
     97
     98static int add_device(device_t *dev)
    12999{
    130         printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n",
     100        printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
    131101            dev->name, (int) dev->handle);
    132102
    133         if (str_cmp(dev->name, "child") != 0) {
     103        if (dev->parent == NULL) {
    134104                fid_t postpone = fibril_create(postponed_birth, dev);
    135                 if (postpone == 0) {
    136                         printf(NAME ": fibril_create() error\n");
    137                         return ENOMEM;
    138                 }
    139105                fibril_add_ready(postpone);
    140106        } else {
    141                 (void) register_fun_verbose(dev, "child without available driver",
     107                register_child_verbose(dev, "child without available driver",
    142108                    "ERROR", "non-existent.match.id", 10);
    143109        }
     
    149115{
    150116        printf(NAME ": HelenOS test2 virtual device driver\n");
    151         return ddf_driver_main(&test2_driver);
     117        return driver_main(&the_driver);
    152118}
    153119
Note: See TracChangeset for help on using the changeset viewer.