source: mainline/uspace/srv/hid/display/idevcfg.c

Last change on this file was de4f165, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 10 months ago

Unbreak build for 32b architectures

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2024 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 server input device configuration
34 */
35
36#include <adt/list.h>
37#include <errno.h>
38#include <io/log.h>
39#include <loc.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include "display.h"
43#include "idevcfg.h"
44#include "seat.h"
45
46/** Create input device configuration entry.
47 *
48 * @param display Parent display
49 * @param svc_id Device service ID
50 * @param seat Seat to which device is assigned
51 * @param ridevcfg Place to store pointer to new input device configuration
52 * entry
53 * @return EOK on success, ENOMEM if out of memory
54 */
55errno_t ds_idevcfg_create(ds_display_t *display, service_id_t svc_id,
56 ds_seat_t *seat, ds_idevcfg_t **ridevcfg)
57{
58 ds_idevcfg_t *idevcfg;
59
60 idevcfg = calloc(1, sizeof(ds_idevcfg_t));
61 if (idevcfg == NULL)
62 return ENOMEM;
63
64 idevcfg->svc_id = svc_id;
65 ds_seat_add_idevcfg(seat, idevcfg);
66
67 ds_display_add_idevcfg(display, idevcfg);
68 *ridevcfg = idevcfg;
69 return EOK;
70}
71
72/** Destroy input device configuration entry.
73 *
74 * @param ddev Display device
75 */
76void ds_idevcfg_destroy(ds_idevcfg_t *idevcfg)
77{
78 ds_display_remove_idevcfg(idevcfg);
79 ds_seat_remove_idevcfg(idevcfg);
80 free(idevcfg);
81}
82
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
174/** @}
175 */
Note: See TracBrowser for help on using the repository browser.