jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.8KB

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