Use `errno_t` in all uspace and kernel code.
[helenos.git] / uspace / drv / char / ski-con / main.c
blob092a908558c2fa71080c22e2fbc9a0cdf0454263
1 /*
2 * Copyright (c) 2017 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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.
29 /** @addtogroup genarch
30 * @{
32 /** @file Ski console driver
35 #include <ddf/driver.h>
36 #include <ddf/log.h>
37 #include <errno.h>
38 #include <stdio.h>
40 #include "ski-con.h"
42 #define NAME "ski-con"
44 static errno_t ski_con_dev_add(ddf_dev_t *dev);
45 static errno_t ski_con_dev_remove(ddf_dev_t *dev);
46 static errno_t ski_con_dev_gone(ddf_dev_t *dev);
47 static errno_t ski_con_fun_online(ddf_fun_t *fun);
48 static errno_t ski_con_fun_offline(ddf_fun_t *fun);
50 static driver_ops_t driver_ops = {
51 .dev_add = ski_con_dev_add,
52 .dev_remove = ski_con_dev_remove,
53 .dev_gone = ski_con_dev_gone,
54 .fun_online = ski_con_fun_online,
55 .fun_offline = ski_con_fun_offline
58 static driver_t ski_con_driver = {
59 .name = NAME,
60 .driver_ops = &driver_ops
63 static errno_t ski_con_dev_add(ddf_dev_t *dev)
65 ski_con_t *ski_con;
67 ddf_msg(LVL_DEBUG, "ski_con_dev_add(%p)", dev);
68 ski_con = ddf_dev_data_alloc(dev, sizeof(ski_con_t));
69 if (ski_con == NULL) {
70 ddf_msg(LVL_ERROR, "Failed allocating soft state.");
71 return ENOMEM;
74 ski_con->dev = dev;
76 return ski_con_add(ski_con);
79 static errno_t ski_con_dev_remove(ddf_dev_t *dev)
81 ski_con_t *ski_con = (ski_con_t *)ddf_dev_data_get(dev);
83 ddf_msg(LVL_DEBUG, "ski_con_dev_remove(%p)", dev);
85 return ski_con_remove(ski_con);
88 static errno_t ski_con_dev_gone(ddf_dev_t *dev)
90 ski_con_t *ski_con = (ski_con_t *)ddf_dev_data_get(dev);
92 ddf_msg(LVL_DEBUG, "ski_con_dev_gone(%p)", dev);
94 return ski_con_gone(ski_con);
97 static errno_t ski_con_fun_online(ddf_fun_t *fun)
99 ddf_msg(LVL_DEBUG, "ski_con_fun_online()");
100 return ddf_fun_online(fun);
103 static errno_t ski_con_fun_offline(ddf_fun_t *fun)
105 ddf_msg(LVL_DEBUG, "ski_con_fun_offline()");
106 return ddf_fun_offline(fun);
109 int main(int argc, char *argv[])
111 printf(NAME ": Ski console driver\n");
112 ddf_log_init(NAME);
113 return ddf_driver_main(&ski_con_driver);
116 /** @}