1 /* -*- Mode: C ; c-basic-offset: 4 -*- */
3 Copyright (C) 2007,2008 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)
28 #include <dbus/dbus.h>
30 #include "controller_internal.h"
33 jack_controller_settings_set_bool_option(
34 const char *value_str
,
37 if (strcmp(value_str
, "true") == 0)
41 else if (strcmp(value_str
, "false") == 0)
47 jack_error("ignoring unknown bool value \"%s\"", value_str
);
52 jack_controller_settings_set_sint_option(
53 const char *value_str
,
56 *value_ptr
= atoi(value_str
);
60 jack_controller_settings_set_uint_option(
61 const char *value_str
,
62 unsigned int *value_ptr
)
64 *value_ptr
= strtoul(value_str
, NULL
, 10);
68 jack_controller_settings_set_char_option(
69 const char *value_str
,
72 if (value_str
[0] == 0 || value_str
[1] != 0)
74 jack_error("invalid char option value \"%s\"", value_str
);
78 *value_ptr
= *value_str
;
82 jack_controller_settings_set_string_option(
83 const char *value_str
,
89 size
= strlen(value_str
);
93 jack_error("string option value \"%s\" is too long, max is %u chars (including terminating zero)", value_str
, (unsigned int)max_size
);
97 strcpy(value_ptr
, value_str
);
101 jack_controller_settings_set_driver_option(
102 jackctl_driver_t
*driver
,
103 const char *option_name
,
104 const char *option_value
)
106 jackctl_parameter_t
*parameter
;
107 jackctl_param_type_t type
;
109 unsigned int value_uint
;
110 union jackctl_parameter_value value
;
112 jack_info("setting driver option \"%s\" to value \"%s\"", option_name
, option_value
);
114 parameter
= jack_controller_find_parameter(jackctl_driver_get_parameters(driver
), option_name
);
115 if (parameter
== NULL
)
118 "Unknown parameter \"%s\" of driver \"%s\"",
120 jackctl_driver_get_name(driver
));
124 type
= jackctl_parameter_get_type(parameter
);
129 jack_controller_settings_set_sint_option(option_value
, &value_int
);
133 jack_controller_settings_set_uint_option(option_value
, &value_uint
);
134 value
.ui
= value_uint
;
137 jack_controller_settings_set_char_option(option_value
, &value
.c
);
139 case JackParamString
:
140 jack_controller_settings_set_string_option(option_value
, value
.str
, sizeof(value
.str
));
143 jack_controller_settings_set_bool_option(option_value
, &value_int
);
147 jack_error("Parameter \"%s\" of driver \"%s\" is of unknown type %d",
148 jackctl_parameter_get_name(parameter
),
149 jackctl_driver_get_name(driver
),
153 jackctl_parameter_set_value(parameter
, &value
);
157 jack_controller_settings_set_internal_option(
158 jackctl_internal_t
*internal
,
159 const char *option_name
,
160 const char *option_value
)
162 jackctl_parameter_t
*parameter
;
163 jackctl_param_type_t type
;
165 unsigned int value_uint
;
166 union jackctl_parameter_value value
;
168 jack_info("setting internal option \"%s\" to value \"%s\"", option_name
, option_value
);
170 parameter
= jack_controller_find_parameter(jackctl_internal_get_parameters(internal
), option_name
);
171 if (parameter
== NULL
)
174 "Unknown parameter \"%s\" of internal \"%s\"",
176 jackctl_internal_get_name(internal
));
180 type
= jackctl_parameter_get_type(parameter
);
185 jack_controller_settings_set_sint_option(option_value
, &value_int
);
189 jack_controller_settings_set_uint_option(option_value
, &value_uint
);
190 value
.ui
= value_uint
;
193 jack_controller_settings_set_char_option(option_value
, &value
.c
);
195 case JackParamString
:
196 jack_controller_settings_set_string_option(option_value
, value
.str
, sizeof(value
.str
));
199 jack_controller_settings_set_bool_option(option_value
, &value_int
);
203 jack_error("Parameter \"%s\" of internal \"%s\" is of unknown type %d",
204 jackctl_parameter_get_name(parameter
),
205 jackctl_internal_get_name(internal
),
209 jackctl_parameter_set_value(parameter
, &value
);
213 jack_controller_settings_set_engine_option(
214 struct jack_controller
*controller_ptr
,
215 const char *option_name
,
216 const char *option_value
)
218 jackctl_parameter_t
*parameter
;
219 jackctl_param_type_t type
;
221 unsigned int value_uint
;
222 union jackctl_parameter_value value
;
224 jack_info("setting engine option \"%s\" to value \"%s\"", option_name
, option_value
);
226 if (strcmp(option_name
, "driver") == 0)
228 if (!jack_controller_select_driver(controller_ptr
, option_value
))
230 jack_error("unknown driver '%s'", option_value
);
236 parameter
= jack_controller_find_parameter(jackctl_server_get_parameters(controller_ptr
->server
), option_name
);
237 if (parameter
== NULL
)
240 "Unknown engine parameter \"%s\"",
245 type
= jackctl_parameter_get_type(parameter
);
250 jack_controller_settings_set_sint_option(option_value
, &value_int
);
254 jack_controller_settings_set_uint_option(option_value
, &value_uint
);
255 value
.ui
= value_uint
;
258 jack_controller_settings_set_char_option(option_value
, &value
.c
);
260 case JackParamString
:
261 jack_controller_settings_set_string_option(option_value
, value
.str
, sizeof(value
.str
));
264 jack_controller_settings_set_bool_option(option_value
, &value_int
);
268 jack_error("Engine parameter \"%s\" is of unknown type %d",
269 jackctl_parameter_get_name(parameter
),
273 jackctl_parameter_set_value(parameter
, &value
);
278 jack_controller_settings_save_options(
280 const JSList
* parameters_list
,
281 void *dbus_call_context_ptr
)
283 jackctl_parameter_t
*parameter
;
284 jackctl_param_type_t type
;
285 union jackctl_parameter_value value
;
289 while (parameters_list
!= NULL
)
291 parameter
= (jackctl_parameter_t
*)parameters_list
->data
;
293 if (jackctl_parameter_is_set(parameter
))
295 type
= jackctl_parameter_get_type(parameter
);
296 value
= jackctl_parameter_get_value(parameter
);
297 name
= jackctl_parameter_get_name(parameter
);
302 sprintf(value_str
, "%d", (int)value
.i
);
303 if (!jack_controller_settings_write_option(context
, name
, value_str
, dbus_call_context_ptr
))
309 sprintf(value_str
, "%u", (unsigned int)value
.ui
);
310 if (!jack_controller_settings_write_option(context
, name
, value_str
, dbus_call_context_ptr
))
316 sprintf(value_str
, "%c", (char)value
.c
);
317 if (!jack_controller_settings_write_option(context
, name
, value_str
, dbus_call_context_ptr
))
322 case JackParamString
:
323 if (!jack_controller_settings_write_option(context
, name
, value
.str
, dbus_call_context_ptr
))
329 if (!jack_controller_settings_write_option(context
, name
, value
.b
? "true" : "false", dbus_call_context_ptr
))
335 jack_error("parameter of unknown type %d", type
);
339 parameters_list
= jack_slist_next(parameters_list
);
346 jack_controller_settings_save_engine_options(
348 struct jack_controller
*controller_ptr
,
349 void *dbus_call_context_ptr
)
351 if (controller_ptr
->driver
!= NULL
)
353 if (!jack_controller_settings_write_option(
356 jackctl_driver_get_name(controller_ptr
->driver
),
357 dbus_call_context_ptr
))
363 return jack_controller_settings_save_options(context
, jackctl_server_get_parameters(controller_ptr
->server
), dbus_call_context_ptr
);
367 jack_controller_settings_save_driver_options(
369 jackctl_driver_t
*driver
,
370 void *dbus_call_context_ptr
)
372 return jack_controller_settings_save_options(context
, jackctl_driver_get_parameters(driver
), dbus_call_context_ptr
);
376 jack_controller_settings_save_internal_options(
378 jackctl_internal_t
*internal
,
379 void *dbus_call_context_ptr
)
381 return jack_controller_settings_save_options(context
, jackctl_internal_get_parameters(internal
), dbus_call_context_ptr
);