Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/display.c

    r6fbd1f9 r5d380b6  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141#include <memgfx/memgc.h>
    4242#include <stdlib.h>
    43 #include <str.h>
    4443#include "client.h"
    4544#include "clonegc.h"
     
    4746#include "cursor.h"
    4847#include "display.h"
    49 #include "idevcfg.h"
    5048#include "seat.h"
    5149#include "window.h"
     
    102100        list_initialize(&disp->cfgclients);
    103101        disp->next_wnd_id = 1;
    104         disp->next_seat_id = 1;
    105102        list_initialize(&disp->ddevs);
    106103        list_initialize(&disp->idevcfgs);
    107         list_initialize(&disp->ievents);
    108         fibril_condvar_initialize(&disp->ievent_cv);
    109104        list_initialize(&disp->seats);
    110105        list_initialize(&disp->windows);
     
    131126        assert(list_empty(&disp->ddevs));
    132127        assert(list_empty(&disp->idevcfgs));
    133         assert(list_empty(&disp->ievents));
    134128        assert(list_empty(&disp->seats));
    135129        assert(list_empty(&disp->windows));
     
    143137        gfx_color_delete(disp->bg_color);
    144138        free(disp);
    145 }
    146 
    147 /** Load display configuration from SIF file.
    148  *
    149  * @param display Display
    150  * @param cfgpath Configuration file path
    151  *
    152  * @return EOK on success or an error code
    153  */
    154 errno_t ds_display_load_cfg(ds_display_t *display, const char *cfgpath)
    155 {
    156         sif_doc_t *doc = NULL;
    157         sif_node_t *rnode;
    158         sif_node_t *ndisplay;
    159         sif_node_t *nseats;
    160         sif_node_t *nseat;
    161         ds_seat_t *seat;
    162         sif_node_t *nidevcfgs;
    163         sif_node_t *nidevcfg;
    164         const char *ntype;
    165         ds_idevcfg_t *idevcfg;
    166         errno_t rc;
    167 
    168         rc = sif_load(cfgpath, &doc);
    169         if (rc != EOK)
    170                 goto error;
    171 
    172         rnode = sif_get_root(doc);
    173         ndisplay = sif_node_first_child(rnode);
    174         ntype = sif_node_get_type(ndisplay);
    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         if (str_cmp(ntype, "seats") != 0) {
    183                 rc = EIO;
    184                 goto error;
    185         }
    186 
    187         /* Load individual seats */
    188         nseat = sif_node_first_child(nseats);
    189         while (nseat != NULL) {
    190                 ntype = sif_node_get_type(nseat);
    191                 if (str_cmp(ntype, "seat") != 0) {
    192                         rc = EIO;
    193                         goto error;
    194                 }
    195 
    196                 rc = ds_seat_load(display, nseat, &seat);
    197                 if (rc != EOK)
    198                         goto error;
    199 
    200                 (void)seat;
    201                 nseat = sif_node_next_child(nseat);
    202         }
    203 
    204         nidevcfgs = sif_node_next_child(nseats);
    205         ntype = sif_node_get_type(nidevcfgs);
    206         if (str_cmp(ntype, "idevcfgs") != 0) {
    207                 rc = EIO;
    208                 goto error;
    209         }
    210 
    211         /* Load individual input device configuration entries */
    212         nidevcfg = sif_node_first_child(nidevcfgs);
    213         while (nidevcfg != NULL) {
    214                 ntype = sif_node_get_type(nidevcfg);
    215                 if (str_cmp(ntype, "idevcfg") != 0) {
    216                         rc = EIO;
    217                         goto error;
    218                 }
    219 
    220                 /*
    221                  * Load device configuration entry. If the device
    222                  * is not currently connected (ENOENT), skip it.
    223                  */
    224                 rc = ds_idevcfg_load(display, nidevcfg, &idevcfg);
    225                 if (rc != EOK && rc != ENOENT)
    226                         goto error;
    227 
    228                 (void)idevcfg;
    229                 nidevcfg = sif_node_next_child(nidevcfg);
    230         }
    231 
    232         sif_delete(doc);
    233         return EOK;
    234 error:
    235         if (doc != NULL)
    236                 sif_delete(doc);
    237 
    238         seat = ds_display_first_seat(display);
    239         while (seat != NULL) {
    240                 ds_seat_destroy(seat);
    241                 seat = ds_display_first_seat(display);
    242         }
    243         return rc;
    244 }
    245 
    246 /** Save display configuration to SIF file.
    247  *
    248  * @param display Display
    249  * @param cfgpath Configuration file path
    250  *
    251  * @return EOK on success or an error code
    252  */
    253 errno_t ds_display_save_cfg(ds_display_t *display, const char *cfgpath)
    254 {
    255         sif_doc_t *doc = NULL;
    256         sif_node_t *rnode;
    257         sif_node_t *ndisplay;
    258         sif_node_t *nseats;
    259         sif_node_t *nseat;
    260         ds_seat_t *seat;
    261         sif_node_t *nidevcfgs;
    262         sif_node_t *nidevcfg;
    263         ds_idevcfg_t *idevcfg;
    264         errno_t rc;
    265 
    266         rc = sif_new(&doc);
    267         if (rc != EOK)
    268                 goto error;
    269 
    270         rnode = sif_get_root(doc);
    271         rc = sif_node_append_child(rnode, "display", &ndisplay);
    272         if (rc != EOK)
    273                 goto error;
    274 
    275         rc = sif_node_append_child(ndisplay, "seats", &nseats);
    276         if (rc != EOK)
    277                 goto error;
    278 
    279         /* Save individual seats */
    280         seat = ds_display_first_seat(display);
    281         while (seat != NULL) {
    282                 rc = sif_node_append_child(nseats, "seat", &nseat);
    283                 if (rc != EOK)
    284                         goto error;
    285 
    286                 rc = ds_seat_save(seat, nseat);
    287                 if (rc != EOK)
    288                         goto error;
    289 
    290                 seat = ds_display_next_seat(seat);
    291         }
    292 
    293         rc = sif_node_append_child(ndisplay, "idevcfgs", &nidevcfgs);
    294         if (rc != EOK)
    295                 goto error;
    296 
    297         /* Save individual input device configuration entries */
    298         idevcfg = ds_display_first_idevcfg(display);
    299         while (idevcfg != NULL) {
    300                 rc = sif_node_append_child(nidevcfgs, "idevcfg", &nidevcfg);
    301                 if (rc != EOK)
    302                         goto error;
    303 
    304                 rc = ds_idevcfg_save(idevcfg, nidevcfg);
    305                 if (rc != EOK)
    306                         goto error;
    307 
    308                 idevcfg = ds_display_next_idevcfg(idevcfg);
    309         }
    310 
    311         rc = sif_save(doc, cfgpath);
    312         if (rc != EOK)
    313                 goto error;
    314 
    315         sif_delete(doc);
    316         return EOK;
    317 error:
    318         if (doc != NULL)
    319                 sif_delete(doc);
    320         return rc;
    321139}
    322140
Note: See TracChangeset for help on using the changeset viewer.