VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceGadgetCfg.cpp@ 72293

Last change on this file since 72293 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 KB
Line 
1/* $Id: UsbTestServiceGadgetCfg.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * UsbTestServ - Remote USB test configuration and execution server, USB gadget Cfg API.
4 */
5
6/*
7 * Copyright (C) 2016-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31
32#include <iprt/cdefs.h>
33#include <iprt/ctype.h>
34#include <iprt/mem.h>
35#include <iprt/string.h>
36#include <iprt/types.h>
37
38#include "UsbTestServiceGadget.h"
39
40
41/*********************************************************************************************************************************
42* Constants And Macros, Structures and Typedefs *
43*********************************************************************************************************************************/
44
45
46/*********************************************************************************************************************************
47* Internal Functions *
48*********************************************************************************************************************************/
49
50/**
51 * Returns the gadget configuration item matching the given key.
52 *
53 * @returns Pointer to the configuration item on success or NULL if not found.
54 * @param paCfg The configuration item array.
55 * @param pszKey The key to look for.
56 */
57static PCUTSGADGETCFGITEM utsGadgetCfgGetItemFromKey(PCUTSGADGETCFGITEM paCfg, const char *pszKey)
58{
59 while ( paCfg
60 && paCfg->pszKey)
61 {
62 if (!RTStrCmp(paCfg->pszKey, pszKey))
63 return paCfg;
64
65 paCfg++;
66 }
67 return NULL;
68}
69
70
71
72DECLHIDDEN(int) utsGadgetCfgQueryBool(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
73 bool *pf)
74{
75 int rc = VERR_NOT_FOUND;
76 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
77
78 if (pCfgItem)
79 {
80 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_BOOLEAN)
81 {
82 *pf = pCfgItem->Val.u.f;
83 rc = VINF_SUCCESS;
84 }
85 else
86 rc = VERR_INVALID_PARAMETER;
87 }
88
89 return rc;
90}
91
92
93DECLHIDDEN(int) utsGadgetCfgQueryBoolDef(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
94 bool *pf, bool fDef)
95{
96 int rc = VERR_INVALID_PARAMETER;
97 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
98
99 if ( !pCfgItem
100 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_BOOLEAN)
101 {
102 *pf = pCfgItem ? pCfgItem->Val.u.f : fDef;
103 rc = VINF_SUCCESS;
104 }
105
106 return rc;
107}
108
109
110DECLHIDDEN(int) utsGadgetCfgQueryString(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
111 char **ppszVal)
112{
113 int rc = VERR_NOT_FOUND;
114 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
115
116 if (pCfgItem)
117 {
118 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_STRING)
119 {
120 *ppszVal = RTStrDup(pCfgItem->Val.u.psz);
121 if (*ppszVal)
122 rc = VINF_SUCCESS;
123 else
124 rc = VERR_NO_STR_MEMORY;
125 }
126 else
127 rc = VERR_INVALID_PARAMETER;
128 }
129
130 return rc;
131}
132
133
134DECLHIDDEN(int) utsGadgetCfgQueryStringDef(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
135 char **ppszVal, const char *pszDef)
136{
137 int rc = VERR_NOT_FOUND;
138 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
139
140 if ( !pCfgItem
141 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_STRING)
142 {
143 *ppszVal = RTStrDup(pCfgItem ? pCfgItem->Val.u.psz : pszDef);
144 if (*ppszVal)
145 rc = VINF_SUCCESS;
146 else
147 rc = VERR_NO_STR_MEMORY;
148 }
149 else
150 rc = VERR_INVALID_PARAMETER;
151
152 return rc;
153}
154
155
156DECLHIDDEN(int) utsGadgetCfgQueryU8(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
157 uint8_t *pu8)
158{
159 int rc = VERR_NOT_FOUND;
160 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
161
162 if (pCfgItem)
163 {
164 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT8)
165 {
166 *pu8 = pCfgItem->Val.u.u8;
167 rc = VINF_SUCCESS;
168 }
169 else
170 rc = VERR_INVALID_PARAMETER;
171 }
172
173 return rc;
174}
175
176
177DECLHIDDEN(int) utsGadgetCfgQueryU8Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
178 uint8_t *pu8, uint8_t u8Def)
179{
180 int rc = VERR_INVALID_PARAMETER;
181 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
182
183 if ( !pCfgItem
184 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT8)
185 {
186 *pu8 = pCfgItem ? pCfgItem->Val.u.u8 : u8Def;
187 rc = VINF_SUCCESS;
188 }
189
190 return rc;
191}
192
193
194DECLHIDDEN(int) utsGadgetCfgQueryU16(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
195 uint16_t *pu16)
196{
197 int rc = VERR_NOT_FOUND;
198 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
199
200 if (pCfgItem)
201 {
202 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT16)
203 {
204 *pu16 = pCfgItem->Val.u.u16;
205 rc = VINF_SUCCESS;
206 }
207 else
208 rc = VERR_INVALID_PARAMETER;
209 }
210
211 return rc;
212}
213
214
215DECLHIDDEN(int) utsGadgetCfgQueryU16Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
216 uint16_t *pu16, uint16_t u16Def)
217{
218 int rc = VERR_INVALID_PARAMETER;
219 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
220
221 if ( !pCfgItem
222 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT16)
223 {
224 *pu16 = pCfgItem ? pCfgItem->Val.u.u16 : u16Def;
225 rc = VINF_SUCCESS;
226 }
227
228 return rc;
229}
230
231
232DECLHIDDEN(int) utsGadgetCfgQueryU32(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
233 uint32_t *pu32)
234{
235 int rc = VERR_NOT_FOUND;
236 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
237
238 if (pCfgItem)
239 {
240 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT32)
241 {
242 *pu32 = pCfgItem->Val.u.u32;
243 rc = VINF_SUCCESS;
244 }
245 else
246 rc = VERR_INVALID_PARAMETER;
247 }
248
249 return rc;
250}
251
252
253DECLHIDDEN(int) utsGadgetCfgQueryU32Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
254 uint32_t *pu32, uint32_t u32Def)
255{
256 int rc = VERR_INVALID_PARAMETER;
257 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
258
259 if ( !pCfgItem
260 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT32)
261 {
262 *pu32 = pCfgItem ? pCfgItem->Val.u.u32 : u32Def;
263 rc = VINF_SUCCESS;
264 }
265
266 return rc;
267}
268
269
270DECLHIDDEN(int) utsGadgetCfgQueryU64(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
271 uint64_t *pu64)
272{
273 int rc = VERR_NOT_FOUND;
274 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
275
276 if (pCfgItem)
277 {
278 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT64)
279 {
280 *pu64 = pCfgItem->Val.u.u64;
281 rc = VINF_SUCCESS;
282 }
283 else
284 rc = VERR_INVALID_PARAMETER;
285 }
286
287 return rc;
288}
289
290
291DECLHIDDEN(int) utsGadgetCfgQueryU64Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
292 uint64_t *pu64, uint64_t u64Def)
293{
294 int rc = VERR_INVALID_PARAMETER;
295 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
296
297 if ( !pCfgItem
298 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_UINT64)
299 {
300 *pu64 = pCfgItem ? pCfgItem->Val.u.u64 : u64Def;
301 rc = VINF_SUCCESS;
302 }
303
304 return rc;
305}
306
307
308DECLHIDDEN(int) utsGadgetCfgQueryS8(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
309 int8_t *pi8)
310{
311 int rc = VERR_NOT_FOUND;
312 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
313
314 if (pCfgItem)
315 {
316 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT8)
317 {
318 *pi8 = pCfgItem->Val.u.i8;
319 rc = VINF_SUCCESS;
320 }
321 else
322 rc = VERR_INVALID_PARAMETER;
323 }
324
325 return rc;
326}
327
328
329DECLHIDDEN(int) utsGadgetCfgQueryS8Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
330 int8_t *pi8, uint8_t i8Def)
331{
332 int rc = VERR_INVALID_PARAMETER;
333 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
334
335 if ( !pCfgItem
336 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT8)
337 {
338 *pi8 = pCfgItem ? pCfgItem->Val.u.i8 : i8Def;
339 rc = VINF_SUCCESS;
340 }
341
342 return rc;
343}
344
345
346DECLHIDDEN(int) utsGadgetCfgQueryS16(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
347 uint16_t *pi16)
348{
349 int rc = VERR_NOT_FOUND;
350 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
351
352 if (pCfgItem)
353 {
354 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT16)
355 {
356 *pi16 = pCfgItem->Val.u.i16;
357 rc = VINF_SUCCESS;
358 }
359 else
360 rc = VERR_INVALID_PARAMETER;
361 }
362
363 return rc;
364}
365
366
367DECLHIDDEN(int) utsGadgetCfgQueryS16Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
368 uint16_t *pi16, uint16_t i16Def)
369{
370 int rc = VERR_INVALID_PARAMETER;
371 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
372
373 if ( !pCfgItem
374 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT16)
375 {
376 *pi16 = pCfgItem ? pCfgItem->Val.u.i16 : i16Def;
377 rc = VINF_SUCCESS;
378 }
379
380 return rc;
381}
382
383
384DECLHIDDEN(int) utsGadgetCfgQueryS32(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
385 uint32_t *pi32)
386{
387 int rc = VERR_NOT_FOUND;
388 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
389
390 if (pCfgItem)
391 {
392 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT32)
393 {
394 *pi32 = pCfgItem->Val.u.i32;
395 rc = VINF_SUCCESS;
396 }
397 else
398 rc = VERR_INVALID_PARAMETER;
399 }
400
401 return rc;
402}
403
404
405DECLHIDDEN(int) utsGadgetCfgQueryS32Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
406 uint32_t *pi32, uint32_t i32Def)
407{
408 int rc = VERR_INVALID_PARAMETER;
409 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
410
411 if ( !pCfgItem
412 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT32)
413 {
414 *pi32 = pCfgItem ? pCfgItem->Val.u.i32 : i32Def;
415 rc = VINF_SUCCESS;
416 }
417
418 return rc;
419}
420
421
422DECLHIDDEN(int) utsGadgetCfgQueryS64(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
423 uint64_t *pi64)
424{
425 int rc = VERR_NOT_FOUND;
426 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
427
428 if (pCfgItem)
429 {
430 if (pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT64)
431 {
432 *pi64 = pCfgItem->Val.u.i64;
433 rc = VINF_SUCCESS;
434 }
435 else
436 rc = VERR_INVALID_PARAMETER;
437 }
438
439 return rc;
440}
441
442
443DECLHIDDEN(int) utsGadgetCfgQueryS64Def(PCUTSGADGETCFGITEM paCfg, const char *pszKey,
444 uint64_t *pi64, uint64_t i64Def)
445{
446 int rc = VERR_INVALID_PARAMETER;
447 PCUTSGADGETCFGITEM pCfgItem = utsGadgetCfgGetItemFromKey(paCfg, pszKey);
448
449 if ( !pCfgItem
450 || pCfgItem->Val.enmType == UTSGADGETCFGTYPE_INT64)
451 {
452 *pi64 = pCfgItem ? pCfgItem->Val.u.i64 : i64Def;
453 rc = VINF_SUCCESS;
454 }
455
456 return rc;
457}
458
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette