41
static int test1_add_device(ddf_dev_t *dev);
42
static int test1_dev_add(ddf_dev_t *dev);
43
static int test1_dev_remove(ddf_dev_t *dev);
44
static int test1_dev_gone(ddf_dev_t *dev);
45
static int test1_fun_online(ddf_fun_t *fun);
46
static int test1_fun_offline(ddf_fun_t *fun);
43
48
static driver_ops_t driver_ops = {
44
.add_device = &test1_add_device
49
.dev_add = &test1_dev_add,
50
.dev_remove = &test1_dev_remove,
51
.dev_gone = &test1_dev_gone,
52
.fun_online = &test1_fun_online,
53
.fun_offline = &test1_fun_offline
47
56
static driver_t test1_driver = {
122
140
* @param dev New device.
123
141
* @return Error code reporting success of the operation.
125
static int test1_add_device(ddf_dev_t *dev)
143
static int test1_dev_add(ddf_dev_t *dev)
127
145
ddf_fun_t *fun_a;
130
ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
149
ddf_msg(LVL_DEBUG, "dev_add(name=\"%s\", handle=%d)",
131
150
dev->name, (int) dev->handle);
152
test1 = ddf_dev_data_alloc(dev, sizeof(test1_t));
154
ddf_msg(LVL_ERROR, "Failed allocating soft state.\n");
133
158
fun_a = ddf_fun_create(dev, fun_exposed, "a");
134
159
if (fun_a == NULL) {
135
160
ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
164
test1->fun_a = fun_a;
139
166
rc = ddf_fun_bind(fun_a);
141
168
ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
169
ddf_fun_destroy(fun_a);
150
178
} else if (str_cmp(dev->name, "test1") == 0) {
151
179
(void) register_fun_verbose(dev,
152
180
"cloning myself ;-)", "clone",
153
"virtual&test1", 10, EOK);
181
"virtual&test1", 10, EOK, &test1->clone);
154
182
(void) register_fun_verbose(dev,
155
183
"cloning myself twice ;-)", "clone",
156
"virtual&test1", 10, EEXISTS);
184
"virtual&test1", 10, EEXISTS, NULL);
157
185
} else if (str_cmp(dev->name, "clone") == 0) {
158
186
(void) register_fun_verbose(dev,
159
187
"run by the same task", "child",
160
"virtual&test1&child", 10, EOK);
188
"virtual&test1&child", 10, EOK, &test1->child);
163
191
ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name);
196
static int fun_remove(ddf_fun_t *fun, const char *name)
200
ddf_msg(LVL_DEBUG, "fun_remove(%p, '%s')", fun, name);
201
rc = ddf_fun_offline(fun);
203
ddf_msg(LVL_ERROR, "Error offlining function '%s'.", name);
207
rc = ddf_fun_unbind(fun);
209
ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
213
ddf_fun_destroy(fun);
217
static int fun_unbind(ddf_fun_t *fun, const char *name)
221
ddf_msg(LVL_DEBUG, "fun_unbind(%p, '%s')", fun, name);
222
rc = ddf_fun_unbind(fun);
224
ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", name);
228
ddf_fun_destroy(fun);
232
static int test1_dev_remove(ddf_dev_t *dev)
234
test1_t *test1 = (test1_t *)dev->driver_data;
237
ddf_msg(LVL_DEBUG, "test1_dev_remove(%p)", dev);
239
if (test1->fun_a != NULL) {
240
rc = fun_remove(test1->fun_a, "a");
245
if (test1->clone != NULL) {
246
rc = fun_remove(test1->clone, "clone");
251
if (test1->child != NULL) {
252
rc = fun_remove(test1->child, "child");
260
static int test1_dev_gone(ddf_dev_t *dev)
262
test1_t *test1 = (test1_t *)dev->driver_data;
265
ddf_msg(LVL_DEBUG, "test1_dev_remove(%p)", dev);
267
if (test1->fun_a != NULL) {
268
rc = fun_unbind(test1->fun_a, "a");
273
if (test1->clone != NULL) {
274
rc = fun_unbind(test1->clone, "clone");
279
if (test1->child != NULL) {
280
rc = fun_unbind(test1->child, "child");
288
static int test1_fun_online(ddf_fun_t *fun)
290
ddf_msg(LVL_DEBUG, "test1_fun_online()");
291
return ddf_fun_online(fun);
294
static int test1_fun_offline(ddf_fun_t *fun)
296
ddf_msg(LVL_DEBUG, "test1_fun_offline()");
297
return ddf_fun_offline(fun);
168
300
int main(int argc, char *argv[])
170
302
printf(NAME ": HelenOS test1 virtual device driver\n");