1 /* -*- Mode: C ; c-basic-offset: 4 -*- */
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)
29 #include <dbus/dbus.h>
31 #include "controller_internal.h"
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
;
43 param_ptr
= jack_params_get_parameter(controller_ptr
->params
, address
);
44 if (param_ptr
== NULL
)
46 jack_error("Unknown parameter");
50 jack_info("setting parameter '%s':'%s':'%s' to value \"%s\"", address
[0], address
[1], address
[2], option_value
);
52 switch (param_ptr
->type
)
55 value
.i
= atoi(option_value
);
58 value
.ui
= strtoul(option_value
, NULL
, 10);
61 if (option_value
[0] == 0 || option_value
[1] != 0)
63 jack_error("invalid char option value \"%s\"", option_value
);
66 value
.c
= *option_value
;
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
));
76 strcpy(value
.str
, option_value
);
79 if (strcmp(option_value
, "true") == 0)
83 else if (strcmp(option_value
, "false") == 0)
89 jack_error("ignoring unknown bool value \"%s\"", option_value
);
94 jack_error("Unknown type %d", (int)param_ptr
->type
);
98 if (param_ptr
->vtable
.set_value(param_ptr
->obj
, &value
))
103 jack_error("Parameter set failed");
106 jack_error("Ignoring restore attempt of parameter '%s':'%s':'%s'", address
[0], address
[1], address
[2]);
110 jack_controller_serialize_parameter_value(
111 const struct jack_parameter
* param_ptr
,
114 union jackctl_parameter_value value
;
116 value
= param_ptr
->vtable
.get_value(param_ptr
->obj
);
118 switch (param_ptr
->type
)
121 sprintf(value_buffer
, "%d", (int)value
.i
);
124 sprintf(value_buffer
, "%u", (unsigned int)value
.ui
);
127 sprintf(value_buffer
, "%c", (char)value
.c
);
129 case JackParamString
:
130 strcpy(value_buffer
, value
.str
);
133 strcpy(value_buffer
, value
.b
? "true" : "false");
137 jack_error("parameter of unknown type %d", (int)param_ptr
->type
);