Changeset 8ff0bd2 in mainline for uspace/drv/test/test1/test1.c


Ignore:
Timestamp:
2011-09-04T11:30:58Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03bc76a
Parents:
d2c67e7 (diff), deac215e (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 moved

Legend:

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

    rd2c67e7 r8ff0bd2  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
     3 * Copyright (c) 2011 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    4041
    4142static int test1_add_device(ddf_dev_t *dev);
     43static int test1_dev_remove(ddf_dev_t *dev);
     44static int test1_fun_online(ddf_fun_t *fun);
     45static int test1_fun_offline(ddf_fun_t *fun);
    4246
    4347static driver_ops_t driver_ops = {
    44         .add_device = &test1_add_device
     48        .add_device = &test1_add_device,
     49        .dev_remove = &test1_dev_remove,
     50        .fun_online = &test1_fun_online,
     51        .fun_offline = &test1_fun_offline
    4552};
    4653
     
    4956        .driver_ops = &driver_ops
    5057};
     58
     59typedef struct {
     60        ddf_fun_t *fun_a;
     61        ddf_fun_t *clone;
     62        ddf_fun_t *child;
     63} test1_t;
    5164
    5265/** Register child and inform user about it.
     
    6073static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    6174    const char *name, const char *match_id, int match_score,
    62     int expected_rc)
     75    int expected_rc, ddf_fun_t **pfun)
    6376{
    6477        ddf_fun_t *fun = NULL;
     
    7487        }
    7588
    76         rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);
     89        rc = ddf_fun_add_match_id(fun, match_id, match_score);
    7790        if (rc != EOK) {
    7891                ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
     
    103116        }
    104117
     118        if (pfun != NULL)
     119                *pfun = fun;
     120
    105121        return rc;
    106122}
     
    126142{
    127143        ddf_fun_t *fun_a;
     144        test1_t *test1;
    128145        int rc;
    129146
    130147        ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
    131148            dev->name, (int) dev->handle);
     149
     150        test1 = ddf_dev_data_alloc(dev, sizeof(test1_t));
     151        if (test1 == NULL) {
     152                ddf_msg(LVL_ERROR, "Failed allocating soft state.\n");
     153                return ENOMEM;
     154        }
    132155
    133156        fun_a = ddf_fun_create(dev, fun_exposed, "a");
     
    137160        }
    138161
     162        test1->fun_a = fun_a;
     163
    139164        rc = ddf_fun_bind(fun_a);
    140165        if (rc != EOK) {
    141166                ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
     167                ddf_fun_destroy(fun_a);
    142168                return rc;
    143169        }
    144170
    145         ddf_fun_add_to_class(fun_a, "virtual");
     171        ddf_fun_add_to_category(fun_a, "virtual");
    146172
    147173        if (str_cmp(dev->name, "null") == 0) {
    148174                fun_a->ops = &char_device_ops;
    149                 ddf_fun_add_to_class(fun_a, "virt-null");
     175                ddf_fun_add_to_category(fun_a, "virt-null");
    150176        } else if (str_cmp(dev->name, "test1") == 0) {
    151177                (void) register_fun_verbose(dev,
    152178                    "cloning myself ;-)", "clone",
    153                     "virtual&test1", 10, EOK);
     179                    "virtual&test1", 10, EOK, &test1->clone);
    154180                (void) register_fun_verbose(dev,
    155181                    "cloning myself twice ;-)", "clone",
    156                     "virtual&test1", 10, EEXISTS);
     182                    "virtual&test1", 10, EEXISTS, NULL);
    157183        } else if (str_cmp(dev->name, "clone") == 0) {
    158184                (void) register_fun_verbose(dev,
    159185                    "run by the same task", "child",
    160                     "virtual&test1&child", 10, EOK);
     186                    "virtual&test1&child", 10, EOK, &test1->child);
    161187        }
    162188
     
    164190
    165191        return EOK;
     192}
     193
     194static int fun_remove(ddf_fun_t *fun, const char *name)
     195{
     196        int rc;
     197
     198        ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name);
     199        rc = ddf_fun_offline(fun);
     200        if (rc != EOK) {
     201                ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name);
     202                return rc;
     203        }
     204
     205        rc = ddf_fun_unbind(fun);
     206        if (rc != EOK) {
     207                ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
     208                return rc;
     209        }
     210
     211        ddf_fun_destroy(fun);
     212        return EOK;
     213}
     214
     215static int test1_dev_remove(ddf_dev_t *dev)
     216{
     217        test1_t *test1 = (test1_t *)dev->driver_data;
     218        int rc;
     219
     220        ddf_msg(LVL_DEBUG, "test1_dev_remove(%p)", dev);
     221
     222        if (test1->fun_a != NULL) {
     223                rc = fun_remove(test1->fun_a, "a");
     224                if (rc != EOK)
     225                        return rc;
     226        }
     227
     228        if (test1->clone != NULL) {
     229                rc = fun_remove(test1->clone, "clone");
     230                if (rc != EOK)
     231                        return rc;
     232        }
     233
     234        if (test1->child != NULL) {
     235                rc = fun_remove(test1->child, "child");
     236                if (rc != EOK)
     237                        return rc;
     238        }
     239
     240        return EOK;
     241}
     242
     243static int test1_fun_online(ddf_fun_t *fun)
     244{
     245        ddf_msg(LVL_DEBUG, "test1_fun_online()");
     246        return ddf_fun_online(fun);
     247}
     248
     249static int test1_fun_offline(ddf_fun_t *fun)
     250{
     251        ddf_msg(LVL_DEBUG, "test1_fun_offline()");
     252        return ddf_fun_offline(fun);
    166253}
    167254
Note: See TracChangeset for help on using the changeset viewer.