Changes in uspace/drv/test2/test2.c [af6b5157:9f6c5ef0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test2/test2.c
raf6b5157 r9f6c5ef0 31 31 32 32 #include <assert.h> 33 #include <async.h>34 33 #include <stdio.h> 35 34 #include <errno.h> 36 35 #include <str_error.h> 37 #include <d df/driver.h>36 #include <driver.h> 38 37 39 38 #define NAME "test2" 40 39 41 static int test2_add_device(ddf_dev_t *dev);40 static int add_device(device_t *dev); 42 41 43 42 static driver_ops_t driver_ops = { 44 .add_device = & test2_add_device43 .add_device = &add_device 45 44 }; 46 45 47 static driver_t t est2_driver = {46 static driver_t the_driver = { 48 47 .name = NAME, 49 48 .driver_ops = &driver_ops … … 58 57 * @param score Device match score. 59 58 */ 60 static int register_fun_verbose(ddf_dev_t *parent, const char *message,59 static void register_child_verbose(device_t *parent, const char *message, 61 60 const char *name, const char *match_id, int match_score) 62 61 { 63 ddf_fun_t *fun;64 int rc;62 printf(NAME ": registering child device `%s': %s.\n", 63 name, message); 65 64 66 printf(NAME ": registering function `%s': %s.\n", name, message); 65 int rc = child_device_register_wrapper(parent, name, 66 match_id, match_score, NULL); 67 67 68 fun = ddf_fun_create(parent, fun_inner, name); 69 if (fun == NULL) { 70 printf(NAME ": error creating function %s\n", name); 71 return ENOMEM; 68 if (rc == EOK) { 69 printf(NAME ": registered child device `%s'.\n", name); 70 } else { 71 printf(NAME ": failed to register child `%s' (%s).\n", 72 name, str_error(rc)); 72 73 } 73 74 rc = ddf_fun_add_match_id(fun, match_id, match_score);75 if (rc != EOK) {76 printf(NAME ": error adding match IDs to function %s\n", name);77 ddf_fun_destroy(fun);78 return rc;79 }80 81 rc = ddf_fun_bind(fun);82 if (rc != EOK) {83 printf(NAME ": error binding function %s: %s\n", name,84 str_error(rc));85 ddf_fun_destroy(fun);86 return rc;87 }88 89 printf(NAME ": registered child device `%s'\n", name);90 return EOK;91 74 } 92 75 93 76 /** Add child devices after some sleep. 94 77 * 95 * @param arg Parent device structure (d df_dev_t *).78 * @param arg Parent device structure (device_t *). 96 79 * @return Always EOK. 97 80 */ 98 81 static int postponed_birth(void *arg) 99 82 { 100 ddf_dev_t *dev = (ddf_dev_t *) arg; 101 ddf_fun_t *fun_a; 102 int rc; 83 device_t *dev = (device_t *) arg; 103 84 104 85 async_usleep(1000); 105 86 106 (void) register_fun_verbose(dev, "child driven by the same task",87 register_child_verbose(dev, "child driven by the same task", 107 88 "child", "virtual&test2", 10); 108 (void) register_fun_verbose(dev, "child driven by test1",89 register_child_verbose(dev, "child driven by test1", 109 90 "test1", "virtual&test1", 10); 110 91 111 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 112 if (fun_a == NULL) { 113 printf(NAME ": error creating function 'a'.\n"); 114 return ENOMEM; 115 } 116 117 rc = ddf_fun_bind(fun_a); 118 if (rc != EOK) { 119 printf(NAME ": error binding function 'a'.\n"); 120 return rc; 121 } 122 123 ddf_fun_add_to_class(fun_a, "virtual"); 92 add_device_to_class(dev, "virtual"); 124 93 125 94 return EOK; 126 95 } 127 96 128 static int test2_add_device(ddf_dev_t *dev) 97 98 static int add_device(device_t *dev) 129 99 { 130 printf(NAME ": test2_add_device(name=\"%s\", handle=%d)\n",100 printf(NAME ": add_device(name=\"%s\", handle=%d)\n", 131 101 dev->name, (int) dev->handle); 132 102 133 if ( str_cmp(dev->name, "child") != 0) {103 if (dev->parent == NULL) { 134 104 fid_t postpone = fibril_create(postponed_birth, dev); 135 if (postpone == 0) {136 printf(NAME ": fibril_create() error\n");137 return ENOMEM;138 }139 105 fibril_add_ready(postpone); 140 106 } else { 141 (void) register_fun_verbose(dev, "child without available driver",107 register_child_verbose(dev, "child without available driver", 142 108 "ERROR", "non-existent.match.id", 10); 143 109 } … … 149 115 { 150 116 printf(NAME ": HelenOS test2 virtual device driver\n"); 151 return d df_driver_main(&test2_driver);117 return driver_main(&the_driver); 152 118 } 153 119
Note:
See TracChangeset
for help on using the changeset viewer.