Changeset 9546146 in mainline for uspace/srv/hid/display/display.c
- Timestamp:
- 2024-08-23T18:02:06Z (10 months ago)
- Branches:
- master
- Children:
- 4af6fb1
- Parents:
- ca95ccd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/display.c
rca95ccd r9546146 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 #include <memgfx/memgc.h> 42 42 #include <stdlib.h> 43 #include <str.h> 43 44 #include "client.h" 44 45 #include "clonegc.h" … … 46 47 #include "cursor.h" 47 48 #include "display.h" 49 #include "idevcfg.h" 48 50 #include "seat.h" 49 51 #include "window.h" … … 100 102 list_initialize(&disp->cfgclients); 101 103 disp->next_wnd_id = 1; 104 disp->next_seat_id = 1; 102 105 list_initialize(&disp->ddevs); 103 106 list_initialize(&disp->idevcfgs); … … 137 140 gfx_color_delete(disp->bg_color); 138 141 free(disp); 142 } 143 144 /** Load display configuration from SIF file. 145 * 146 * @param display Display 147 * @param cfgpath Configuration file path 148 * 149 * @return EOK on success or an error code 150 */ 151 errno_t ds_display_load_cfg(ds_display_t *display, const char *cfgpath) 152 { 153 sif_doc_t *doc = NULL; 154 sif_node_t *rnode; 155 sif_node_t *ndisplay; 156 sif_node_t *nseats; 157 sif_node_t *nseat; 158 ds_seat_t *seat; 159 sif_node_t *nidevcfgs; 160 sif_node_t *nidevcfg; 161 const char *ntype; 162 ds_idevcfg_t *idevcfg; 163 errno_t rc; 164 165 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: load '%s'", cfgpath); 166 rc = sif_load(cfgpath, &doc); 167 if (rc != EOK) 168 goto error; 169 170 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: get root"); 171 rnode = sif_get_root(doc); 172 ndisplay = sif_node_first_child(rnode); 173 ntype = sif_node_get_type(ndisplay); 174 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: check display node"); 175 if (str_cmp(ntype, "display") != 0) { 176 rc = EIO; 177 goto error; 178 } 179 180 nseats = sif_node_first_child(ndisplay); 181 ntype = sif_node_get_type(nseats); 182 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: check seats node"); 183 if (str_cmp(ntype, "seats") != 0) { 184 rc = EIO; 185 goto error; 186 } 187 188 /* Load individual seats */ 189 nseat = sif_node_first_child(nseats); 190 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: walk seat nodes"); 191 while (nseat != NULL) { 192 ntype = sif_node_get_type(nseat); 193 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: check seat node"); 194 if (str_cmp(ntype, "seat") != 0) { 195 rc = EIO; 196 goto error; 197 } 198 199 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: load seat"); 200 rc = ds_seat_load(display, nseat, &seat); 201 if (rc != EOK) 202 goto error; 203 204 (void)seat; 205 nseat = sif_node_next_child(nseat); 206 } 207 208 nidevcfgs = sif_node_next_child(nseats); 209 ntype = sif_node_get_type(nidevcfgs); 210 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: check idevcfgs node"); 211 if (str_cmp(ntype, "idevcfgs") != 0) { 212 rc = EIO; 213 goto error; 214 } 215 216 /* Load individual input device configuration entries */ 217 nidevcfg = sif_node_first_child(nidevcfgs); 218 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: walk idevcfg nodes"); 219 while (nidevcfg != NULL) { 220 ntype = sif_node_get_type(nidevcfg); 221 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: check idevcfg node"); 222 if (str_cmp(ntype, "idevcfg") != 0) { 223 rc = EIO; 224 goto error; 225 } 226 227 log_msg(LOG_DEFAULT, LVL_NOTE, "ds_display_load_cfg: load idevcfg"); 228 rc = ds_idevcfg_load(display, nidevcfg, &idevcfg); 229 if (rc != EOK) 230 goto error; 231 232 (void)idevcfg; 233 nidevcfg = sif_node_next_child(nidevcfg); 234 } 235 236 sif_delete(doc); 237 return EOK; 238 error: 239 if (doc != NULL) 240 sif_delete(doc); 241 242 seat = ds_display_first_seat(display); 243 while (seat != NULL) { 244 ds_seat_destroy(seat); 245 seat = ds_display_first_seat(display); 246 } 247 return rc; 248 } 249 250 /** Save seat to SIF node. 251 * 252 * @param display Display 253 * @param cfgpath Configuration file path 254 * 255 * @return EOK on success or an error code 256 */ 257 errno_t ds_display_save_cfg(ds_display_t *display, const char *cfgpath) 258 { 259 sif_doc_t *doc = NULL; 260 sif_node_t *rnode; 261 sif_node_t *ndisplay; 262 sif_node_t *nseats; 263 sif_node_t *nseat; 264 ds_seat_t *seat; 265 sif_node_t *nidevcfgs; 266 sif_node_t *nidevcfg; 267 ds_idevcfg_t *idevcfg; 268 errno_t rc; 269 270 rc = sif_new(&doc); 271 if (rc != EOK) 272 goto error; 273 274 rnode = sif_get_root(doc); 275 rc = sif_node_append_child(rnode, "display", &ndisplay); 276 if (rc != EOK) 277 goto error; 278 279 rc = sif_node_append_child(ndisplay, "seats", &nseats); 280 if (rc != EOK) 281 goto error; 282 283 /* Save individual seats */ 284 seat = ds_display_first_seat(display); 285 while (seat != NULL) { 286 rc = sif_node_append_child(nseats, "seat", &nseat); 287 if (rc != EOK) 288 goto error; 289 290 rc = ds_seat_save(seat, nseat); 291 if (rc != EOK) 292 goto error; 293 294 seat = ds_display_next_seat(seat); 295 } 296 297 rc = sif_node_append_child(ndisplay, "idevcfgs", &nidevcfgs); 298 if (rc != EOK) 299 goto error; 300 301 /* Save individual input device configuration entries */ 302 idevcfg = ds_display_first_idevcfg(display); 303 while (idevcfg != NULL) { 304 rc = sif_node_append_child(nidevcfgs, "idevcfg", &nidevcfg); 305 if (rc != EOK) 306 goto error; 307 308 rc = ds_idevcfg_save(idevcfg, nidevcfg); 309 if (rc != EOK) 310 goto error; 311 312 idevcfg = ds_display_next_idevcfg(idevcfg); 313 } 314 315 rc = sif_save(doc, cfgpath); 316 if (rc != EOK) 317 goto error; 318 319 sif_delete(doc); 320 return EOK; 321 error: 322 if (doc != NULL) 323 sif_delete(doc); 324 return rc; 139 325 } 140 326
Note:
See TracChangeset
for help on using the changeset viewer.