Changeset 9546146 in mainline for uspace/srv/hid/display/idevcfg.c


Ignore:
Timestamp:
2024-08-23T18:02:06Z (4 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
4af6fb1
Parents:
ca95ccd
Message:

Persistently store display/seat configuration.

File:
1 edited

Legend:

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

    rca95ccd r9546146  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <io/log.h>
    3939#include <loc.h>
     40#include <stdio.h>
    4041#include <stdlib.h>
    4142#include "display.h"
     
    8081}
    8182
     83/** Load input device configuration entry from SIF node.
     84 *
     85 * @param display Display
     86 * @param enode Entry node from which the entry should be loaded
     87 * @param ridevcfg Place to store pointer to the newly loaded input device
     88 *                 configuration entry
     89 *
     90 * @return EOK on success or an error code
     91 */
     92errno_t ds_idevcfg_load(ds_display_t *display, sif_node_t *enode,
     93    ds_idevcfg_t **ridevcfg)
     94{
     95        const char *svc_name;
     96        const char *sseat_id;
     97        char *endptr;
     98        unsigned long svc_id;
     99        unsigned long seat_id;
     100        ds_seat_t *seat;
     101        ds_idevcfg_t *idevcfg;
     102        errno_t rc;
     103
     104        svc_name = sif_node_get_attr(enode, "svc-name");
     105        if (svc_name == NULL)
     106                return EIO;
     107
     108        sseat_id = sif_node_get_attr(enode, "seat-id");
     109        if (sseat_id == NULL)
     110                return EIO;
     111
     112        rc = loc_service_get_id(svc_name, &svc_id, 0);
     113        if (rc != EOK)
     114                return rc;
     115
     116        seat_id = strtoul(sseat_id, &endptr, 10);
     117        if (*endptr != '\0')
     118                return EIO;
     119
     120        seat = ds_display_find_seat(display, seat_id);
     121        if (seat == NULL)
     122                return EIO;
     123
     124        rc = ds_idevcfg_create(display, svc_id, seat, &idevcfg);
     125        if (rc != EOK)
     126                return rc;
     127
     128        (void)idevcfg;
     129        return EOK;
     130}
     131
     132/** Save input device configuration entry to SIF node.
     133 *
     134 * @param idevcfg Input device configuration entry
     135 * @param enode Entry node to which the entry should be saved
     136 *
     137 * @return EOK on success or an error code
     138 */
     139errno_t ds_idevcfg_save(ds_idevcfg_t *idevcfg, sif_node_t *enode)
     140{
     141        char *svc_name;
     142        char *sseat_id;
     143        errno_t rc;
     144        int rv;
     145
     146        rc = loc_service_get_name(idevcfg->svc_id, &svc_name);
     147        if (rc != EOK)
     148                return rc;
     149
     150        rc = sif_node_set_attr(enode, "svc-name", svc_name);
     151        if (rc != EOK) {
     152                free(svc_name);
     153                return rc;
     154        }
     155
     156        free(svc_name);
     157
     158        rv = asprintf(&sseat_id, "%lu", (unsigned long)idevcfg->seat->id);
     159        if (rv < 0) {
     160                rc = ENOMEM;
     161                return rc;
     162        }
     163
     164        rc = sif_node_set_attr(enode, "seat-id", sseat_id);
     165        if (rc != EOK) {
     166                free(sseat_id);
     167                return rc;
     168        }
     169
     170        free(sseat_id);
     171        return EOK;
     172}
     173
    82174/** @}
    83175 */
Note: See TracChangeset for help on using the changeset viewer.