[wscript] Even more -Wl,--as-needed fixes
[jack2.git] / dbus / xml.c
blobc7e11377999b7ca58df0be42820624facb0895fe
1 /* -*- Mode: C ; c-basic-offset: 4 -*- */
2 /*
3 Copyright (C) 2007,2008,2011 Nedko Arnaudov
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #if defined(HAVE_CONFIG_H)
21 #include "config.h"
22 #endif
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <assert.h>
29 #include <dbus/dbus.h>
31 #include "controller_internal.h"
33 void
34 jack_controller_deserialize_parameter_value(
35 struct jack_controller *controller_ptr,
36 const char * const * address,
37 const char * option_value)
39 const struct jack_parameter * param_ptr;
40 union jackctl_parameter_value value;
41 size_t size;
43 param_ptr = jack_params_get_parameter(controller_ptr->params, address);
44 if (param_ptr == NULL)
46 jack_error("Unknown parameter");
47 goto ignore;
50 jack_info("setting parameter '%s':'%s':'%s' to value \"%s\"", address[0], address[1], address[2], option_value);
52 switch (param_ptr->type)
54 case JackParamInt:
55 value.i = atoi(option_value);
56 break;
57 case JackParamUInt:
58 value.ui = strtoul(option_value, NULL, 10);
59 break;
60 case JackParamChar:
61 if (option_value[0] == 0 || option_value[1] != 0)
63 jack_error("invalid char option value \"%s\"", option_value);
64 goto ignore;
66 value.c = *option_value;
67 break;
68 case JackParamString:
69 size = strlen(option_value);
70 if (size >= sizeof(value.str))
72 jack_error("string option value \"%s\" is too long, max is %zu chars (including terminating zero)", option_value, sizeof(value.str));
73 goto ignore;
76 strcpy(value.str, option_value);
77 break;
78 case JackParamBool:
79 if (strcmp(option_value, "true") == 0)
81 value.b = true;
83 else if (strcmp(option_value, "false") == 0)
85 value.b = false;
87 else
89 jack_error("ignoring unknown bool value \"%s\"", option_value);
90 goto ignore;
92 break;
93 default:
94 jack_error("Unknown type %d", (int)param_ptr->type);
95 goto ignore;
98 if (param_ptr->vtable.set_value(param_ptr->obj, &value))
100 return;
103 jack_error("Parameter set failed");
105 ignore:
106 jack_error("Ignoring restore attempt of parameter '%s':'%s':'%s'", address[0], address[1], address[2]);
109 void
110 jack_controller_serialize_parameter_value(
111 const struct jack_parameter * param_ptr,
112 char * value_buffer)
114 union jackctl_parameter_value value;
116 value = param_ptr->vtable.get_value(param_ptr->obj);
118 switch (param_ptr->type)
120 case JackParamInt:
121 sprintf(value_buffer, "%d", (int)value.i);
122 return;
123 case JackParamUInt:
124 sprintf(value_buffer, "%u", (unsigned int)value.ui);
125 return;
126 case JackParamChar:
127 sprintf(value_buffer, "%c", (char)value.c);
128 return;
129 case JackParamString:
130 strcpy(value_buffer, value.str);
131 return;
132 case JackParamBool:
133 strcpy(value_buffer, value.b ? "true" : "false");
134 return;
137 jack_error("parameter of unknown type %d", (int)param_ptr->type);
138 assert(false);
139 *value_buffer = 0;