source: mainline/uspace/drv/test/test3/test3.c@ 1dc4a5e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1dc4a5e was 1dc4a5e, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Renaming to reflect classes are gone.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file
30 */
31
32#include <assert.h>
33#include <stdio.h>
34#include <errno.h>
35#include <str_error.h>
36#include <ddf/driver.h>
37#include <ddf/log.h>
38
39#define NAME "test3"
40
41static int test3_add_device(ddf_dev_t *dev);
42
43static driver_ops_t driver_ops = {
44 .add_device = &test3_add_device
45};
46
47static driver_t test3_driver = {
48 .name = NAME,
49 .driver_ops = &driver_ops
50};
51
52static int register_fun_and_add_to_category(ddf_dev_t *parent,
53 const char *base_name, size_t index, const char *class_name)
54{
55 ddf_fun_t *fun = NULL;
56 int rc;
57 char *fun_name = NULL;
58
59 rc = asprintf(&fun_name, "%s%zu", base_name, index);
60 if (rc < 0) {
61 ddf_msg(LVL_ERROR, "Failed to format string: %s", str_error(rc));
62 goto leave;
63 }
64
65 fun = ddf_fun_create(parent, fun_exposed, fun_name);
66 if (fun == NULL) {
67 ddf_msg(LVL_ERROR, "Failed creating function %s", fun_name);
68 rc = ENOMEM;
69 goto leave;
70 }
71
72 rc = ddf_fun_bind(fun);
73 if (rc != EOK) {
74 ddf_msg(LVL_ERROR, "Failed binding function %s: %s", fun_name,
75 str_error(rc));
76 goto leave;
77 }
78
79 ddf_fun_add_to_category(fun, class_name);
80
81 ddf_msg(LVL_NOTE, "Registered exposed function `%s'.", fun_name);
82
83leave:
84 free(fun_name);
85
86 if ((rc != EOK) && (fun != NULL)) {
87 ddf_fun_destroy(fun);
88 }
89
90 return rc;
91}
92
93static int test3_add_device(ddf_dev_t *dev)
94{
95 int rc = EOK;
96
97 ddf_msg(LVL_DEBUG, "add_device(name=\"%s\", handle=%d)",
98 dev->name, (int) dev->handle);
99
100 size_t i;
101 for (i = 0; i < 20; i++) {
102 rc = register_fun_and_add_to_category(dev,
103 "test3_", i, "test3");
104 if (rc != EOK) {
105 break;
106 }
107 }
108
109 return rc;
110}
111
112int main(int argc, char *argv[])
113{
114 printf(NAME ": HelenOS test3 virtual device driver\n");
115 ddf_log_init(NAME, LVL_ERROR);
116 return ddf_driver_main(&test3_driver);
117}
118
Note: See TracBrowser for help on using the repository browser.