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 libipcgfx
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file GFX IPC server
|
---|
34 | *
|
---|
35 | * Serve a graphics context via HelenOS IPC.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <errno.h>
|
---|
39 | #include <gfx/color.h>
|
---|
40 | #include <gfx/render.h>
|
---|
41 | #include <ipc/bd.h>
|
---|
42 | #include <ipcgfx/ipc/gc.h>
|
---|
43 | #include <ipcgfx/server.h>
|
---|
44 | #include <stdint.h>
|
---|
45 |
|
---|
46 | #include <stdio.h>
|
---|
47 |
|
---|
48 | #include <bd_srv.h>
|
---|
49 |
|
---|
50 | static void gc_set_rgb_color_srv(gfx_context_t *gc, ipc_call_t *call)
|
---|
51 | {
|
---|
52 | uint16_t r, g, b;
|
---|
53 | gfx_color_t *color;
|
---|
54 | errno_t rc;
|
---|
55 |
|
---|
56 | r = ipc_get_arg1(call);
|
---|
57 | g = ipc_get_arg2(call);
|
---|
58 | b = ipc_get_arg3(call);
|
---|
59 |
|
---|
60 | rc = gfx_color_new_rgb_i16(r, g, b, &color);
|
---|
61 | if (rc != EOK) {
|
---|
62 | async_answer_0(call, ENOMEM);
|
---|
63 | return;
|
---|
64 | }
|
---|
65 |
|
---|
66 | rc = gfx_set_color(gc, color);
|
---|
67 | async_answer_0(call, rc);
|
---|
68 | printf("done with rgb_color_srv\n");
|
---|
69 | }
|
---|
70 |
|
---|
71 | static void gc_fill_rect_srv(gfx_context_t *gc, ipc_call_t *call)
|
---|
72 | {
|
---|
73 | gfx_rect_t rect;
|
---|
74 | errno_t rc;
|
---|
75 |
|
---|
76 | rect.p0.x = ipc_get_arg1(call);
|
---|
77 | rect.p0.y = ipc_get_arg2(call);
|
---|
78 | rect.p1.x = ipc_get_arg3(call);
|
---|
79 | rect.p1.y = ipc_get_arg4(call);
|
---|
80 |
|
---|
81 | rc = gfx_fill_rect(gc, &rect);
|
---|
82 | async_answer_0(call, rc);
|
---|
83 | }
|
---|
84 |
|
---|
85 | errno_t gc_conn(ipc_call_t *icall, gfx_context_t *gc)
|
---|
86 | {
|
---|
87 | /* Accept the connection */
|
---|
88 | async_accept_0(icall);
|
---|
89 |
|
---|
90 | printf("gc_conn: accepted connection\n");
|
---|
91 |
|
---|
92 | while (true) {
|
---|
93 | ipc_call_t call;
|
---|
94 | async_get_call(&call);
|
---|
95 | sysarg_t method = ipc_get_imethod(&call);
|
---|
96 |
|
---|
97 | if (!method) {
|
---|
98 | /* The other side has hung up */
|
---|
99 | async_answer_0(&call, EOK);
|
---|
100 | break;
|
---|
101 | }
|
---|
102 |
|
---|
103 | switch (method) {
|
---|
104 | case GC_SET_RGB_COLOR:
|
---|
105 | printf("gc_conn: set_rgb_color\n");
|
---|
106 | gc_set_rgb_color_srv(gc, &call);
|
---|
107 | printf("gc_conn: done set_rgb_color\n");
|
---|
108 | break;
|
---|
109 | case GC_FILL_RECT:
|
---|
110 | printf("gc_conn: fill_rect_srv\n");
|
---|
111 | gc_fill_rect_srv(gc, &call);
|
---|
112 | printf("gc_conn: done fill_rect_srv\n");
|
---|
113 | break;
|
---|
114 | default:
|
---|
115 | printf("gc_conn: answer einval\n");
|
---|
116 | async_answer_0(&call, EINVAL);
|
---|
117 | printf("gc_conn: done answer einval\n");
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | return EOK;
|
---|
122 | }
|
---|
123 |
|
---|
124 | /** @}
|
---|
125 | */
|
---|