00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00032 #include <assert.h>
00033 #include <async.h>
00034 #include <stdio.h>
00035 #include <errno.h>
00036 #include <str_error.h>
00037 #include <ddf/driver.h>
00038 #include <ddf/log.h>
00039
00040 #define NAME "test2"
00041
00042 static int test2_add_device(ddf_dev_t *dev);
00043
00044 static driver_ops_t driver_ops = {
00045 .add_device = &test2_add_device
00046 };
00047
00048 static driver_t test2_driver = {
00049 .name = NAME,
00050 .driver_ops = &driver_ops
00051 };
00052
00061 static int register_fun_verbose(ddf_dev_t *parent, const char *message,
00062 const char *name, const char *match_id, int match_score)
00063 {
00064 ddf_fun_t *fun;
00065 int rc;
00066
00067 ddf_msg(LVL_DEBUG, "Registering function `%s': %s.", name, message);
00068
00069 fun = ddf_fun_create(parent, fun_inner, name);
00070 if (fun == NULL) {
00071 ddf_msg(LVL_ERROR, "Failed creating function %s", name);
00072 return ENOMEM;
00073 }
00074
00075 rc = ddf_fun_add_match_id(fun, match_id, match_score);
00076 if (rc != EOK) {
00077 ddf_msg(LVL_ERROR, "Failed adding match IDs to function %s",
00078 name);
00079 ddf_fun_destroy(fun);
00080 return rc;
00081 }
00082
00083 rc = ddf_fun_bind(fun);
00084 if (rc != EOK) {
00085 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", name,
00086 str_error(rc));
00087 ddf_fun_destroy(fun);
00088 return rc;
00089 }
00090
00091 ddf_msg(LVL_NOTE, "Registered child device `%s'", name);
00092 return EOK;
00093 }
00094
00100 static int postponed_birth(void *arg)
00101 {
00102 ddf_dev_t *dev = (ddf_dev_t *) arg;
00103 ddf_fun_t *fun_a;
00104 int rc;
00105
00106 async_usleep(1000);
00107
00108 (void) register_fun_verbose(dev, "child driven by the same task",
00109 "child", "virtual&test2", 10);
00110 (void) register_fun_verbose(dev, "child driven by test1",
00111 "test1", "virtual&test1", 10);
00112
00113 fun_a = ddf_fun_create(dev, fun_exposed, "a");
00114 if (fun_a == NULL) {
00115 ddf_msg(LVL_ERROR, "Failed creating function 'a'.");
00116 return ENOMEM;
00117 }
00118
00119 rc = ddf_fun_bind(fun_a);
00120 if (rc != EOK) {
00121 ddf_msg(LVL_ERROR, "Failed binding function 'a'.");
00122 return rc;
00123 }
00124
00125 ddf_fun_add_to_class(fun_a, "virtual");
00126
00127 return EOK;
00128 }
00129
00130 static int test2_add_device(ddf_dev_t *dev)
00131 {
00132 ddf_msg(LVL_DEBUG, "test2_add_device(name=\"%s\", handle=%d)",
00133 dev->name, (int) dev->handle);
00134
00135 if (str_cmp(dev->name, "child") != 0) {
00136 fid_t postpone = fibril_create(postponed_birth, dev);
00137 if (postpone == 0) {
00138 ddf_msg(LVL_ERROR, "fibril_create() failed.");
00139 return ENOMEM;
00140 }
00141 fibril_add_ready(postpone);
00142 } else {
00143 (void) register_fun_verbose(dev, "child without available driver",
00144 "ERROR", "non-existent.match.id", 10);
00145 }
00146
00147 return EOK;
00148 }
00149
00150 int main(int argc, char *argv[])
00151 {
00152 printf(NAME ": HelenOS test2 virtual device driver\n");
00153 ddf_log_init(NAME, LVL_ERROR);
00154 return ddf_driver_main(&test2_driver);
00155 }
00156
00157