Changeset 1a5b252 in mainline for uspace/drv/test/test1/test1.c
- Timestamp:
- 2011-08-21T11:54:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8cc4ddb
- Parents:
- e64df9a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test/test1/test1.c
re64df9a r1a5b252 1 1 /* 2 2 * Copyright (c) 2010 Vojtech Horky 3 * Copyright (c) 2011 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 40 41 41 42 static int test1_add_device(ddf_dev_t *dev); 43 static int test1_dev_remove(ddf_dev_t *dev); 44 static int test1_fun_online(ddf_fun_t *fun); 45 static int test1_fun_offline(ddf_fun_t *fun); 42 46 43 47 static driver_ops_t driver_ops = { 44 .add_device = &test1_add_device 48 .add_device = &test1_add_device, 49 .dev_remove = &test1_dev_remove, 50 .fun_online = &test1_fun_online, 51 .fun_offline = &test1_fun_offline 45 52 }; 46 53 … … 49 56 .driver_ops = &driver_ops 50 57 }; 58 59 typedef struct { 60 ddf_fun_t *fun_a; 61 ddf_fun_t *clone; 62 ddf_fun_t *child; 63 } test1_t; 51 64 52 65 /** Register child and inform user about it. … … 60 73 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 61 74 const char *name, const char *match_id, int match_score, 62 int expected_rc )75 int expected_rc, ddf_fun_t **pfun) 63 76 { 64 77 ddf_fun_t *fun = NULL; … … 103 116 } 104 117 118 if (pfun != NULL) 119 *pfun = fun; 120 105 121 return rc; 106 122 } … … 126 142 { 127 143 ddf_fun_t *fun_a; 144 test1_t *test1; 128 145 int rc; 129 146 130 147 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 131 148 dev->name, (int) dev->handle); 149 150 test1 = calloc(1, sizeof(test1_t)); 151 if (test1 == NULL) { 152 ddf_msg(LVL_ERROR, "Failed allocating softstate.\n"); 153 return ENOMEM; 154 } 132 155 133 156 fun_a = ddf_fun_create(dev, fun_exposed, "a"); … … 140 163 if (rc != EOK) { 141 164 ddf_msg(LVL_ERROR, "Failed binding function 'a'."); 165 ddf_fun_destroy(fun_a); 142 166 return rc; 143 167 } … … 151 175 (void) register_fun_verbose(dev, 152 176 "cloning myself ;-)", "clone", 153 "virtual&test1", 10, EOK );177 "virtual&test1", 10, EOK, &test1->clone); 154 178 (void) register_fun_verbose(dev, 155 179 "cloning myself twice ;-)", "clone", 156 "virtual&test1", 10, EEXISTS );180 "virtual&test1", 10, EEXISTS, NULL); 157 181 } else if (str_cmp(dev->name, "clone") == 0) { 158 182 (void) register_fun_verbose(dev, 159 183 "run by the same task", "child", 160 "virtual&test1&child", 10, EOK );184 "virtual&test1&child", 10, EOK, &test1->child); 161 185 } 162 186 163 187 ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name); 164 188 189 test1->fun_a = fun_a; 190 dev->driver_data = test1; 165 191 return EOK; 192 } 193 194 static int fun_remove(ddf_fun_t *fun, const char *name) 195 { 196 int rc; 197 198 ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')\n", fun, name); 199 rc = ddf_fun_offline(fun); 200 if (rc != EOK) { 201 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name); 202 return rc; 203 } 204 205 rc = ddf_fun_unbind(fun); 206 if (rc != EOK) { 207 ddf_msg(LVL_ERROR, "Failed offlining function '%s'.", name); 208 return rc; 209 } 210 211 ddf_fun_destroy(fun); 212 return EOK; 213 } 214 215 static int test1_dev_remove(ddf_dev_t *dev) 216 { 217 test1_t *test1 = (test1_t *)dev->driver_data; 218 int rc; 219 220 ddf_msg(LVL_DEBUG, "test1_dev_remove(%p)", dev); 221 222 if (test1->fun_a != NULL) { 223 rc = fun_remove(test1->fun_a, "a"); 224 if (rc != EOK) 225 return rc; 226 } 227 228 if (test1->clone != NULL) { 229 rc = fun_remove(test1->clone, "clone"); 230 if (rc != EOK) 231 return rc; 232 } 233 234 if (test1->child != NULL) { 235 rc = fun_remove(test1->child, "child"); 236 if (rc != EOK) 237 return rc; 238 } 239 240 return EOK; 241 } 242 243 static int test1_fun_online(ddf_fun_t *fun) 244 { 245 ddf_msg(LVL_DEBUG, "test1_fun_online()"); 246 return ddf_fun_online(fun); 247 } 248 249 static int test1_fun_offline(ddf_fun_t *fun) 250 { 251 ddf_msg(LVL_DEBUG, "test1_fun_offline()"); 252 return ddf_fun_offline(fun); 166 253 } 167 254
Note:
See TracChangeset
for help on using the changeset viewer.