Ignore:
File:
1 edited

Legend:

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

    rdeac215e r1dc4a5e  
    3939#define NAME "test3"
    4040
    41 #define NUM_FUNCS 20
    42 
    4341static int test3_add_device(ddf_dev_t *dev);
    44 static int test3_dev_remove(ddf_dev_t *dev);
    45 static int test3_fun_online(ddf_fun_t *fun);
    46 static int test3_fun_offline(ddf_fun_t *fun);
    4742
    4843static driver_ops_t driver_ops = {
    49         .add_device = &test3_add_device,
    50         .dev_remove = &test3_dev_remove,
    51         .fun_online = &test3_fun_online,
    52         .fun_offline = &test3_fun_offline,
     44        .add_device = &test3_add_device
    5345};
    5446
     
    5850};
    5951
    60 typedef struct {
    61         ddf_dev_t *dev;
    62         ddf_fun_t *fun[NUM_FUNCS];
    63 } test3_t;
    64 
    6552static int register_fun_and_add_to_category(ddf_dev_t *parent,
    66     const char *base_name, size_t index, const char *class_name,
    67     ddf_fun_t **pfun)
     53     const char *base_name, size_t index, const char *class_name)
    6854{
    6955        ddf_fun_t *fun = NULL;
     
    10288        }
    10389       
    104         *pfun = fun;
    10590        return rc;
    106 }
    107 
    108 static 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;
    12791}
    12892
     
    13094{
    13195        int rc = EOK;
    132         test3_t *test3;
    13396
    13497        ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
    13598            dev->name, (int) dev->handle);
    13699
    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 
    143100        size_t i;
    144         for (i = 0; i < NUM_FUNCS; i++) {
     101        for (i = 0; i < 20; i++) {
    145102                rc = register_fun_and_add_to_category(dev,
    146                     "test3_", i, "test3", &test3->fun[i]);
     103                    "test3_", i, "test3");
    147104                if (rc != EOK) {
    148105                        break;
     
    153110}
    154111
    155 static 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 
    179 static 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 
    185 static 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 
    192112int main(int argc, char *argv[])
    193113{
Note: See TracChangeset for help on using the changeset viewer.