Changes in uspace/drv/test1/test1.c [fc51296:3fddb55] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test1/test1.c
rfc51296 r3fddb55 35 35 #include <str_error.h> 36 36 #include <ddf/driver.h> 37 #include <ddf/log.h>38 37 39 38 #include "test1.h" … … 59 58 */ 60 59 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 61 const char *name, const char *match_id, int match_score) 60 const char *name, const char *match_id, int match_score, 61 int expected_rc) 62 62 { 63 ddf_fun_t *fun ;63 ddf_fun_t *fun = NULL; 64 64 int rc; 65 65 66 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.\n", name, message);66 printf(NAME ": registering function `%s': %s.\n", name, message); 67 67 68 68 fun = ddf_fun_create(parent, fun_inner, name); 69 69 if (fun == NULL) { 70 ddf_msg(LVL_ERROR, "Failed creating function %s\n", name); 71 return ENOMEM; 70 printf(NAME ": error creating function %s\n", name); 71 rc = ENOMEM; 72 goto leave; 72 73 } 73 74 74 rc = ddf_fun_add_match_id(fun, match_id, match_score);75 rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score); 75 76 if (rc != EOK) { 76 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s\n", 77 name); 78 ddf_fun_destroy(fun); 79 return rc; 77 printf(NAME ": error adding match IDs to function %s\n", name); 78 goto leave; 80 79 } 81 80 82 81 rc = ddf_fun_bind(fun); 83 82 if (rc != EOK) { 84 ddf_msg(LVL_ERROR, "Failedbinding function %s: %s\n", name,83 printf(NAME ": error binding function %s: %s\n", name, 85 84 str_error(rc)); 86 ddf_fun_destroy(fun); 87 return rc; 85 goto leave; 88 86 } 89 87 90 ddf_msg(LVL_NOTE, "Registered child device `%s'\n", name); 91 return EOK; 88 printf(NAME ": registered child device `%s'\n", name); 89 rc = EOK; 90 91 92 leave: 93 if (rc != expected_rc) { 94 fprintf(stderr, 95 NAME ": Unexpected error registering function `%s'.\n" \ 96 NAME ": Expected \"%s\" but got \"%s\".\n", 97 name, str_error(expected_rc), str_error(rc)); 98 } 99 100 if ((rc != EOK) && (fun != NULL)) { 101 ddf_fun_destroy(fun); 102 } 103 104 return rc; 92 105 } 93 106 … … 114 127 int rc; 115 128 116 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)\n",129 printf(NAME ": add_device(name=\"%s\", handle=%d)\n", 117 130 dev->name, (int) dev->handle); 118 131 119 132 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 120 133 if (fun_a == NULL) { 121 ddf_msg(LVL_ERROR, "Failedcreating function 'a'.\n");134 printf(NAME ": error creating function 'a'.\n"); 122 135 return ENOMEM; 123 136 } … … 125 138 rc = ddf_fun_bind(fun_a); 126 139 if (rc != EOK) { 127 ddf_msg(LVL_ERROR, "Failedbinding function 'a'.\n");140 printf(NAME ": error binding function 'a'.\n"); 128 141 return rc; 129 142 } … … 135 148 ddf_fun_add_to_class(fun_a, "virt-null"); 136 149 } else if (str_cmp(dev->name, "test1") == 0) { 137 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone", 138 "virtual&test1", 10); 150 (void) register_fun_verbose(dev, 151 "cloning myself ;-)", "clone", 152 "virtual&test1", 10, EOK); 153 (void) register_fun_verbose(dev, 154 "cloning myself twice ;-)", "clone", 155 "virtual&test1", 10, EEXISTS); 139 156 } else if (str_cmp(dev->name, "clone") == 0) { 140 (void) register_fun_verbose(dev, "run by the same task", "child", 141 "virtual&test1&child", 10); 157 (void) register_fun_verbose(dev, 158 "run by the same task", "child", 159 "virtual&test1&child", 10, EOK); 142 160 } 143 161 144 ddf_msg(LVL_DEBUG, "Device `%s' accepted.\n", dev->name);162 printf(NAME ": device `%s' accepted.\n", dev->name); 145 163 146 164 return EOK; … … 150 168 { 151 169 printf(NAME ": HelenOS test1 virtual device driver\n"); 152 ddf_log_init(NAME, LVL_ERROR);153 170 return ddf_driver_main(&test1_driver); 154 171 }
Note:
See TracChangeset
for help on using the changeset viewer.