Changes in uspace/drv/test/test3/test3.c [deac215e:1dc4a5e] in mainline
- File:
-
- 1 edited
-
uspace/drv/test/test3/test3.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test/test3/test3.c
rdeac215e r1dc4a5e 39 39 #define NAME "test3" 40 40 41 #define NUM_FUNCS 2042 43 41 static 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);47 42 48 43 static 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 53 45 }; 54 46 … … 58 50 }; 59 51 60 typedef struct {61 ddf_dev_t *dev;62 ddf_fun_t *fun[NUM_FUNCS];63 } test3_t;64 65 52 static 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) 68 54 { 69 55 ddf_fun_t *fun = NULL; … … 102 88 } 103 89 104 *pfun = fun;105 90 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;127 91 } 128 92 … … 130 94 { 131 95 int rc = EOK; 132 test3_t *test3;133 96 134 97 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 135 98 dev->name, (int) dev->handle); 136 99 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 143 100 size_t i; 144 for (i = 0; i < NUM_FUNCS; i++) {101 for (i = 0; i < 20; i++) { 145 102 rc = register_fun_and_add_to_category(dev, 146 "test3_", i, "test3" , &test3->fun[i]);103 "test3_", i, "test3"); 147 104 if (rc != EOK) { 148 105 break; … … 153 110 } 154 111 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 192 112 int main(int argc, char *argv[]) 193 113 {
Note:
See TracChangeset
for help on using the changeset viewer.
