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


Ignore:
Timestamp:
2024-10-13T08:23:40Z (8 weeks ago)
Author:
GitHub <noreply@…>
Children:
0472cf17
Parents:
2a0c827c (diff), b3b79981 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
git-committer:
GitHub <noreply@…> (2024-10-13 08:23:40)
Message:

Merge branch 'HelenOS:master' into topic/packet-capture

File:
1 edited

Legend:

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

    r2a0c827c rebb1489  
    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        service_id_t 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.