Changeset b29bb09 in mainline for uspace/drv/test/test3/test3.c
- Timestamp:
- 2011-09-03T13:10:25Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- deac215e
- Parents:
- 7fff38c1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test/test3/test3.c
r7fff38c1 rb29bb09 39 39 #define NAME "test3" 40 40 41 #define NUM_FUNCS 20 42 41 43 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); 42 47 43 48 static 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, 45 53 }; 46 54 … … 50 58 }; 51 59 60 typedef struct { 61 ddf_dev_t *dev; 62 ddf_fun_t *fun[NUM_FUNCS]; 63 } test3_t; 64 52 65 static 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) 54 68 { 55 69 ddf_fun_t *fun = NULL; … … 88 102 } 89 103 104 *pfun = fun; 90 105 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')\n", 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; 91 127 } 92 128 … … 94 130 { 95 131 int rc = EOK; 132 test3_t *test3; 96 133 97 134 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 98 135 dev->name, (int) dev->handle); 99 136 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 100 143 size_t i; 101 for (i = 0; i < 20; i++) {144 for (i = 0; i < NUM_FUNCS; i++) { 102 145 rc = register_fun_and_add_to_category(dev, 103 "test3_", i, "test3" );146 "test3_", i, "test3", &test3->fun[i]); 104 147 if (rc != EOK) { 105 148 break; … … 110 153 } 111 154 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 112 192 int main(int argc, char *argv[]) 113 193 {
Note:
See TracChangeset
for help on using the changeset viewer.