Changeset 8ff0bd2 in mainline for uspace/drv/test/test2/test2.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/test2/test2.c

    rd2c67e7 r8ff0bd2  
    4141
    4242static int test2_add_device(ddf_dev_t *dev);
     43static int test2_dev_remove(ddf_dev_t *dev);
     44static int test2_fun_online(ddf_fun_t *fun);
     45static int test2_fun_offline(ddf_fun_t *fun);
    4346
    4447static driver_ops_t driver_ops = {
    45         .add_device = &test2_add_device
     48        .add_device = &test2_add_device,
     49        .dev_remove = &test2_dev_remove,
     50        .fun_online = &test2_fun_online,
     51        .fun_offline = &test2_fun_offline
    4652};
    4753
     
    5056        .driver_ops = &driver_ops
    5157};
     58
     59/* Device soft state */
     60typedef struct {
     61        ddf_dev_t *dev;
     62
     63        ddf_fun_t *fun_a;
     64        ddf_fun_t *fun_err;
     65        ddf_fun_t *child;
     66        ddf_fun_t *test1;
     67} test2_t;
    5268
    5369/** Register child and inform user about it.
     
    6076 */
    6177static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    62     const char *name, const char *match_id, int match_score)
     78    const char *name, const char *match_id, int match_score, ddf_fun_t **pfun)
    6379{
    6480        ddf_fun_t *fun;
     
    89105        }
    90106
     107        *pfun = fun;
     108
    91109        ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
    92110        return EOK;
     
    100118static int postponed_birth(void *arg)
    101119{
    102         ddf_dev_t *dev = (ddf_dev_t *) arg;
     120        test2_t *test2 = (test2_t *) arg;
    103121        ddf_fun_t *fun_a;
    104122        int rc;
     
    106124        async_usleep(1000);
    107125
    108         (void) register_fun_verbose(dev, "child driven by the same task",
    109             "child", "virtual&test2", 10);
    110         (void) register_fun_verbose(dev, "child driven by test1",
    111             "test1", "virtual&test1", 10);
    112 
    113         fun_a = ddf_fun_create(dev, fun_exposed, "a");
     126        (void) register_fun_verbose(test2->dev, "child driven by the same task",
     127            "child", "virtual&test2", 10, &test2->child);
     128        (void) register_fun_verbose(test2->dev, "child driven by test1",
     129            "test1", "virtual&test1", 10, &test2->test1);
     130
     131        fun_a = ddf_fun_create(test2->dev, fun_exposed, "a");
    114132        if (fun_a == NULL) {
    115133                ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
     
    123141        }
    124142
    125         ddf_fun_add_to_class(fun_a, "virtual");
    126 
     143        ddf_fun_add_to_category(fun_a, "virtual");
     144        test2->fun_a = fun_a;
     145
     146        return EOK;
     147}
     148
     149static int fun_remove(ddf_fun_t *fun, const char *name)
     150{
     151        int rc;
     152
     153        ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name);
     154        rc = ddf_fun_offline(fun);
     155        if (rc != EOK) {
     156                ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name);
     157                return rc;
     158        }
     159
     160        rc = ddf_fun_unbind(fun);
     161        if (rc != EOK) {
     162                ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
     163                return rc;
     164        }
     165
     166        ddf_fun_destroy(fun);
    127167        return EOK;
    128168}
     
    130170static int test2_add_device(ddf_dev_t *dev)
    131171{
     172        test2_t *test2;
     173
    132174        ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",
    133175            dev->name, (int) dev->handle);
    134176
     177        test2 = ddf_dev_data_alloc(dev, sizeof(test2_t));
     178        if (test2 == NULL) {
     179                ddf_msg(LVL_ERROR, "Failed allocating soft state.");
     180                return ENOMEM;
     181        }
     182
     183        test2->dev = dev;
     184
    135185        if (str_cmp(dev->name, "child") != 0) {
    136                 fid_t postpone = fibril_create(postponed_birth, dev);
     186                fid_t postpone = fibril_create(postponed_birth, test2);
    137187                if (postpone == 0) {
    138188                        ddf_msg(LVL_ERROR, "fibril_create() failed.");
     
    142192        } else {
    143193                (void) register_fun_verbose(dev, "child without available driver",
    144                     "ERROR", "non-existent.match.id", 10);
    145         }
    146 
    147         return EOK;
     194                    "ERROR", "non-existent.match.id", 10, &test2->fun_err);
     195        }
     196
     197        return EOK;
     198}
     199
     200static int test2_dev_remove(ddf_dev_t *dev)
     201{
     202        test2_t *test2 = (test2_t *)dev->driver_data;
     203        int rc;
     204
     205        ddf_msg(LVL_DEBUG, "test2_dev_remove(%p)", dev);
     206
     207        if (test2->fun_a != NULL) {
     208                rc = fun_remove(test2->fun_a, "a");
     209                if (rc != EOK)
     210                        return rc;
     211        }
     212
     213        if (test2->fun_err != NULL) {
     214                rc = fun_remove(test2->fun_err, "ERROR");
     215                if (rc != EOK)
     216                        return rc;
     217        }
     218
     219        if (test2->child != NULL) {
     220                rc = fun_remove(test2->child, "child");
     221                if (rc != EOK)
     222                        return rc;
     223        }
     224
     225        if (test2->test1 != NULL) {
     226                rc = fun_remove(test2->test1, "test1");
     227                if (rc != EOK)
     228                        return rc;
     229        }
     230
     231        return EOK;
     232}
     233
     234
     235static int test2_fun_online(ddf_fun_t *fun)
     236{
     237        ddf_msg(LVL_DEBUG, "test2_fun_online()");
     238        return ddf_fun_online(fun);
     239}
     240
     241static int test2_fun_offline(ddf_fun_t *fun)
     242{
     243        ddf_msg(LVL_DEBUG, "test2_fun_offline()");
     244        return ddf_fun_offline(fun);
    148245}
    149246
Note: See TracChangeset for help on using the changeset viewer.