source: mainline/uspace/lib/ddev/src/ddev_srv.c@ aef48ce

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

Fix date and debug prints (thx Jakub)

  • Property mode set to 100644
File size: 4.0 KB
Line 
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/** Connect to a GC.
46 *
47 * XXX As a workaround here we tell the client the values of arg2 and arg3
48 * needed to connect to the GC using async_connect_me_to(), these need
49 * to be provided by the ddev_ops_t.get_gc. Different values are needed
50 * for a DDF driver or a regular server. This would not be needed if we
51 * had a proper way of creating an endpoint and passing it to our client.
52 */
53static void ddev_get_gc_srv(ddev_srv_t *srv, ipc_call_t *icall)
54{
55 sysarg_t arg2;
56 sysarg_t arg3;
57 errno_t rc;
58
59 if (srv->ops->get_gc == NULL) {
60 async_answer_0(icall, ENOTSUP);
61 return;
62 }
63
64 rc = srv->ops->get_gc(srv->arg, &arg2, &arg3);
65 async_answer_2(icall, rc, arg2, arg3);
66}
67
68/** Get display device information */
69static void ddev_get_info_srv(ddev_srv_t *srv, ipc_call_t *icall)
70{
71 ddev_info_t info;
72 errno_t rc;
73
74 ipc_call_t call;
75 size_t size;
76 if (!async_data_read_receive(&call, &size)) {
77 async_answer_0(&call, EREFUSED);
78 async_answer_0(icall, EREFUSED);
79 return;
80 }
81
82 if (size != sizeof(ddev_info_t)) {
83 async_answer_0(&call, EINVAL);
84 async_answer_0(icall, EINVAL);
85 return;
86 }
87
88 if (srv->ops->get_info == NULL) {
89 async_answer_0(&call, ENOTSUP);
90 async_answer_0(icall, ENOTSUP);
91 return;
92 }
93
94 rc = srv->ops->get_info(srv->arg, &info);
95 if (rc != EOK) {
96 async_answer_0(&call, rc);
97 async_answer_0(icall, rc);
98 return;
99 }
100
101 rc = async_data_read_finalize(&call, &info, sizeof(ddev_info_t));
102 if (rc != EOK) {
103 async_answer_0(icall, rc);
104 return;
105 }
106
107 async_answer_0(icall, EOK);
108}
109
110void ddev_conn(ipc_call_t *icall, ddev_srv_t *srv)
111{
112 /* Accept the connection */
113 async_accept_0(icall);
114
115 while (true) {
116 ipc_call_t call;
117
118 async_get_call(&call);
119 sysarg_t method = ipc_get_imethod(&call);
120
121 if (!method) {
122 /* The other side has hung up */
123 async_answer_0(&call, EOK);
124 break;
125 }
126
127 switch (method) {
128 case DDEV_GET_GC:
129 ddev_get_gc_srv(srv, &call);
130 break;
131 case DDEV_GET_INFO:
132 ddev_get_info_srv(srv, &call);
133 break;
134 default:
135 async_answer_0(&call, ENOTSUP);
136 }
137 }
138
139 /* Hang up callback session */
140 if (srv->client_sess != NULL) {
141 async_hangup(srv->client_sess);
142 srv->client_sess = NULL;
143 }
144}
145
146/** Initialize display device server structure
147 *
148 * @param srv Display device server structure to initialize
149 */
150void ddev_srv_initialize(ddev_srv_t *srv)
151{
152 memset(srv, 0, sizeof(*srv));
153}
154
155/** @}
156 */
Note: See TracBrowser for help on using the repository browser.