1 | /*
|
---|
2 | * Copyright (c) 2023 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 display
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file Display configuration ops implementation
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <errno.h>
|
---|
37 | #include <io/log.h>
|
---|
38 | #include <stdlib.h>
|
---|
39 | #include <str.h>
|
---|
40 | #include <dispcfg_srv.h>
|
---|
41 | #include "display.h"
|
---|
42 | #include "seat.h"
|
---|
43 | #include "cfgclient.h"
|
---|
44 |
|
---|
45 | static errno_t dispc_get_seat_list(void *, dispcfg_seat_list_t **);
|
---|
46 | static errno_t dispc_get_seat_info(void *, sysarg_t, dispcfg_seat_info_t **);
|
---|
47 | static errno_t dispc_seat_create(void *, const char *, sysarg_t *);
|
---|
48 | static errno_t dispc_seat_delete(void *, sysarg_t);
|
---|
49 | static errno_t dispc_get_event(void *, dispcfg_ev_t *);
|
---|
50 |
|
---|
51 | dispcfg_ops_t dispcfg_srv_ops = {
|
---|
52 | .get_seat_list = dispc_get_seat_list,
|
---|
53 | .get_seat_info = dispc_get_seat_info,
|
---|
54 | .seat_create = dispc_seat_create,
|
---|
55 | .seat_delete = dispc_seat_delete,
|
---|
56 | .get_event = dispc_get_event,
|
---|
57 | };
|
---|
58 |
|
---|
59 | /** Get seat list.
|
---|
60 | *
|
---|
61 | * @param arg Argument (CFG client)
|
---|
62 | * @param rlist Place to store pointer to new list
|
---|
63 | * @return EOK on success or an error code
|
---|
64 | */
|
---|
65 | static errno_t dispc_get_seat_list(void *arg, dispcfg_seat_list_t **rlist)
|
---|
66 | {
|
---|
67 | ds_cfgclient_t *cfgclient = (ds_cfgclient_t *)arg;
|
---|
68 | dispcfg_seat_list_t *list;
|
---|
69 | ds_seat_t *seat;
|
---|
70 | unsigned i;
|
---|
71 |
|
---|
72 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispcfg_get_seat_list()");
|
---|
73 |
|
---|
74 | list = calloc(1, sizeof(dispcfg_seat_list_t));
|
---|
75 | if (list == NULL)
|
---|
76 | return ENOMEM;
|
---|
77 |
|
---|
78 | ds_display_lock(cfgclient->display);
|
---|
79 |
|
---|
80 | /* Count the number of seats */
|
---|
81 | list->nseats = 0;
|
---|
82 | seat = ds_display_first_seat(cfgclient->display);
|
---|
83 | while (seat != NULL) {
|
---|
84 | ++list->nseats;
|
---|
85 | seat = ds_display_next_seat(seat);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /* Allocate array for seat IDs */
|
---|
89 | list->seats = calloc(list->nseats, sizeof(sysarg_t));
|
---|
90 | if (list->seats == NULL) {
|
---|
91 | ds_display_unlock(cfgclient->display);
|
---|
92 | free(list);
|
---|
93 | return ENOMEM;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* Fill in seat IDs */
|
---|
97 | i = 0;
|
---|
98 | seat = ds_display_first_seat(cfgclient->display);
|
---|
99 | while (seat != NULL) {
|
---|
100 | list->seats[i++] = seat->id;
|
---|
101 | seat = ds_display_next_seat(seat);
|
---|
102 | }
|
---|
103 |
|
---|
104 | ds_display_unlock(cfgclient->display);
|
---|
105 | *rlist = list;
|
---|
106 | return EOK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /** Get seat information.
|
---|
110 | *
|
---|
111 | * @param arg Argument (CFG client)
|
---|
112 | * @param seat_id Seat ID
|
---|
113 | * @param rinfo Place to store pointer to new seat information structure
|
---|
114 | * @return EOK on success or an error code
|
---|
115 | */
|
---|
116 | static errno_t dispc_get_seat_info(void *arg, sysarg_t seat_id,
|
---|
117 | dispcfg_seat_info_t **rinfo)
|
---|
118 | {
|
---|
119 | ds_cfgclient_t *cfgclient = (ds_cfgclient_t *)arg;
|
---|
120 | ds_seat_t *seat;
|
---|
121 | dispcfg_seat_info_t *info;
|
---|
122 |
|
---|
123 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispcfg_get_seat_info()");
|
---|
124 |
|
---|
125 | ds_display_lock(cfgclient->display);
|
---|
126 | seat = ds_display_find_seat(cfgclient->display, seat_id);
|
---|
127 | if (seat == NULL) {
|
---|
128 | ds_display_unlock(cfgclient->display);
|
---|
129 | return ENOENT;
|
---|
130 | }
|
---|
131 |
|
---|
132 | info = calloc(1, sizeof(dispcfg_seat_info_t));
|
---|
133 | if (info == NULL) {
|
---|
134 | ds_display_unlock(cfgclient->display);
|
---|
135 | return ENOMEM;
|
---|
136 | }
|
---|
137 |
|
---|
138 | (void)seat;
|
---|
139 | info->name = str_dup(seat->name);
|
---|
140 | if (info->name == NULL) {
|
---|
141 | ds_display_unlock(cfgclient->display);
|
---|
142 | free(info);
|
---|
143 | return ENOMEM;
|
---|
144 | }
|
---|
145 |
|
---|
146 | ds_display_unlock(cfgclient->display);
|
---|
147 | *rinfo = info;
|
---|
148 | return EOK;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /** Create seat.
|
---|
152 | *
|
---|
153 | * @param arg Argument (CFG client)
|
---|
154 | * @param name Seat name
|
---|
155 | * @param rseat_id Place to store ID of the new seat
|
---|
156 | * @return EOK on success or an error code
|
---|
157 | */
|
---|
158 | static errno_t dispc_seat_create(void *arg, const char *name,
|
---|
159 | sysarg_t *rseat_id)
|
---|
160 | {
|
---|
161 | ds_cfgclient_t *cfgclient = (ds_cfgclient_t *)arg;
|
---|
162 | ds_seat_t *seat;
|
---|
163 | errno_t rc;
|
---|
164 |
|
---|
165 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispcfg_seat_create()");
|
---|
166 |
|
---|
167 | ds_display_lock(cfgclient->display);
|
---|
168 |
|
---|
169 | rc = ds_seat_create(cfgclient->display, name, &seat);
|
---|
170 | if (rc != EOK) {
|
---|
171 | ds_display_unlock(cfgclient->display);
|
---|
172 | return rc;
|
---|
173 | }
|
---|
174 |
|
---|
175 | (void) ds_display_paint(cfgclient->display, NULL);
|
---|
176 | ds_display_unlock(cfgclient->display);
|
---|
177 |
|
---|
178 | *rseat_id = seat->id;
|
---|
179 | return EOK;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /** Delete seat.
|
---|
183 | *
|
---|
184 | * @param arg Argument (CFG client)
|
---|
185 | * @param seat_id Seat ID
|
---|
186 | * @return EOK on success or an error code
|
---|
187 | */
|
---|
188 | static errno_t dispc_seat_delete(void *arg, sysarg_t seat_id)
|
---|
189 | {
|
---|
190 | ds_cfgclient_t *cfgclient = (ds_cfgclient_t *)arg;
|
---|
191 | ds_seat_t *seat;
|
---|
192 |
|
---|
193 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispcfg_seat_delete()");
|
---|
194 |
|
---|
195 | ds_display_lock(cfgclient->display);
|
---|
196 | seat = ds_display_find_seat(cfgclient->display, seat_id);
|
---|
197 | if (seat == NULL) {
|
---|
198 | ds_display_unlock(cfgclient->display);
|
---|
199 | return ENOENT;
|
---|
200 | }
|
---|
201 |
|
---|
202 | ds_seat_destroy(seat);
|
---|
203 |
|
---|
204 | (void) ds_display_paint(cfgclient->display, NULL);
|
---|
205 | ds_display_unlock(cfgclient->display);
|
---|
206 | return EOK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | /** Get display configuration event.
|
---|
210 | *
|
---|
211 | * @param arg Argument (CFG client)
|
---|
212 | * @param ev Place to store event
|
---|
213 | * @return EOK on success, ENOENT if there are no events
|
---|
214 | */
|
---|
215 | static errno_t dispc_get_event(void *arg, dispcfg_ev_t *ev)
|
---|
216 | {
|
---|
217 | ds_cfgclient_t *cfgclient = (ds_cfgclient_t *)arg;
|
---|
218 | errno_t rc;
|
---|
219 |
|
---|
220 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispcfg_get_event()");
|
---|
221 |
|
---|
222 | ds_display_lock(cfgclient->display);
|
---|
223 | rc = ds_cfgclient_get_event(cfgclient, ev);
|
---|
224 | ds_display_unlock(cfgclient->display);
|
---|
225 | return rc;
|
---|
226 | }
|
---|
227 |
|
---|
228 | /** @}
|
---|
229 | */
|
---|