[6d15572] | 1 | /*
|
---|
| 2 | * Copyright (c) 2017 Jiri Svoboda
|
---|
| 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 |
|
---|
[6404aca] | 29 | /** @addtogroup uspace_drv_ski_con
|
---|
[6d15572] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file Ski console driver
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <ddf/driver.h>
|
---|
| 36 | #include <ddf/log.h>
|
---|
| 37 | #include <errno.h>
|
---|
| 38 | #include <stdio.h>
|
---|
| 39 |
|
---|
| 40 | #include "ski-con.h"
|
---|
| 41 |
|
---|
| 42 | #define NAME "ski-con"
|
---|
| 43 |
|
---|
[b7fd2a0] | 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);
|
---|
[6d15572] | 49 |
|
---|
| 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
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | static driver_t ski_con_driver = {
|
---|
| 59 | .name = NAME,
|
---|
| 60 | .driver_ops = &driver_ops
|
---|
| 61 | };
|
---|
| 62 |
|
---|
[b7fd2a0] | 63 | static errno_t ski_con_dev_add(ddf_dev_t *dev)
|
---|
[6d15572] | 64 | {
|
---|
| 65 | ski_con_t *ski_con;
|
---|
| 66 |
|
---|
[1433ecda] | 67 | ddf_msg(LVL_DEBUG, "ski_con_dev_add(%p)", dev);
|
---|
[6d15572] | 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;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | ski_con->dev = dev;
|
---|
| 75 |
|
---|
| 76 | return ski_con_add(ski_con);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[b7fd2a0] | 79 | static errno_t ski_con_dev_remove(ddf_dev_t *dev)
|
---|
[6d15572] | 80 | {
|
---|
[1433ecda] | 81 | ski_con_t *ski_con = (ski_con_t *)ddf_dev_data_get(dev);
|
---|
[6d15572] | 82 |
|
---|
[1433ecda] | 83 | ddf_msg(LVL_DEBUG, "ski_con_dev_remove(%p)", dev);
|
---|
[6d15572] | 84 |
|
---|
[1433ecda] | 85 | return ski_con_remove(ski_con);
|
---|
[6d15572] | 86 | }
|
---|
| 87 |
|
---|
[b7fd2a0] | 88 | static errno_t ski_con_dev_gone(ddf_dev_t *dev)
|
---|
[6d15572] | 89 | {
|
---|
[1433ecda] | 90 | ski_con_t *ski_con = (ski_con_t *)ddf_dev_data_get(dev);
|
---|
[6d15572] | 91 |
|
---|
[1433ecda] | 92 | ddf_msg(LVL_DEBUG, "ski_con_dev_gone(%p)", dev);
|
---|
[6d15572] | 93 |
|
---|
[1433ecda] | 94 | return ski_con_gone(ski_con);
|
---|
[6d15572] | 95 | }
|
---|
| 96 |
|
---|
[b7fd2a0] | 97 | static errno_t ski_con_fun_online(ddf_fun_t *fun)
|
---|
[6d15572] | 98 | {
|
---|
[1433ecda] | 99 | ddf_msg(LVL_DEBUG, "ski_con_fun_online()");
|
---|
| 100 | return ddf_fun_online(fun);
|
---|
[6d15572] | 101 | }
|
---|
| 102 |
|
---|
[b7fd2a0] | 103 | static errno_t ski_con_fun_offline(ddf_fun_t *fun)
|
---|
[6d15572] | 104 | {
|
---|
[1433ecda] | 105 | ddf_msg(LVL_DEBUG, "ski_con_fun_offline()");
|
---|
| 106 | return ddf_fun_offline(fun);
|
---|
[6d15572] | 107 | }
|
---|
| 108 |
|
---|
| 109 | int main(int argc, char *argv[])
|
---|
| 110 | {
|
---|
| 111 | printf(NAME ": Ski console driver\n");
|
---|
| 112 | ddf_log_init(NAME);
|
---|
| 113 | return ddf_driver_main(&ski_con_driver);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | /** @}
|
---|
| 117 | */
|
---|