port: Make PORT_TYPES_MAX constant
[jack2.git] / dbus / controller_iface_configure.c
bloba5e67f30f332af73d63aa6585b672e6f2ed47167
1 /* -*- Mode: C ; c-basic-offset: 4 -*- */
2 /*
3 Copyright (C) 2007,2008,2011 Nedko Arnaudov
4 Copyright (C) 2007-2008 Juuso Alasuutari
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #if defined(HAVE_CONFIG_H)
22 #include "config.h"
23 #endif
25 #include <stdint.h>
26 #include <string.h>
27 #include <assert.h>
28 #include <dbus/dbus.h>
30 #include "jackdbus.h"
31 #include "controller_internal.h"
32 #include "xml.h"
34 unsigned char jack_controller_dbus_types[JACK_PARAM_MAX] =
36 [JackParamInt] = DBUS_TYPE_INT32,
37 [JackParamUInt] = DBUS_TYPE_UINT32,
38 [JackParamChar] = DBUS_TYPE_BYTE,
39 [JackParamString] = DBUS_TYPE_STRING,
40 [JackParamBool] = DBUS_TYPE_BOOLEAN,
43 const char *jack_controller_dbus_type_signatures[JACK_PARAM_MAX] =
45 [JackParamInt] = DBUS_TYPE_INT32_AS_STRING,
46 [JackParamUInt] = DBUS_TYPE_UINT32_AS_STRING,
47 [JackParamChar] = DBUS_TYPE_BYTE_AS_STRING,
48 [JackParamString] = DBUS_TYPE_STRING_AS_STRING,
49 [JackParamBool] = DBUS_TYPE_BOOLEAN_AS_STRING,
52 #define PARAM_TYPE_JACK_TO_DBUS(_) jack_controller_dbus_types[_]
53 #define PARAM_TYPE_JACK_TO_DBUS_SIGNATURE(_) jack_controller_dbus_type_signatures[_]
55 static
56 bool
57 jack_controller_jack_to_dbus_variant(
58 jackctl_param_type_t type,
59 const union jackctl_parameter_value *value_ptr,
60 message_arg_t *dbusv_ptr)
62 switch (type)
64 case JackParamInt:
65 dbusv_ptr->int32 = (dbus_int32_t)value_ptr->i;
66 return true;
67 case JackParamUInt:
68 dbusv_ptr->uint32 = (dbus_uint32_t)value_ptr->ui;
69 return true;
70 case JackParamChar:
71 dbusv_ptr->byte = value_ptr->c;
72 return true;
73 case JackParamString:
74 dbusv_ptr->string = value_ptr->str;
75 return true;
76 case JackParamBool:
77 dbusv_ptr->boolean = (dbus_bool_t)value_ptr->b;
78 return true;
81 jack_error("Unknown JACK parameter type %i", (int)type);
82 assert(0);
83 return false;
86 static
87 bool
88 jack_controller_dbus_to_jack_variant(
89 int type,
90 const message_arg_t *dbusv_ptr,
91 union jackctl_parameter_value *value_ptr)
93 size_t len;
95 switch (type)
97 case DBUS_TYPE_INT32:
98 value_ptr->i = dbusv_ptr->int32;
99 return true;
100 case DBUS_TYPE_UINT32:
101 value_ptr->ui = dbusv_ptr->uint32;
102 return true;
103 case DBUS_TYPE_BYTE:
104 value_ptr->c = dbusv_ptr->byte;
105 return true;
106 case DBUS_TYPE_STRING:
107 len = strlen(dbusv_ptr->string);
108 if (len > JACK_PARAM_STRING_MAX)
110 jack_error("Parameter string value is too long (%u)", (unsigned int)len);
111 return false;
113 memcpy(value_ptr->str, dbusv_ptr->string, len + 1);
115 return true;
116 case DBUS_TYPE_BOOLEAN:
117 value_ptr->b = dbusv_ptr->boolean;
118 return true;
121 jack_error("Unknown D-Bus parameter type %i", (int)type);
122 return false;
126 * Construct a return message for a Get[Driver|Engine]ParameterValue method call.
128 * The operation can only fail due to lack of memory, in which case
129 * there's no sense in trying to construct an error return. Instead,
130 * call->reply will be set to NULL and handled in send_method_return().
132 static void
133 jack_dbus_construct_method_return_parameter(
134 struct jack_dbus_method_call * call,
135 dbus_bool_t is_set,
136 int type,
137 const char *signature,
138 message_arg_t default_value,
139 message_arg_t value)
141 DBusMessageIter iter;
143 /* Create a new method return message. */
144 call->reply = dbus_message_new_method_return (call->message);
145 if (!call->reply)
147 goto fail;
150 dbus_message_iter_init_append (call->reply, &iter);
152 /* Append the is_set argument. */
153 if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, (const void *) &is_set))
155 goto fail_unref;
158 /* Append the 'default' and 'value' arguments. */
159 if (!jack_dbus_message_append_variant(&iter, type, signature, &default_value))
161 goto fail_unref;
163 if (!jack_dbus_message_append_variant(&iter, type, signature, &value))
165 goto fail_unref;
168 return;
170 fail_unref:
171 dbus_message_unref (call->reply);
172 call->reply = NULL;
174 fail:
175 jack_error ("Ran out of memory trying to construct method return");
178 static
179 bool
180 jack_controller_dbus_get_parameter_address_ex(
181 struct jack_dbus_method_call * call,
182 DBusMessageIter * iter_ptr,
183 const char ** address_array)
185 const char * signature;
186 DBusMessageIter array_iter;
187 int type;
188 int index;
190 if (!dbus_message_iter_init(call->message, iter_ptr))
192 jack_dbus_error(
193 call,
194 JACK_DBUS_ERROR_INVALID_ARGS,
195 "Invalid arguments to method '%s'. No input arguments found.",
196 call->method_name);
197 return false;
200 signature = dbus_message_iter_get_signature(iter_ptr);
201 if (signature == NULL)
203 jack_error("dbus_message_iter_get_signature() failed");
204 return false;
207 if (strcmp(signature, "as") != 0)
209 jack_dbus_error(
210 call,
211 JACK_DBUS_ERROR_INVALID_ARGS,
212 "Invalid arguments to method '%s'. Input arguments signature '%s', must begin with 'as'.",
213 call->method_name,
214 signature);
215 return false;
218 dbus_message_iter_recurse(iter_ptr, &array_iter);
220 index = 0;
221 while ((type = dbus_message_iter_get_arg_type(&array_iter)) != DBUS_TYPE_INVALID)
223 if (index == PARAM_ADDRESS_SIZE)
225 jack_dbus_error(
226 call,
227 JACK_DBUS_ERROR_INVALID_ARGS,
228 "Invalid arguments to method '%s'. Parameter address array must contain not more than %u elements.",
229 (unsigned int)PARAM_ADDRESS_SIZE,
230 call->method_name);
231 return false;
235 if (type != DBUS_TYPE_STRING)
237 jack_dbus_error(
238 call,
239 JACK_DBUS_ERROR_FATAL,
240 "Internal error when parsing parameter address of method '%s'. Address array element type '%c' is not string type.",
241 call->method_name,
242 type);
243 return false;
246 dbus_message_iter_get_basic(&array_iter, address_array + index);
247 //jack_info("address component: '%s'", address_array[index]);
249 dbus_message_iter_next(&array_iter);
250 index++;
253 while (index < PARAM_ADDRESS_SIZE)
255 address_array[index] = NULL;
256 index++;
259 return true;
262 static
263 bool
264 jack_controller_dbus_get_parameter_address(
265 struct jack_dbus_method_call * call,
266 const char ** address_array)
268 DBusMessageIter iter;
269 bool ret;
271 ret = jack_controller_dbus_get_parameter_address_ex(call, &iter, address_array);
272 if (ret && dbus_message_iter_has_next(&iter))
274 jack_dbus_error(
275 call,
276 JACK_DBUS_ERROR_INVALID_ARGS,
277 "Invalid arguments to method '%s'. Input arguments signature must be 'as'.",
278 call->method_name);
279 return false;
282 return ret;
285 #define controller_ptr ((struct jack_controller *)call->context)
287 static bool append_node_name(void * context, const char * name)
289 return dbus_message_iter_append_basic(context, DBUS_TYPE_STRING, &name);
292 static
293 void
294 jack_controller_dbus_read_container(
295 struct jack_dbus_method_call * call)
297 const char * address[PARAM_ADDRESS_SIZE];
298 dbus_bool_t leaf;
299 DBusMessageIter iter;
300 DBusMessageIter array_iter;
302 //jack_info("jack_controller_dbus_read_container() called");
304 if (!jack_controller_dbus_get_parameter_address(call, address))
306 /* The method call had invalid arguments meaning that
307 * jack_controller_dbus_get_parameter_address() has
308 * constructed an error for us. */
309 return;
312 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
314 /* Create a new method return message. */
315 call->reply = dbus_message_new_method_return(call->message);
316 if (!call->reply)
318 goto oom;
321 dbus_message_iter_init_append(call->reply, &iter);
323 if (!jack_params_check_address(controller_ptr->params, address, false))
325 jack_dbus_error(
326 call,
327 JACK_DBUS_ERROR_INVALID_ARGS,
328 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
329 address[0],
330 address[1],
331 address[2],
332 call->method_name);
333 return;
336 leaf = jack_params_is_leaf_container(controller_ptr->params, address);
337 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &leaf))
339 goto oom_unref;
342 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &array_iter))
344 goto oom_unref;
348 if (!jack_params_iterate_container(controller_ptr->params, address, append_node_name, &array_iter))
350 goto oom_close_unref;
353 dbus_message_iter_close_container(&iter, &array_iter);
355 return;
357 oom_close_unref:
358 dbus_message_iter_close_container(&iter, &array_iter);
360 oom_unref:
361 dbus_message_unref(call->reply);
362 call->reply = NULL;
364 oom:
365 jack_error ("Ran out of memory trying to construct method return");
368 static bool append_parameter(void * context, const struct jack_parameter * param_ptr)
370 DBusMessageIter struct_iter;
371 unsigned char type;
373 /* Open the struct. */
374 if (!dbus_message_iter_open_container(context, DBUS_TYPE_STRUCT, NULL, &struct_iter))
376 goto fail;
379 /* Append parameter type. */
380 type = PARAM_TYPE_JACK_TO_DBUS(param_ptr->type);
381 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE, &type))
383 goto fail_close;
386 /* Append parameter name. */
387 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &param_ptr->name))
389 goto fail_close;
392 /* Append parameter short description. */
393 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &param_ptr->short_decr))
395 goto fail_close;
398 /* Append parameter long description. */
399 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &param_ptr->long_descr))
401 goto fail_close;
404 /* Close the struct. */
405 if (!dbus_message_iter_close_container(context, &struct_iter))
407 goto fail;
410 return true;
412 fail_close:
413 dbus_message_iter_close_container(context, &struct_iter);
415 fail:
416 return false;
419 static
420 void
421 jack_controller_dbus_get_parameters_info(
422 struct jack_dbus_method_call * call)
424 const char * address[PARAM_ADDRESS_SIZE];
425 DBusMessageIter iter, array_iter;
427 //jack_info("jack_controller_dbus_get_parameters_info() called");
429 if (!jack_controller_dbus_get_parameter_address(call, address))
431 /* The method call had invalid arguments meaning that
432 * jack_controller_dbus_get_parameter_address() has
433 * constructed an error for us. */
434 return;
437 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
439 if (!jack_params_check_address(controller_ptr->params, address, true))
441 jack_dbus_error(
442 call,
443 JACK_DBUS_ERROR_INVALID_ARGS,
444 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
445 address[0],
446 address[1],
447 address[2],
448 call->method_name);
449 return;
452 call->reply = dbus_message_new_method_return (call->message);
453 if (!call->reply)
455 goto fail;
458 dbus_message_iter_init_append (call->reply, &iter);
460 /* Open the array. */
461 if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ysss)", &array_iter))
463 goto fail_unref;
466 if (!jack_params_iterate_params(controller_ptr->params, address, append_parameter, &array_iter))
468 goto fail_close_unref;
471 /* Close the array. */
472 if (!dbus_message_iter_close_container (&iter, &array_iter))
474 goto fail_unref;
477 return;
479 fail_close_unref:
480 dbus_message_iter_close_container (&iter, &array_iter);
482 fail_unref:
483 dbus_message_unref (call->reply);
484 call->reply = NULL;
486 fail:
487 jack_error ("Ran out of memory trying to construct method return");
490 static
491 void
492 jack_controller_dbus_get_parameter_info(
493 struct jack_dbus_method_call * call)
495 const char * address[PARAM_ADDRESS_SIZE];
496 const struct jack_parameter * param_ptr;
497 DBusMessageIter iter;
499 //jack_info("jack_controller_dbus_get_parameter_info() called");
501 if (!jack_controller_dbus_get_parameter_address(call, address))
503 /* The method call had invalid arguments meaning that
504 * jack_controller_dbus_get_parameter_address() has
505 * constructed an error for us. */
506 return;
509 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
511 param_ptr = jack_params_get_parameter(controller_ptr->params, address);
512 if (param_ptr == NULL)
514 jack_dbus_error(
515 call,
516 JACK_DBUS_ERROR_INVALID_ARGS,
517 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
518 address[0],
519 address[1],
520 address[2],
521 call->method_name);
522 return;
525 call->reply = dbus_message_new_method_return(call->message);
526 if (!call->reply)
528 goto fail;
531 dbus_message_iter_init_append(call->reply, &iter);
533 if (!append_parameter(&iter, param_ptr))
535 goto fail_unref;
538 return;
540 fail_unref:
541 dbus_message_unref(call->reply);
542 call->reply = NULL;
544 fail:
545 jack_error("Ran out of memory trying to construct method return");
548 static
549 void
550 jack_controller_dbus_get_parameter_constraint(
551 struct jack_dbus_method_call * call)
553 const char * address[PARAM_ADDRESS_SIZE];
554 const struct jack_parameter * param_ptr;
555 uint32_t index;
556 DBusMessageIter iter, array_iter, struct_iter;
557 const char * descr;
558 message_arg_t value;
560 //jack_info("jack_controller_dbus_get_parameter_constraint() called");
562 if (!jack_controller_dbus_get_parameter_address(call, address))
564 /* The method call had invalid arguments meaning that
565 * jack_controller_dbus_get_parameter_address() has
566 * constructed an error for us. */
567 return;
570 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
572 param_ptr = jack_params_get_parameter(controller_ptr->params, address);
573 if (param_ptr == NULL)
575 jack_dbus_error(
576 call,
577 JACK_DBUS_ERROR_INVALID_ARGS,
578 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
579 address[0],
580 address[1],
581 address[2],
582 call->method_name);
583 return;
586 call->reply = dbus_message_new_method_return(call->message);
587 if (!call->reply)
589 goto fail;
592 dbus_message_iter_init_append(call->reply, &iter);
594 if ((param_ptr->constraint_flags & JACK_CONSTRAINT_FLAG_VALID) != 0)
596 value.boolean = param_ptr->constraint_range;
598 else
600 value.boolean = false;
603 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &value))
605 goto fail_unref;
608 if ((param_ptr->constraint_flags & JACK_CONSTRAINT_FLAG_VALID) != 0)
610 value.boolean = (param_ptr->constraint_flags & JACK_CONSTRAINT_FLAG_STRICT) != 0;
613 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &value))
615 goto fail_unref;
618 if ((param_ptr->constraint_flags & JACK_CONSTRAINT_FLAG_VALID) != 0)
620 value.boolean = (param_ptr->constraint_flags & JACK_CONSTRAINT_FLAG_FAKE_VALUE) != 0;
623 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &value))
625 goto fail_unref;
628 /* Open the array. */
629 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(vs)", &array_iter))
631 goto fail_unref;
634 if ((param_ptr->constraint_flags & JACK_CONSTRAINT_FLAG_VALID) == 0)
636 goto close;
639 if (param_ptr->constraint_range)
641 /* Open the struct. */
642 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
644 goto fail_close_unref;
647 jack_controller_jack_to_dbus_variant(param_ptr->type, &param_ptr->constraint.range.min, &value);
649 if (!jack_dbus_message_append_variant(
650 &struct_iter,
651 PARAM_TYPE_JACK_TO_DBUS(param_ptr->type),
652 PARAM_TYPE_JACK_TO_DBUS_SIGNATURE(param_ptr->type),
653 &value))
655 goto fail_close2_unref;
658 descr = "min";
660 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &descr))
662 goto fail_close2_unref;
665 /* Close the struct. */
666 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
668 goto fail_close_unref;
671 /* Open the struct. */
672 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
674 goto fail_close_unref;
677 jack_controller_jack_to_dbus_variant(param_ptr->type, &param_ptr->constraint.range.max, &value);
679 if (!jack_dbus_message_append_variant(
680 &struct_iter,
681 PARAM_TYPE_JACK_TO_DBUS(param_ptr->type),
682 PARAM_TYPE_JACK_TO_DBUS_SIGNATURE(param_ptr->type),
683 &value))
685 goto fail_close2_unref;
688 descr = "max";
690 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &descr))
692 goto fail_close2_unref;
695 /* Close the struct. */
696 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
698 goto fail_close_unref;
701 else
703 /* Append enum values to the array. */
704 for (index = 0 ; index < param_ptr->constraint.enumeration.count ; index++)
706 descr = param_ptr->constraint.enumeration.possible_values_array[index].short_desc;
708 jack_controller_jack_to_dbus_variant(param_ptr->type, &param_ptr->constraint.enumeration.possible_values_array[index].value, &value);
710 /* Open the struct. */
711 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
713 goto fail_close_unref;
716 if (!jack_dbus_message_append_variant(
717 &struct_iter,
718 PARAM_TYPE_JACK_TO_DBUS(param_ptr->type),
719 PARAM_TYPE_JACK_TO_DBUS_SIGNATURE(param_ptr->type),
720 &value))
722 goto fail_close2_unref;
725 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &descr))
727 goto fail_close2_unref;
730 /* Close the struct. */
731 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
733 goto fail_close_unref;
738 close:
739 /* Close the array. */
740 if (!dbus_message_iter_close_container(&iter, &array_iter))
742 goto fail_unref;
745 return;
747 fail_close2_unref:
748 dbus_message_iter_close_container(&array_iter, &struct_iter);
750 fail_close_unref:
751 dbus_message_iter_close_container(&iter, &array_iter);
753 fail_unref:
754 dbus_message_unref(call->reply);
755 call->reply = NULL;
757 fail:
758 jack_error ("Ran out of memory trying to construct method return");
761 static void
762 jack_controller_dbus_get_parameter_value(
763 struct jack_dbus_method_call * call)
765 const char * address[PARAM_ADDRESS_SIZE];
766 const struct jack_parameter * param_ptr;
767 union jackctl_parameter_value jackctl_value;
768 union jackctl_parameter_value jackctl_default_value;
769 message_arg_t value;
770 message_arg_t default_value;
772 //jack_info("jack_controller_dbus_get_parameter_value() called");
774 if (!jack_controller_dbus_get_parameter_address(call, address))
776 /* The method call had invalid arguments meaning that
777 * jack_controller_dbus_get_parameter_address() has
778 * constructed an error for us. */
779 return;
782 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
784 param_ptr = jack_params_get_parameter(controller_ptr->params, address);
785 if (param_ptr == NULL)
787 jack_dbus_error(
788 call,
789 JACK_DBUS_ERROR_INVALID_ARGS,
790 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
791 address[0],
792 address[1],
793 address[2],
794 call->method_name);
795 return;
798 jackctl_default_value = param_ptr->vtable.get_default_value(param_ptr->obj);
799 jackctl_value = param_ptr->vtable.get_value(param_ptr->obj);
801 jack_controller_jack_to_dbus_variant(param_ptr->type, &jackctl_value, &value);
802 jack_controller_jack_to_dbus_variant(param_ptr->type, &jackctl_default_value, &default_value);
804 /* Construct the reply. */
805 jack_dbus_construct_method_return_parameter(
806 call,
807 (dbus_bool_t)(param_ptr->vtable.is_set(param_ptr->obj) ? TRUE : FALSE),
808 PARAM_TYPE_JACK_TO_DBUS(param_ptr->type),
809 PARAM_TYPE_JACK_TO_DBUS_SIGNATURE(param_ptr->type),
810 default_value,
811 value);
814 static
815 void
816 jack_controller_dbus_set_parameter_value(
817 struct jack_dbus_method_call * call)
819 const char * address[PARAM_ADDRESS_SIZE];
820 const struct jack_parameter * param_ptr;
821 DBusMessageIter iter;
822 DBusMessageIter variant_iter;
823 message_arg_t arg;
824 int arg_type;
825 union jackctl_parameter_value value;
827 //jack_info("jack_controller_dbus_set_parameter_value() called");
829 if (!jack_controller_dbus_get_parameter_address_ex(call, &iter, address))
831 /* The method call had invalid arguments meaning that
832 * jack_controller_dbus_get_parameter_address() has
833 * constructed an error for us. */
834 return;
837 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
839 param_ptr = jack_params_get_parameter(controller_ptr->params, address);
840 if (param_ptr == NULL)
842 jack_dbus_error(
843 call,
844 JACK_DBUS_ERROR_INVALID_ARGS,
845 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
846 address[0],
847 address[1],
848 address[2],
849 call->method_name);
850 return;
853 dbus_message_iter_next(&iter);
855 if (dbus_message_iter_has_next(&iter))
857 jack_dbus_error(
858 call,
859 JACK_DBUS_ERROR_INVALID_ARGS,
860 "Invalid arguments to method '%s'. Too many arguments.",
861 call->method_name);
862 return;
865 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
867 jack_dbus_error(
868 call,
869 JACK_DBUS_ERROR_INVALID_ARGS,
870 "Invalid arguments to method '%s'. Value to set must be variant.",
871 call->method_name);
872 return;
875 dbus_message_iter_recurse (&iter, &variant_iter);
876 dbus_message_iter_get_basic(&variant_iter, &arg);
877 arg_type = dbus_message_iter_get_arg_type(&variant_iter);
879 //jack_info("argument of type '%c'", arg_type);
881 if (PARAM_TYPE_JACK_TO_DBUS(param_ptr->type) != arg_type)
883 jack_dbus_error(
884 call,
885 JACK_DBUS_ERROR_INVALID_ARGS,
886 "Parameter value type mismatch: was expecting '%c', got '%c'",
887 (char)PARAM_TYPE_JACK_TO_DBUS(param_ptr->type),
888 (char)arg_type);
889 return;
892 if (!jack_controller_dbus_to_jack_variant(
893 arg_type,
894 &arg,
895 &value))
897 jack_dbus_error(
898 call,
899 JACK_DBUS_ERROR_INVALID_ARGS,
900 "Cannot convert parameter value");
901 return;
904 param_ptr->vtable.set_value(param_ptr->obj, &value);
906 jack_controller_pending_save(controller_ptr);
908 jack_dbus_construct_method_return_empty(call);
912 static
913 void
914 jack_controller_dbus_reset_parameter_value(
915 struct jack_dbus_method_call * call)
917 const char * address[PARAM_ADDRESS_SIZE];
918 const struct jack_parameter * param_ptr;
920 //jack_info("jack_controller_dbus_reset_parameter_value() called");
922 if (!jack_controller_dbus_get_parameter_address(call, address))
924 /* The method call had invalid arguments meaning that
925 * jack_controller_dbus_get_parameter_address() has
926 * constructed an error for us. */
927 return;
930 //jack_info("address is '%s':'%s':'%s'", address[0], address[1], address[2]);
932 param_ptr = jack_params_get_parameter(controller_ptr->params, address);
933 if (param_ptr == NULL)
935 jack_dbus_error(
936 call,
937 JACK_DBUS_ERROR_INVALID_ARGS,
938 "Invalid container address '%s':'%s':'%s' supplied to method '%s'.",
939 address[0],
940 address[1],
941 address[2],
942 call->method_name);
943 return;
946 param_ptr->vtable.reset(param_ptr->obj);
948 jack_controller_pending_save(controller_ptr);
950 jack_dbus_construct_method_return_empty(call);
953 #undef controller_ptr
955 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(ReadContainer, "Get names of child parameters or containers")
956 JACK_DBUS_METHOD_ARGUMENT_IN("parent", "as", "Address of parent container")
957 JACK_DBUS_METHOD_ARGUMENT_OUT("leaf", "b", "Whether children are parameters (true) or containers (false)")
958 JACK_DBUS_METHOD_ARGUMENT_OUT("children", "as", "Array of child names")
959 JACK_DBUS_METHOD_ARGUMENTS_END
961 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(GetParametersInfo, "Retrieve info about parameters")
962 JACK_DBUS_METHOD_ARGUMENT_IN("parent", "as", "Address of parameters parent")
963 JACK_DBUS_METHOD_ARGUMENT_OUT("parameter_info_array", "a(ysss)", "Array of parameter info structs. Each info struct contains: type char, name, short and long description")
964 JACK_DBUS_METHOD_ARGUMENTS_END
966 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(GetParameterInfo, "Retrieve info about parameter")
967 JACK_DBUS_METHOD_ARGUMENT_IN("parameter", "as", "Address of parameter")
968 JACK_DBUS_METHOD_ARGUMENT_OUT("parameter_info", "(ysss)", "Parameter info struct that contains: type char, name, short and long description")
969 JACK_DBUS_METHOD_ARGUMENTS_END
971 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(GetParameterConstraint, "Get constraint of parameter")
972 JACK_DBUS_METHOD_ARGUMENT_IN("parameter", "as", "Address of parameter")
973 JACK_DBUS_METHOD_ARGUMENT_OUT("is_range", "b", "Whether constrinat is a range. If so, values parameter will contain two values, min and max")
974 JACK_DBUS_METHOD_ARGUMENT_OUT("is_strict", "b", "Whether enum constraint is strict. I.e. value not listed in values array will not work")
975 JACK_DBUS_METHOD_ARGUMENT_OUT("is_fake_value", "b", "Whether enum values are fake. I.e. have no user meaningful meaning")
976 JACK_DBUS_METHOD_ARGUMENT_OUT("values", "a(vs)", "Values. If there is no constraint, this array will be empty. For range constraint there will be two values, min and max. For enum constraint there will be 2 or more values.")
977 JACK_DBUS_METHOD_ARGUMENTS_END
979 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(GetParameterValue, "Get value of parameter")
980 JACK_DBUS_METHOD_ARGUMENT_IN("parameter", "as", "Address of parameter")
981 JACK_DBUS_METHOD_ARGUMENT_OUT("is_set", "b", "Whether parameter is set or its default value is used")
982 JACK_DBUS_METHOD_ARGUMENT_OUT("default", "v", "Default value of parameter")
983 JACK_DBUS_METHOD_ARGUMENT_OUT("value", "v", "Actual value of parameter")
984 JACK_DBUS_METHOD_ARGUMENTS_END
986 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(SetParameterValue, "Set value of parameter")
987 JACK_DBUS_METHOD_ARGUMENT_IN("parameter", "as", "Address of parameter")
988 JACK_DBUS_METHOD_ARGUMENT_IN("value", "v", "New value for parameter")
989 JACK_DBUS_METHOD_ARGUMENTS_END
991 JACK_DBUS_METHOD_ARGUMENTS_BEGIN_EX(ResetParameterValue, "Reset parameter to default value")
992 JACK_DBUS_METHOD_ARGUMENT_IN("parameter", "as", "Address of parameter")
993 JACK_DBUS_METHOD_ARGUMENTS_END
995 JACK_DBUS_METHODS_BEGIN
996 JACK_DBUS_METHOD_DESCRIBE(ReadContainer, jack_controller_dbus_read_container)
997 JACK_DBUS_METHOD_DESCRIBE(GetParametersInfo, jack_controller_dbus_get_parameters_info)
998 JACK_DBUS_METHOD_DESCRIBE(GetParameterInfo, jack_controller_dbus_get_parameter_info)
999 JACK_DBUS_METHOD_DESCRIBE(GetParameterConstraint, jack_controller_dbus_get_parameter_constraint)
1000 JACK_DBUS_METHOD_DESCRIBE(GetParameterValue, jack_controller_dbus_get_parameter_value)
1001 JACK_DBUS_METHOD_DESCRIBE(SetParameterValue, jack_controller_dbus_set_parameter_value)
1002 JACK_DBUS_METHOD_DESCRIBE(ResetParameterValue, jack_controller_dbus_reset_parameter_value)
1003 JACK_DBUS_METHODS_END
1006 * Parameter addresses:
1008 * "engine"
1009 * "engine", "driver"
1010 * "engine", "realtime"
1011 * "engine", ...more engine parameters
1013 * "driver", "device"
1014 * "driver", ...more driver parameters
1016 * "drivers", "alsa", "device"
1017 * "drivers", "alsa", ...more alsa driver parameters
1019 * "drivers", ...more drivers
1021 * "internals", "netmanager", "multicast_ip"
1022 * "internals", "netmanager", ...more netmanager parameters
1024 * "internals", ...more internals
1028 JACK_DBUS_IFACE_BEGIN(g_jack_controller_iface_configure, "org.jackaudio.Configure")
1029 JACK_DBUS_IFACE_EXPOSE_METHODS
1030 JACK_DBUS_IFACE_END