Changeset b04967a in mainline for uspace/drv/test1/test1.c
- Timestamp:
- 2011-04-07T15:53:46Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c156c2d
- Parents:
- 64dbc83 (diff), a82889e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/test1/test1.c
r64dbc83 rb04967a 35 35 #include <str_error.h> 36 36 #include <ddf/driver.h> 37 #include <ddf/log.h> 37 38 38 39 #include "test1.h" … … 58 59 */ 59 60 static int register_fun_verbose(ddf_dev_t *parent, const char *message, 60 const char *name, const char *match_id, int match_score) 61 const char *name, const char *match_id, int match_score, 62 int expected_rc) 61 63 { 62 ddf_fun_t *fun ;64 ddf_fun_t *fun = NULL; 63 65 int rc; 64 66 65 printf(NAME ": registering function `%s': %s.\n", name, message);67 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message); 66 68 67 69 fun = ddf_fun_create(parent, fun_inner, name); 68 70 if (fun == NULL) { 69 printf(NAME ": error creating function %s\n", name); 70 return ENOMEM; 71 ddf_msg(LVL_ERROR, "Failed creating function %s", name); 72 rc = ENOMEM; 73 goto leave; 71 74 } 72 75 73 rc = ddf_fun_add_match_id(fun, match_id, match_score);76 rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score); 74 77 if (rc != EOK) { 75 printf(NAME ": error adding match IDs to function %s\n", name);76 ddf_fun_destroy(fun);77 return rc;78 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s", 79 name); 80 goto leave; 78 81 } 79 82 80 83 rc = ddf_fun_bind(fun); 81 84 if (rc != EOK) { 82 printf(NAME ": error binding function %s: %s\n", name,85 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name, 83 86 str_error(rc)); 84 ddf_fun_destroy(fun); 85 return rc; 87 goto leave; 86 88 } 87 89 88 printf(NAME ": registered child device `%s'\n", name); 89 return EOK; 90 ddf_msg(LVL_NOTE, "Registered child device `%s'", name); 91 rc = EOK; 92 93 leave: 94 if (rc != expected_rc) { 95 fprintf(stderr, 96 NAME ": Unexpected error registering function `%s'.\n" 97 NAME ": Expected \"%s\" but got \"%s\".\n", 98 name, str_error(expected_rc), str_error(rc)); 99 } 100 101 if ((rc != EOK) && (fun != NULL)) { 102 ddf_fun_destroy(fun); 103 } 104 105 return rc; 90 106 } 91 107 … … 112 128 int rc; 113 129 114 printf(NAME ": add_device(name=\"%s\", handle=%d)\n",130 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)", 115 131 dev->name, (int) dev->handle); 116 132 117 133 fun_a = ddf_fun_create(dev, fun_exposed, "a"); 118 134 if (fun_a == NULL) { 119 printf(NAME ": error creating function 'a'.\n");135 ddf_msg(LVL_ERROR, "Failed creating function 'a'."); 120 136 return ENOMEM; 121 137 } … … 123 139 rc = ddf_fun_bind(fun_a); 124 140 if (rc != EOK) { 125 printf(NAME ": error binding function 'a'.\n");141 ddf_msg(LVL_ERROR, "Failed binding function 'a'."); 126 142 return rc; 127 143 } … … 133 149 ddf_fun_add_to_class(fun_a, "virt-null"); 134 150 } else if (str_cmp(dev->name, "test1") == 0) { 135 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone", 136 "virtual&test1", 10); 151 (void) register_fun_verbose(dev, 152 "cloning myself ;-)", "clone", 153 "virtual&test1", 10, EOK); 154 (void) register_fun_verbose(dev, 155 "cloning myself twice ;-)", "clone", 156 "virtual&test1", 10, EEXISTS); 137 157 } else if (str_cmp(dev->name, "clone") == 0) { 138 (void) register_fun_verbose(dev, "run by the same task", "child", 139 "virtual&test1&child", 10); 158 (void) register_fun_verbose(dev, 159 "run by the same task", "child", 160 "virtual&test1&child", 10, EOK); 140 161 } 141 162 142 printf(NAME ": device `%s' accepted.\n", dev->name);163 ddf_msg(LVL_DEBUG, "Device `%s' accepted.", dev->name); 143 164 144 165 return EOK; … … 148 169 { 149 170 printf(NAME ": HelenOS test1 virtual device driver\n"); 171 ddf_log_init(NAME, LVL_ERROR); 150 172 return ddf_driver_main(&test1_driver); 151 173 }
Note:
See TracChangeset
for help on using the changeset viewer.