Changeset 3b5d1535 in mainline for uspace/drv/test1/test1.c


Ignore:
Timestamp:
2011-02-23T10:28:21Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eb48f61
Parents:
e936e8e (diff), eb1a2f4 (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/test1/test1.c

    re936e8e r3b5d1535  
    3434#include <errno.h>
    3535#include <str_error.h>
     36#include <ddf/driver.h>
     37
    3638#include "test1.h"
    3739
    38 static int add_device(device_t *dev);
     40static int test1_add_device(ddf_dev_t *dev);
    3941
    4042static driver_ops_t driver_ops = {
    41         .add_device = &add_device
     43        .add_device = &test1_add_device
    4244};
    4345
    44 static driver_t the_driver = {
     46static driver_t test1_driver = {
    4547        .name = NAME,
    4648        .driver_ops = &driver_ops
     
    5557 * @param score Device match score.
    5658 */
    57 static void register_child_verbose(device_t *parent, const char *message,
     59static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    5860    const char *name, const char *match_id, int match_score)
    5961{
    60         printf(NAME ": registering child device `%s': %s.\n",
    61            name, message);
     62        ddf_fun_t *fun;
     63        int rc;
    6264
    63         int rc = child_device_register_wrapper(parent, name,
    64             match_id, match_score, NULL);
     65        printf(NAME ": registering function `%s': %s.\n", name, message);
    6566
    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));
     67        fun = ddf_fun_create(parent, fun_inner, name);
     68        if (fun == NULL) {
     69                printf(NAME ": error creating function %s\n", name);
     70                return ENOMEM;
    7171        }
     72
     73        rc = ddf_fun_add_match_id(fun, match_id, match_score);
     74        if (rc != EOK) {
     75                printf(NAME ": error adding match IDs to function %s\n", name);
     76                ddf_fun_destroy(fun);
     77                return rc;
     78        }
     79
     80        rc = ddf_fun_bind(fun);
     81        if (rc != EOK) {
     82                printf(NAME ": error binding function %s: %s\n", name,
     83                    str_error(rc));
     84                ddf_fun_destroy(fun);
     85                return rc;
     86        }
     87
     88        printf(NAME ": registered child device `%s'\n", name);
     89        return EOK;
    7290}
    7391
     
    89107 * @return Error code reporting success of the operation.
    90108 */
    91 static int add_device(device_t *dev)
     109static int test1_add_device(ddf_dev_t *dev)
    92110{
     111        ddf_fun_t *fun_a;
     112        int rc;
     113
    93114        printf(NAME ": add_device(name=\"%s\", handle=%d)\n",
    94115            dev->name, (int) dev->handle);
    95116
    96         add_device_to_class(dev, "virtual");
     117        fun_a = ddf_fun_create(dev, fun_exposed, "a");
     118        if (fun_a == NULL) {
     119                printf(NAME ": error creating function 'a'.\n");
     120                return ENOMEM;
     121        }
     122
     123        rc = ddf_fun_bind(fun_a);
     124        if (rc != EOK) {
     125                printf(NAME ": error binding function 'a'.\n");
     126                return rc;
     127        }
     128
     129        ddf_fun_add_to_class(fun_a, "virtual");
    97130
    98131        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",
     132                fun_a->ops = &char_device_ops;
     133                ddf_fun_add_to_class(fun_a, "virt-null");
     134        } else if (str_cmp(dev->name, "test1") == 0) {
     135                (void) register_fun_verbose(dev, "cloning myself ;-)", "clone",
    103136                    "virtual&test1", 10);
    104137        } else if (str_cmp(dev->name, "clone") == 0) {
    105                 register_child_verbose(dev, "run by the same task", "child",
     138                (void) register_fun_verbose(dev, "run by the same task", "child",
    106139                    "virtual&test1&child", 10);
    107140        }
     
    115148{
    116149        printf(NAME ": HelenOS test1 virtual device driver\n");
    117         return driver_main(&the_driver);
     150        return ddf_driver_main(&test1_driver);
    118151}
    119152
Note: See TracChangeset for help on using the changeset viewer.