Changeset c05642d in mainline for uspace/drv/test/test3/test3.c


Ignore:
Timestamp:
2011-09-07T00:03:26Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5081276
Parents:
bb74dabe (diff), 038b289 (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/test/test3/test3.c

    rbb74dabe rc05642d  
    3939#define NAME "test3"
    4040
     41#define NUM_FUNCS 20
     42
    4143static int test3_add_device(ddf_dev_t *dev);
     44static int test3_dev_remove(ddf_dev_t *dev);
     45static int test3_fun_online(ddf_fun_t *fun);
     46static int test3_fun_offline(ddf_fun_t *fun);
    4247
    4348static driver_ops_t driver_ops = {
    44         .add_device = &test3_add_device
     49        .add_device = &test3_add_device,
     50        .dev_remove = &test3_dev_remove,
     51        .fun_online = &test3_fun_online,
     52        .fun_offline = &test3_fun_offline,
    4553};
    4654
     
    5058};
    5159
     60typedef struct {
     61        ddf_dev_t *dev;
     62        ddf_fun_t *fun[NUM_FUNCS];
     63} test3_t;
     64
    5265static int register_fun_and_add_to_category(ddf_dev_t *parent,
    53      const char *base_name, size_t index, const char *class_name)
     66    const char *base_name, size_t index, const char *class_name,
     67    ddf_fun_t **pfun)
    5468{
    5569        ddf_fun_t *fun = NULL;
     
    88102        }
    89103       
     104        *pfun = fun;
    90105        return rc;
     106}
     107
     108static int fun_remove(ddf_fun_t *fun, const char *name)
     109{
     110        int rc;
     111
     112        ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name);
     113        rc = ddf_fun_offline(fun);
     114        if (rc != EOK) {
     115                ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name);
     116                return rc;
     117        }
     118
     119        rc = ddf_fun_unbind(fun);
     120        if (rc != EOK) {
     121                ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
     122                return rc;
     123        }
     124
     125        ddf_fun_destroy(fun);
     126        return EOK;
    91127}
    92128
     
    94130{
    95131        int rc = EOK;
     132        test3_t *test3;
    96133
    97134        ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
    98135            dev->name, (int) dev->handle);
    99136
     137        test3 = ddf_dev_data_alloc(dev, sizeof(test3_t));
     138        if (test3 == NULL) {
     139                ddf_msg(LVL_ERROR, "Failed allocating soft state.");
     140                return ENOMEM;
     141        }
     142
    100143        size_t i;
    101         for (i = 0; i < 20; i++) {
     144        for (i = 0; i < NUM_FUNCS; i++) {
    102145                rc = register_fun_and_add_to_category(dev,
    103                     "test3_", i, "test3");
     146                    "test3_", i, "test3", &test3->fun[i]);
    104147                if (rc != EOK) {
    105148                        break;
     
    110153}
    111154
     155static int test3_dev_remove(ddf_dev_t *dev)
     156{
     157        test3_t *test3 = (test3_t *)dev->driver_data;
     158        char *fun_name;
     159        int rc;
     160        size_t i;
     161
     162        for (i = 0; i < NUM_FUNCS; i++) {
     163                rc = asprintf(&fun_name, "test3_%zu", i);
     164                if (rc < 0) {
     165                        ddf_msg(LVL_ERROR, "Failed to format string: %s", str_error(rc));
     166                        return ENOMEM;
     167                }
     168
     169                rc = fun_remove(test3->fun[i], fun_name);
     170                if (rc != EOK)
     171                        return rc;
     172
     173                free(fun_name);
     174        }
     175
     176        return EOK;
     177}
     178
     179static int test3_fun_online(ddf_fun_t *fun)
     180{
     181        ddf_msg(LVL_DEBUG, "test3_fun_online()");
     182        return ddf_fun_online(fun);
     183}
     184
     185static int test3_fun_offline(ddf_fun_t *fun)
     186{
     187        ddf_msg(LVL_DEBUG, "test3_fun_offline()");
     188        return ddf_fun_offline(fun);
     189}
     190
     191
    112192int main(int argc, char *argv[])
    113193{
Note: See TracChangeset for help on using the changeset viewer.