Ignore:
File:
1 edited

Legend:

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

    rebcb05a r7551706b  
    3434#include <errno.h>
    3535#include <str_error.h>
    36 #include <ddf/driver.h>
    37 #include <ddf/log.h>
    38 
    3936#include "test1.h"
    4037
    41 static int test1_add_device(ddf_dev_t *dev);
     38static int add_device(device_t *dev);
    4239
    4340static driver_ops_t driver_ops = {
    44         .add_device = &test1_add_device
     41        .add_device = &add_device
    4542};
    4643
    47 static driver_t test1_driver = {
     44static driver_t the_driver = {
    4845        .name = NAME,
    4946        .driver_ops = &driver_ops
     
    5855 * @param score Device match score.
    5956 */
    60 static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    61     const char *name, const char *match_id, int match_score,
    62     int expected_rc)
     57static void register_child_verbose(device_t *parent, const char *message,
     58    const char *name, const char *match_id, int match_score)
    6359{
    64         ddf_fun_t *fun = NULL;
    65         int rc;
     60        printf(NAME ": registering child device `%s': %s.\n",
     61           name, message);
    6662
    67         ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
     63        int rc = child_device_register_wrapper(parent, name,
     64            match_id, match_score);
    6865
    69         fun = ddf_fun_create(parent, fun_inner, name);
    70         if (fun == NULL) {
    71                 ddf_msg(LVL_ERROR, "Failed creating function %s", name);
    72                 rc = ENOMEM;
    73                 goto leave;
     66        if (rc == EOK) {
     67                printf(NAME ": registered child device `%s'.\n", name);
     68        } else {
     69                printf(NAME ": failed to register child `%s' (%s).\n",
     70                    name, str_error(rc));
    7471        }
    75 
    76         rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);
    77         if (rc != EOK) {
    78                 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
    79                     name);
    80                 goto leave;
    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                 goto leave;
    88         }
    89 
    90         ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
    91         rc = EOK;
    92 
    93 leave:
    94         if (rc != expected_rc) {
    95                 fprintf(stderr,
    96                     NAME ": Unexpected error registering function `%s'.\n"
    97                     NAME ":     Expected \"%s\" but got \"%s\".\n",
    98                     name, str_error(expected_rc), str_error(rc));
    99         }
    100 
    101         if ((rc != EOK) && (fun != NULL)) {
    102                 ddf_fun_destroy(fun);
    103         }
    104 
    105         return rc;
    10672}
    10773
     
    12389 * @return Error code reporting success of the operation.
    12490 */
    125 static int test1_add_device(ddf_dev_t *dev)
     91static int add_device(device_t *dev)
    12692{
    127         ddf_fun_t *fun_a;
    128         int rc;
    129 
    130         ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
     93        printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
    13194            dev->name, (int) dev->handle);
    13295
    133         fun_a = ddf_fun_create(dev, fun_exposed, "a");
    134         if (fun_a == NULL) {
    135                 ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
    136                 return ENOMEM;
     96        add_device_to_class(dev, "virtual");
     97
     98        if (str_cmp(dev->name, "null") == 0) {
     99                dev->ops = &char_device_ops;
     100                add_device_to_class(dev, "virt-null");
     101        } else if (dev->parent == NULL) {
     102                register_child_verbose(dev, "cloning myself ;-)", "clone",
     103                    "virtual&test1", 10);
     104        } else if (str_cmp(dev->name, "clone") == 0) {
     105                register_child_verbose(dev, "run by the same task", "child",
     106                    "virtual&test1&child", 10);
    137107        }
    138108
    139         rc = ddf_fun_bind(fun_a);
    140         if (rc != EOK) {
    141                 ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
    142                 return rc;
    143         }
    144 
    145         ddf_fun_add_to_class(fun_a, "virtual");
    146 
    147         if (str_cmp(dev->name, "null") == 0) {
    148                 fun_a->ops = &char_device_ops;
    149                 ddf_fun_add_to_class(fun_a, "virt-null");
    150         } else if (str_cmp(dev->name, "test1") == 0) {
    151                 (void) register_fun_verbose(dev,
    152                     "cloning myself ;-)", "clone",
    153                     "virtual&test1", 10, EOK);
    154                 (void) register_fun_verbose(dev,
    155                     "cloning myself twice ;-)", "clone",
    156                     "virtual&test1", 10, EEXISTS);
    157         } else if (str_cmp(dev->name, "clone") == 0) {
    158                 (void) register_fun_verbose(dev,
    159                     "run by the same task", "child",
    160                     "virtual&test1&child", 10, EOK);
    161         }
    162 
    163         ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);
     109        printf(NAME ": device `%s' accepted.\n", dev->name);
    164110
    165111        return EOK;
     
    169115{
    170116        printf(NAME ": HelenOS test1 virtual device driver\n");
    171         ddf_log_init(NAME, LVL_ERROR);
    172         return ddf_driver_main(&test1_driver);
     117        return driver_main(&the_driver);
    173118}
    174119
Note: See TracChangeset for help on using the changeset viewer.