[973efd36] | 1 | /*
|
---|
| 2 | * Copyright (c) 2019 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 |
|
---|
| 29 | /** @addtogroup libddev
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief Display protocol server stub
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <ddev_srv.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <io/log.h>
|
---|
| 40 | #include <ipc/ddev.h>
|
---|
| 41 | #include <mem.h>
|
---|
| 42 | #include <stdlib.h>
|
---|
| 43 | #include <stddef.h>
|
---|
| 44 |
|
---|
| 45 | #include <stdio.h>
|
---|
| 46 |
|
---|
[0b63dc2] | 47 | /** Connect to a GC.
|
---|
| 48 | *
|
---|
| 49 | * XXX As a workaround here we tell the client the values of arg2 and arg3
|
---|
| 50 | * needed to connect to the GC using async_connect_me_to(), these need
|
---|
| 51 | * to be provided by the ddev_ops_t.get_gc. Different values are needed
|
---|
| 52 | * for a DDF driver or a regular server. This would not be needed if we
|
---|
| 53 | * had a proper way of creating an endpoint and passing it to our client.
|
---|
| 54 | */
|
---|
| 55 | static void ddev_get_gc_srv(ddev_srv_t *srv, ipc_call_t *icall)
|
---|
| 56 | {
|
---|
| 57 | sysarg_t arg2;
|
---|
| 58 | sysarg_t arg3;
|
---|
| 59 | errno_t rc;
|
---|
| 60 |
|
---|
| 61 | printf("ddev_get_gc_srv\n");
|
---|
| 62 |
|
---|
| 63 | if (srv->ops->get_gc == NULL) {
|
---|
| 64 | async_answer_0(icall, ENOTSUP);
|
---|
| 65 | return;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | rc = srv->ops->get_gc(srv->arg, &arg2, &arg3);
|
---|
| 69 | async_answer_2(icall, rc, arg2, arg3);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[b252e87] | 72 | /** Get display device information */
|
---|
| 73 | static void ddev_get_info_srv(ddev_srv_t *srv, ipc_call_t *icall)
|
---|
| 74 | {
|
---|
| 75 | ddev_info_t info;
|
---|
| 76 | errno_t rc;
|
---|
| 77 |
|
---|
| 78 | printf("ddev_get_info_srv\n");
|
---|
| 79 |
|
---|
| 80 | ipc_call_t call;
|
---|
| 81 | size_t size;
|
---|
| 82 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 83 | async_answer_0(&call, EREFUSED);
|
---|
| 84 | async_answer_0(icall, EREFUSED);
|
---|
| 85 | return;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | if (size != sizeof(ddev_info_t)) {
|
---|
| 89 | async_answer_0(&call, EINVAL);
|
---|
| 90 | async_answer_0(icall, EINVAL);
|
---|
| 91 | return;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | if (srv->ops->get_info == NULL) {
|
---|
| 95 | printf("get_info is NULL -> ENOTSUP\n");
|
---|
| 96 | async_answer_0(&call, ENOTSUP);
|
---|
| 97 | async_answer_0(icall, ENOTSUP);
|
---|
| 98 | return;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | rc = srv->ops->get_info(srv->arg, &info);
|
---|
| 102 | if (rc != EOK) {
|
---|
| 103 | async_answer_0(&call, rc);
|
---|
| 104 | async_answer_0(icall, rc);
|
---|
| 105 | return;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | rc = async_data_read_finalize(&call, &info, sizeof(ddev_info_t));
|
---|
| 109 | if (rc != EOK) {
|
---|
| 110 | async_answer_0(icall, rc);
|
---|
| 111 | return;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | async_answer_0(icall, EOK);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[973efd36] | 117 | void ddev_conn(ipc_call_t *icall, ddev_srv_t *srv)
|
---|
| 118 | {
|
---|
| 119 | /* Accept the connection */
|
---|
| 120 | async_accept_0(icall);
|
---|
[0b63dc2] | 121 | printf("ddev_conn\n");
|
---|
[973efd36] | 122 |
|
---|
| 123 | while (true) {
|
---|
| 124 | ipc_call_t call;
|
---|
| 125 |
|
---|
| 126 | async_get_call(&call);
|
---|
| 127 | sysarg_t method = ipc_get_imethod(&call);
|
---|
| 128 |
|
---|
| 129 | if (!method) {
|
---|
| 130 | /* The other side has hung up */
|
---|
| 131 | async_answer_0(&call, EOK);
|
---|
| 132 | break;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | printf("display_conn method=%u\n", (unsigned) method);
|
---|
| 136 | switch (method) {
|
---|
| 137 | case DDEV_GET_GC:
|
---|
[0b63dc2] | 138 | ddev_get_gc_srv(srv, &call);
|
---|
| 139 | break;
|
---|
[b252e87] | 140 | case DDEV_GET_INFO:
|
---|
| 141 | ddev_get_info_srv(srv, &call);
|
---|
| 142 | break;
|
---|
[973efd36] | 143 | default:
|
---|
| 144 | async_answer_0(&call, ENOTSUP);
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /* Hang up callback session */
|
---|
| 149 | if (srv->client_sess != NULL) {
|
---|
| 150 | async_hangup(srv->client_sess);
|
---|
| 151 | srv->client_sess = NULL;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | /** Initialize display device server structure
|
---|
| 156 | *
|
---|
| 157 | * @param srv Display device server structure to initialize
|
---|
| 158 | */
|
---|
| 159 | void ddev_srv_initialize(ddev_srv_t *srv)
|
---|
| 160 | {
|
---|
| 161 | memset(srv, 0, sizeof(*srv));
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | /** @}
|
---|
| 165 | */
|
---|