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.

1253 lines
35KB

  1. /* -*- Mode: C ; c-basic-offset: 4 -*- */
  2. /*
  3. Copyright (C) 2007,2008 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. #include <stdbool.h>
  16. #include <stdint.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <dbus/dbus.h>
  20. #include "controller_internal.h"
  21. void
  22. jack_controller_settings_set_bool_option(
  23. const char *value_str,
  24. int *value_ptr)
  25. {
  26. if (strcmp(value_str, "true") == 0)
  27. {
  28. *value_ptr = true;
  29. }
  30. else if (strcmp(value_str, "false") == 0)
  31. {
  32. *value_ptr = false;
  33. }
  34. else
  35. {
  36. jack_error("ignoring unknown bool value \"%s\"", value_str);
  37. }
  38. }
  39. void
  40. jack_controller_settings_set_sint_option(
  41. const char *value_str,
  42. int *value_ptr)
  43. {
  44. *value_ptr = atoi(value_str);
  45. }
  46. void
  47. jack_controller_settings_set_uint_option(
  48. const char *value_str,
  49. unsigned int *value_ptr)
  50. {
  51. *value_ptr = strtoul(value_str, NULL, 10);
  52. }
  53. void
  54. jack_controller_settings_set_char_option(
  55. const char *value_str,
  56. char *value_ptr)
  57. {
  58. if (value_str[0] == 0 || value_str[1] != 0)
  59. {
  60. jack_error("invalid char option value \"%s\"", value_str);
  61. return;
  62. }
  63. *value_ptr = *value_str;
  64. }
  65. void
  66. jack_controller_settings_set_string_option(
  67. const char *value_str,
  68. char *value_ptr,
  69. size_t max_size)
  70. {
  71. size_t size;
  72. size = strlen(value_str);
  73. if (size >= max_size)
  74. {
  75. jack_error("string option value \"%s\" is too long, max is %u chars (including terminating zero)", value_str, (unsigned int)max_size);
  76. return;
  77. }
  78. strcpy(value_ptr, value_str);
  79. }
  80. void
  81. jack_controller_settings_set_driver_option(
  82. jackctl_driver_t *driver,
  83. const char *option_name,
  84. const char *option_value)
  85. {
  86. jackctl_parameter_t *parameter;
  87. jackctl_param_type_t type;
  88. int value_int;
  89. unsigned int value_uint;
  90. union jackctl_parameter_value value;
  91. jack_info("setting driver option \"%s\" to value \"%s\"", option_name, option_value);
  92. parameter = jack_controller_find_parameter(jackctl_driver_get_parameters(driver), option_name);
  93. if (parameter == NULL)
  94. {
  95. jack_error(
  96. "Unknown parameter \"%s\" of driver \"%s\"",
  97. option_name,
  98. jackctl_driver_get_name(driver));
  99. return;
  100. }
  101. type = jackctl_parameter_get_type(parameter);
  102. switch (type)
  103. {
  104. case JackParamInt:
  105. jack_controller_settings_set_sint_option(option_value, &value_int);
  106. value.i = value_int;
  107. break;
  108. case JackParamUInt:
  109. jack_controller_settings_set_uint_option(option_value, &value_uint);
  110. value.ui = value_uint;
  111. break;
  112. case JackParamChar:
  113. jack_controller_settings_set_char_option(option_value, &value.c);
  114. break;
  115. case JackParamString:
  116. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  117. break;
  118. case JackParamBool:
  119. jack_controller_settings_set_bool_option(option_value, &value_int);
  120. value.i = value_int;
  121. break;
  122. default:
  123. jack_error("Parameter \"%s\" of driver \"%s\" is of unknown type %d",
  124. jackctl_parameter_get_name(parameter),
  125. jackctl_driver_get_name(driver),
  126. type);
  127. }
  128. jackctl_parameter_set_value(parameter, &value);
  129. }
  130. void
  131. jack_controller_settings_set_engine_option(
  132. struct jack_controller *controller_ptr,
  133. const char *option_name,
  134. const char *option_value)
  135. {
  136. jackctl_parameter_t *parameter;
  137. jackctl_param_type_t type;
  138. int value_int;
  139. unsigned int value_uint;
  140. union jackctl_parameter_value value;
  141. jack_info("setting engine option \"%s\" to value \"%s\"", option_name, option_value);
  142. if (strcmp(option_name, "driver") == 0)
  143. {
  144. if (!jack_controller_select_driver(controller_ptr, option_value))
  145. {
  146. jack_error("unknown driver '%s'", option_value);
  147. }
  148. return;
  149. }
  150. parameter = jack_controller_find_parameter(jackctl_server_get_parameters(controller_ptr->server), option_name);
  151. if (parameter == NULL)
  152. {
  153. jack_error(
  154. "Unknown engine parameter \"%s\"",
  155. option_name);
  156. return;
  157. }
  158. type = jackctl_parameter_get_type(parameter);
  159. switch (type)
  160. {
  161. case JackParamInt:
  162. jack_controller_settings_set_sint_option(option_value, &value_int);
  163. value.i = value_int;
  164. break;
  165. case JackParamUInt:
  166. jack_controller_settings_set_uint_option(option_value, &value_uint);
  167. value.ui = value_uint;
  168. break;
  169. case JackParamChar:
  170. jack_controller_settings_set_char_option(option_value, &value.c);
  171. break;
  172. case JackParamString:
  173. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  174. break;
  175. case JackParamBool:
  176. jack_controller_settings_set_bool_option(option_value, &value_int);
  177. value.i = value_int;
  178. break;
  179. default:
  180. jack_error("Engine parameter \"%s\" is of unknown type %d",
  181. jackctl_parameter_get_name(parameter),
  182. type);
  183. }
  184. jackctl_parameter_set_value(parameter, &value);
  185. }
  186. static
  187. bool
  188. jack_controller_settings_save_options(
  189. void *context,
  190. const JSList * parameters_list,
  191. void *dbus_call_context_ptr)
  192. {
  193. jackctl_parameter_t *parameter;
  194. jackctl_param_type_t type;
  195. union jackctl_parameter_value value;
  196. const char * name;
  197. char value_str[50];
  198. while (parameters_list != NULL)
  199. {
  200. parameter = (jackctl_parameter_t *)parameters_list->data;
  201. if (jackctl_parameter_is_set(parameter))
  202. {
  203. type = jackctl_parameter_get_type(parameter);
  204. value = jackctl_parameter_get_value(parameter);
  205. name = jackctl_parameter_get_name(parameter);
  206. switch (type)
  207. {
  208. case JackParamInt:
  209. sprintf(value_str, "%d", (int)value.i);
  210. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  211. {
  212. return false;
  213. }
  214. break;
  215. case JackParamUInt:
  216. sprintf(value_str, "%u", (unsigned int)value.ui);
  217. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  218. {
  219. return false;
  220. }
  221. break;
  222. case JackParamChar:
  223. sprintf(value_str, "%c", (char)value.c);
  224. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  225. {
  226. return false;
  227. }
  228. break;
  229. case JackParamString:
  230. if (!jack_controller_settings_write_option(context, name, value.str, dbus_call_context_ptr))
  231. {
  232. return false;
  233. }
  234. break;
  235. case JackParamBool:
  236. if (!jack_controller_settings_write_option(context, name, value.b ? "true" : "false", dbus_call_context_ptr))
  237. {
  238. return false;
  239. }
  240. break;
  241. default:
  242. jack_error("parameter of unknown type %d", type);
  243. }
  244. }
  245. parameters_list = jack_slist_next(parameters_list);
  246. }
  247. return true;
  248. }
  249. bool
  250. jack_controller_settings_save_engine_options(
  251. void *context,
  252. struct jack_controller *controller_ptr,
  253. void *dbus_call_context_ptr)
  254. {
  255. if (controller_ptr->driver != NULL)
  256. {
  257. if (!jack_controller_settings_write_option(
  258. context,
  259. "driver",
  260. jackctl_driver_get_name(controller_ptr->driver),
  261. dbus_call_context_ptr))
  262. {
  263. return false;
  264. }
  265. }
  266. return jack_controller_settings_save_options(context, jackctl_server_get_parameters(controller_ptr->server), dbus_call_context_ptr);
  267. }
  268. bool
  269. jack_controller_settings_save_driver_options(
  270. void *context,
  271. jackctl_driver_t *driver,
  272. void *dbus_call_context_ptr)
  273. {
  274. return jack_controller_settings_save_options(context, jackctl_driver_get_parameters(driver), dbus_call_context_ptr);
  275. }
  276. /* -*- Mode: C ; c-basic-offset: 4 -*- */
  277. /*
  278. Copyright (C) 2007,2008 Nedko Arnaudov
  279. This program is free software; you can redistribute it and/or modify
  280. it under the terms of the GNU General Public License as published by
  281. the Free Software Foundation; either version 2 of the License.
  282. This program is distributed in the hope that it will be useful,
  283. but WITHOUT ANY WARRANTY; without even the implied warranty of
  284. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  285. GNU General Public License for more details.
  286. You should have received a copy of the GNU General Public License
  287. along with this program; if not, write to the Free Software
  288. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  289. */
  290. #include <stdbool.h>
  291. #include <stdint.h>
  292. #include <string.h>
  293. #include <stdio.h>
  294. #include <dbus/dbus.h>
  295. #include "controller_internal.h"
  296. void
  297. jack_controller_settings_set_bool_option(
  298. const char *value_str,
  299. int *value_ptr)
  300. {
  301. if (strcmp(value_str, "true") == 0)
  302. {
  303. *value_ptr = true;
  304. }
  305. else if (strcmp(value_str, "false") == 0)
  306. {
  307. *value_ptr = false;
  308. }
  309. else
  310. {
  311. jack_error("ignoring unknown bool value \"%s\"", value_str);
  312. }
  313. }
  314. void
  315. jack_controller_settings_set_sint_option(
  316. const char *value_str,
  317. int *value_ptr)
  318. {
  319. *value_ptr = atoi(value_str);
  320. }
  321. void
  322. jack_controller_settings_set_uint_option(
  323. const char *value_str,
  324. unsigned int *value_ptr)
  325. {
  326. *value_ptr = strtoul(value_str, NULL, 10);
  327. }
  328. void
  329. jack_controller_settings_set_char_option(
  330. const char *value_str,
  331. char *value_ptr)
  332. {
  333. if (value_str[0] == 0 || value_str[1] != 0)
  334. {
  335. jack_error("invalid char option value \"%s\"", value_str);
  336. return;
  337. }
  338. *value_ptr = *value_str;
  339. }
  340. void
  341. jack_controller_settings_set_string_option(
  342. const char *value_str,
  343. char *value_ptr,
  344. size_t max_size)
  345. {
  346. size_t size;
  347. size = strlen(value_str);
  348. if (size >= max_size)
  349. {
  350. jack_error("string option value \"%s\" is too long, max is %u chars (including terminating zero)", value_str, (unsigned int)max_size);
  351. return;
  352. }
  353. strcpy(value_ptr, value_str);
  354. }
  355. void
  356. jack_controller_settings_set_driver_option(
  357. jackctl_driver_t *driver,
  358. const char *option_name,
  359. const char *option_value)
  360. {
  361. jackctl_parameter_t *parameter;
  362. jackctl_param_type_t type;
  363. int value_int;
  364. unsigned int value_uint;
  365. union jackctl_parameter_value value;
  366. jack_info("setting driver option \"%s\" to value \"%s\"", option_name, option_value);
  367. parameter = jack_controller_find_parameter(jackctl_driver_get_parameters(driver), option_name);
  368. if (parameter == NULL)
  369. {
  370. jack_error(
  371. "Unknown parameter \"%s\" of driver \"%s\"",
  372. option_name,
  373. jackctl_driver_get_name(driver));
  374. return;
  375. }
  376. type = jackctl_parameter_get_type(parameter);
  377. switch (type)
  378. {
  379. case JackParamInt:
  380. jack_controller_settings_set_sint_option(option_value, &value_int);
  381. value.i = value_int;
  382. break;
  383. case JackParamUInt:
  384. jack_controller_settings_set_uint_option(option_value, &value_uint);
  385. value.ui = value_uint;
  386. break;
  387. case JackParamChar:
  388. jack_controller_settings_set_char_option(option_value, &value.c);
  389. break;
  390. case JackParamString:
  391. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  392. break;
  393. case JackParamBool:
  394. jack_controller_settings_set_bool_option(option_value, &value_int);
  395. value.i = value_int;
  396. break;
  397. default:
  398. jack_error("Parameter \"%s\" of driver \"%s\" is of unknown type %d",
  399. jackctl_parameter_get_name(parameter),
  400. jackctl_driver_get_name(driver),
  401. type);
  402. }
  403. jackctl_parameter_set_value(parameter, &value);
  404. }
  405. void
  406. jack_controller_settings_set_engine_option(
  407. struct jack_controller *controller_ptr,
  408. const char *option_name,
  409. const char *option_value)
  410. {
  411. jackctl_parameter_t *parameter;
  412. jackctl_param_type_t type;
  413. int value_int;
  414. unsigned int value_uint;
  415. union jackctl_parameter_value value;
  416. jack_info("setting engine option \"%s\" to value \"%s\"", option_name, option_value);
  417. if (strcmp(option_name, "driver") == 0)
  418. {
  419. if (!jack_controller_select_driver(controller_ptr, option_value))
  420. {
  421. jack_error("unknown driver '%s'", option_value);
  422. }
  423. return;
  424. }
  425. parameter = jack_controller_find_parameter(jackctl_server_get_parameters(controller_ptr->server), option_name);
  426. if (parameter == NULL)
  427. {
  428. jack_error(
  429. "Unknown engine parameter \"%s\"",
  430. option_name);
  431. return;
  432. }
  433. type = jackctl_parameter_get_type(parameter);
  434. switch (type)
  435. {
  436. case JackParamInt:
  437. jack_controller_settings_set_sint_option(option_value, &value_int);
  438. value.i = value_int;
  439. break;
  440. case JackParamUInt:
  441. jack_controller_settings_set_uint_option(option_value, &value_uint);
  442. value.ui = value_uint;
  443. break;
  444. case JackParamChar:
  445. jack_controller_settings_set_char_option(option_value, &value.c);
  446. break;
  447. case JackParamString:
  448. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  449. break;
  450. case JackParamBool:
  451. jack_controller_settings_set_bool_option(option_value, &value_int);
  452. value.i = value_int;
  453. break;
  454. default:
  455. jack_error("Engine parameter \"%s\" is of unknown type %d",
  456. jackctl_parameter_get_name(parameter),
  457. type);
  458. }
  459. jackctl_parameter_set_value(parameter, &value);
  460. }
  461. static
  462. bool
  463. jack_controller_settings_save_options(
  464. void *context,
  465. const JSList * parameters_list,
  466. void *dbus_call_context_ptr)
  467. {
  468. jackctl_parameter_t *parameter;
  469. jackctl_param_type_t type;
  470. union jackctl_parameter_value value;
  471. const char * name;
  472. char value_str[50];
  473. while (parameters_list != NULL)
  474. {
  475. parameter = (jackctl_parameter_t *)parameters_list->data;
  476. if (jackctl_parameter_is_set(parameter))
  477. {
  478. type = jackctl_parameter_get_type(parameter);
  479. value = jackctl_parameter_get_value(parameter);
  480. name = jackctl_parameter_get_name(parameter);
  481. switch (type)
  482. {
  483. case JackParamInt:
  484. sprintf(value_str, "%d", (int)value.i);
  485. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  486. {
  487. return false;
  488. }
  489. break;
  490. case JackParamUInt:
  491. sprintf(value_str, "%u", (unsigned int)value.ui);
  492. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  493. {
  494. return false;
  495. }
  496. break;
  497. case JackParamChar:
  498. sprintf(value_str, "%c", (char)value.c);
  499. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  500. {
  501. return false;
  502. }
  503. break;
  504. case JackParamString:
  505. if (!jack_controller_settings_write_option(context, name, value.str, dbus_call_context_ptr))
  506. {
  507. return false;
  508. }
  509. break;
  510. case JackParamBool:
  511. if (!jack_controller_settings_write_option(context, name, value.b ? "true" : "false", dbus_call_context_ptr))
  512. {
  513. return false;
  514. }
  515. break;
  516. default:
  517. jack_error("parameter of unknown type %d", type);
  518. }
  519. }
  520. parameters_list = jack_slist_next(parameters_list);
  521. }
  522. return true;
  523. }
  524. bool
  525. jack_controller_settings_save_engine_options(
  526. void *context,
  527. struct jack_controller *controller_ptr,
  528. void *dbus_call_context_ptr)
  529. {
  530. if (controller_ptr->driver != NULL)
  531. {
  532. if (!jack_controller_settings_write_option(
  533. context,
  534. "driver",
  535. jackctl_driver_get_name(controller_ptr->driver),
  536. dbus_call_context_ptr))
  537. {
  538. return false;
  539. }
  540. }
  541. return jack_controller_settings_save_options(context, jackctl_server_get_parameters(controller_ptr->server), dbus_call_context_ptr);
  542. }
  543. bool
  544. jack_controller_settings_save_driver_options(
  545. void *context,
  546. jackctl_driver_t *driver,
  547. void *dbus_call_context_ptr)
  548. {
  549. return jack_controller_settings_save_options(context, jackctl_driver_get_parameters(driver), dbus_call_context_ptr);
  550. }
  551. /* -*- Mode: C ; c-basic-offset: 4 -*- */
  552. /*
  553. Copyright (C) 2007,2008 Nedko Arnaudov
  554. This program is free software; you can redistribute it and/or modify
  555. it under the terms of the GNU General Public License as published by
  556. the Free Software Foundation; either version 2 of the License.
  557. This program is distributed in the hope that it will be useful,
  558. but WITHOUT ANY WARRANTY; without even the implied warranty of
  559. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  560. GNU General Public License for more details.
  561. You should have received a copy of the GNU General Public License
  562. along with this program; if not, write to the Free Software
  563. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  564. */
  565. #include <stdbool.h>
  566. #include <stdint.h>
  567. #include <string.h>
  568. #include <stdio.h>
  569. #include <dbus/dbus.h>
  570. #include "controller_internal.h"
  571. void
  572. jack_controller_settings_set_bool_option(
  573. const char *value_str,
  574. int *value_ptr)
  575. {
  576. if (strcmp(value_str, "true") == 0)
  577. {
  578. *value_ptr = true;
  579. }
  580. else if (strcmp(value_str, "false") == 0)
  581. {
  582. *value_ptr = false;
  583. }
  584. else
  585. {
  586. jack_error("ignoring unknown bool value \"%s\"", value_str);
  587. }
  588. }
  589. void
  590. jack_controller_settings_set_sint_option(
  591. const char *value_str,
  592. int *value_ptr)
  593. {
  594. *value_ptr = atoi(value_str);
  595. }
  596. void
  597. jack_controller_settings_set_uint_option(
  598. const char *value_str,
  599. unsigned int *value_ptr)
  600. {
  601. *value_ptr = strtoul(value_str, NULL, 10);
  602. }
  603. void
  604. jack_controller_settings_set_char_option(
  605. const char *value_str,
  606. char *value_ptr)
  607. {
  608. if (value_str[0] == 0 || value_str[1] != 0)
  609. {
  610. jack_error("invalid char option value \"%s\"", value_str);
  611. return;
  612. }
  613. *value_ptr = *value_str;
  614. }
  615. void
  616. jack_controller_settings_set_string_option(
  617. const char *value_str,
  618. char *value_ptr,
  619. size_t max_size)
  620. {
  621. size_t size;
  622. size = strlen(value_str);
  623. if (size >= max_size)
  624. {
  625. jack_error("string option value \"%s\" is too long, max is %u chars (including terminating zero)", value_str, (unsigned int)max_size);
  626. return;
  627. }
  628. strcpy(value_ptr, value_str);
  629. }
  630. void
  631. jack_controller_settings_set_driver_option(
  632. jackctl_driver_t *driver,
  633. const char *option_name,
  634. const char *option_value)
  635. {
  636. jackctl_parameter_t *parameter;
  637. jackctl_param_type_t type;
  638. int value_int;
  639. unsigned int value_uint;
  640. union jackctl_parameter_value value;
  641. jack_info("setting driver option \"%s\" to value \"%s\"", option_name, option_value);
  642. parameter = jack_controller_find_parameter(jackctl_driver_get_parameters(driver), option_name);
  643. if (parameter == NULL)
  644. {
  645. jack_error(
  646. "Unknown parameter \"%s\" of driver \"%s\"",
  647. option_name,
  648. jackctl_driver_get_name(driver));
  649. return;
  650. }
  651. type = jackctl_parameter_get_type(parameter);
  652. switch (type)
  653. {
  654. case JackParamInt:
  655. jack_controller_settings_set_sint_option(option_value, &value_int);
  656. value.i = value_int;
  657. break;
  658. case JackParamUInt:
  659. jack_controller_settings_set_uint_option(option_value, &value_uint);
  660. value.ui = value_uint;
  661. break;
  662. case JackParamChar:
  663. jack_controller_settings_set_char_option(option_value, &value.c);
  664. break;
  665. case JackParamString:
  666. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  667. break;
  668. case JackParamBool:
  669. jack_controller_settings_set_bool_option(option_value, &value_int);
  670. value.i = value_int;
  671. break;
  672. default:
  673. jack_error("Parameter \"%s\" of driver \"%s\" is of unknown type %d",
  674. jackctl_parameter_get_name(parameter),
  675. jackctl_driver_get_name(driver),
  676. type);
  677. }
  678. jackctl_parameter_set_value(parameter, &value);
  679. }
  680. void
  681. jack_controller_settings_set_engine_option(
  682. struct jack_controller *controller_ptr,
  683. const char *option_name,
  684. const char *option_value)
  685. {
  686. jackctl_parameter_t *parameter;
  687. jackctl_param_type_t type;
  688. int value_int;
  689. unsigned int value_uint;
  690. union jackctl_parameter_value value;
  691. jack_info("setting engine option \"%s\" to value \"%s\"", option_name, option_value);
  692. if (strcmp(option_name, "driver") == 0)
  693. {
  694. if (!jack_controller_select_driver(controller_ptr, option_value))
  695. {
  696. jack_error("unknown driver '%s'", option_value);
  697. }
  698. return;
  699. }
  700. parameter = jack_controller_find_parameter(jackctl_server_get_parameters(controller_ptr->server), option_name);
  701. if (parameter == NULL)
  702. {
  703. jack_error(
  704. "Unknown engine parameter \"%s\"",
  705. option_name);
  706. return;
  707. }
  708. type = jackctl_parameter_get_type(parameter);
  709. switch (type)
  710. {
  711. case JackParamInt:
  712. jack_controller_settings_set_sint_option(option_value, &value_int);
  713. value.i = value_int;
  714. break;
  715. case JackParamUInt:
  716. jack_controller_settings_set_uint_option(option_value, &value_uint);
  717. value.ui = value_uint;
  718. break;
  719. case JackParamChar:
  720. jack_controller_settings_set_char_option(option_value, &value.c);
  721. break;
  722. case JackParamString:
  723. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  724. break;
  725. case JackParamBool:
  726. jack_controller_settings_set_bool_option(option_value, &value_int);
  727. value.i = value_int;
  728. break;
  729. default:
  730. jack_error("Engine parameter \"%s\" is of unknown type %d",
  731. jackctl_parameter_get_name(parameter),
  732. type);
  733. }
  734. jackctl_parameter_set_value(parameter, &value);
  735. }
  736. static
  737. bool
  738. jack_controller_settings_save_options(
  739. void *context,
  740. const JSList * parameters_list,
  741. void *dbus_call_context_ptr)
  742. {
  743. jackctl_parameter_t *parameter;
  744. jackctl_param_type_t type;
  745. union jackctl_parameter_value value;
  746. const char * name;
  747. char value_str[50];
  748. while (parameters_list != NULL)
  749. {
  750. parameter = (jackctl_parameter_t *)parameters_list->data;
  751. if (jackctl_parameter_is_set(parameter))
  752. {
  753. type = jackctl_parameter_get_type(parameter);
  754. value = jackctl_parameter_get_value(parameter);
  755. name = jackctl_parameter_get_name(parameter);
  756. switch (type)
  757. {
  758. case JackParamInt:
  759. sprintf(value_str, "%d", (int)value.i);
  760. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  761. {
  762. return false;
  763. }
  764. break;
  765. case JackParamUInt:
  766. sprintf(value_str, "%u", (unsigned int)value.ui);
  767. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  768. {
  769. return false;
  770. }
  771. break;
  772. case JackParamChar:
  773. sprintf(value_str, "%c", (char)value.c);
  774. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  775. {
  776. return false;
  777. }
  778. break;
  779. case JackParamString:
  780. if (!jack_controller_settings_write_option(context, name, value.str, dbus_call_context_ptr))
  781. {
  782. return false;
  783. }
  784. break;
  785. case JackParamBool:
  786. if (!jack_controller_settings_write_option(context, name, value.b ? "true" : "false", dbus_call_context_ptr))
  787. {
  788. return false;
  789. }
  790. break;
  791. default:
  792. jack_error("parameter of unknown type %d", type);
  793. }
  794. }
  795. parameters_list = jack_slist_next(parameters_list);
  796. }
  797. return true;
  798. }
  799. bool
  800. jack_controller_settings_save_engine_options(
  801. void *context,
  802. struct jack_controller *controller_ptr,
  803. void *dbus_call_context_ptr)
  804. {
  805. if (controller_ptr->driver != NULL)
  806. {
  807. if (!jack_controller_settings_write_option(
  808. context,
  809. "driver",
  810. jackctl_driver_get_name(controller_ptr->driver),
  811. dbus_call_context_ptr))
  812. {
  813. return false;
  814. }
  815. }
  816. return jack_controller_settings_save_options(context, jackctl_server_get_parameters(controller_ptr->server), dbus_call_context_ptr);
  817. }
  818. bool
  819. jack_controller_settings_save_driver_options(
  820. void *context,
  821. jackctl_driver_t *driver,
  822. void *dbus_call_context_ptr)
  823. {
  824. return jack_controller_settings_save_options(context, jackctl_driver_get_parameters(driver), dbus_call_context_ptr);
  825. }
  826. /* -*- Mode: C ; c-basic-offset: 4 -*- */
  827. /*
  828. Copyright (C) 2007,2008 Nedko Arnaudov
  829. This program is free software; you can redistribute it and/or modify
  830. it under the terms of the GNU General Public License as published by
  831. the Free Software Foundation; either version 2 of the License.
  832. This program is distributed in the hope that it will be useful,
  833. but WITHOUT ANY WARRANTY; without even the implied warranty of
  834. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  835. GNU General Public License for more details.
  836. You should have received a copy of the GNU General Public License
  837. along with this program; if not, write to the Free Software
  838. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  839. */
  840. #include <stdbool.h>
  841. #include <stdint.h>
  842. #include <string.h>
  843. #include <stdio.h>
  844. #include <dbus/dbus.h>
  845. #include "controller_internal.h"
  846. void
  847. jack_controller_settings_set_bool_option(
  848. const char *value_str,
  849. int *value_ptr)
  850. {
  851. if (strcmp(value_str, "true") == 0)
  852. {
  853. *value_ptr = true;
  854. }
  855. else if (strcmp(value_str, "false") == 0)
  856. {
  857. *value_ptr = false;
  858. }
  859. else
  860. {
  861. jack_error("ignoring unknown bool value \"%s\"", value_str);
  862. }
  863. }
  864. void
  865. jack_controller_settings_set_sint_option(
  866. const char *value_str,
  867. int *value_ptr)
  868. {
  869. *value_ptr = atoi(value_str);
  870. }
  871. void
  872. jack_controller_settings_set_uint_option(
  873. const char *value_str,
  874. unsigned int *value_ptr)
  875. {
  876. *value_ptr = strtoul(value_str, NULL, 10);
  877. }
  878. void
  879. jack_controller_settings_set_char_option(
  880. const char *value_str,
  881. char *value_ptr)
  882. {
  883. if (value_str[0] == 0 || value_str[1] != 0)
  884. {
  885. jack_error("invalid char option value \"%s\"", value_str);
  886. return;
  887. }
  888. *value_ptr = *value_str;
  889. }
  890. void
  891. jack_controller_settings_set_string_option(
  892. const char *value_str,
  893. char *value_ptr,
  894. size_t max_size)
  895. {
  896. size_t size;
  897. size = strlen(value_str);
  898. if (size >= max_size)
  899. {
  900. jack_error("string option value \"%s\" is too long, max is %u chars (including terminating zero)", value_str, (unsigned int)max_size);
  901. return;
  902. }
  903. strcpy(value_ptr, value_str);
  904. }
  905. void
  906. jack_controller_settings_set_driver_option(
  907. jackctl_driver_t *driver,
  908. const char *option_name,
  909. const char *option_value)
  910. {
  911. jackctl_parameter_t *parameter;
  912. jackctl_param_type_t type;
  913. int value_int;
  914. unsigned int value_uint;
  915. union jackctl_parameter_value value;
  916. jack_info("setting driver option \"%s\" to value \"%s\"", option_name, option_value);
  917. parameter = jack_controller_find_parameter(jackctl_driver_get_parameters(driver), option_name);
  918. if (parameter == NULL)
  919. {
  920. jack_error(
  921. "Unknown parameter \"%s\" of driver \"%s\"",
  922. option_name,
  923. jackctl_driver_get_name(driver));
  924. return;
  925. }
  926. type = jackctl_parameter_get_type(parameter);
  927. switch (type)
  928. {
  929. case JackParamInt:
  930. jack_controller_settings_set_sint_option(option_value, &value_int);
  931. value.i = value_int;
  932. break;
  933. case JackParamUInt:
  934. jack_controller_settings_set_uint_option(option_value, &value_uint);
  935. value.ui = value_uint;
  936. break;
  937. case JackParamChar:
  938. jack_controller_settings_set_char_option(option_value, &value.c);
  939. break;
  940. case JackParamString:
  941. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  942. break;
  943. case JackParamBool:
  944. jack_controller_settings_set_bool_option(option_value, &value_int);
  945. value.i = value_int;
  946. break;
  947. default:
  948. jack_error("Parameter \"%s\" of driver \"%s\" is of unknown type %d",
  949. jackctl_parameter_get_name(parameter),
  950. jackctl_driver_get_name(driver),
  951. type);
  952. }
  953. jackctl_parameter_set_value(parameter, &value);
  954. }
  955. void
  956. jack_controller_settings_set_engine_option(
  957. struct jack_controller *controller_ptr,
  958. const char *option_name,
  959. const char *option_value)
  960. {
  961. jackctl_parameter_t *parameter;
  962. jackctl_param_type_t type;
  963. int value_int;
  964. unsigned int value_uint;
  965. union jackctl_parameter_value value;
  966. jack_info("setting engine option \"%s\" to value \"%s\"", option_name, option_value);
  967. if (strcmp(option_name, "driver") == 0)
  968. {
  969. if (!jack_controller_select_driver(controller_ptr, option_value))
  970. {
  971. jack_error("unknown driver '%s'", option_value);
  972. }
  973. return;
  974. }
  975. parameter = jack_controller_find_parameter(jackctl_server_get_parameters(controller_ptr->server), option_name);
  976. if (parameter == NULL)
  977. {
  978. jack_error(
  979. "Unknown engine parameter \"%s\"",
  980. option_name);
  981. return;
  982. }
  983. type = jackctl_parameter_get_type(parameter);
  984. switch (type)
  985. {
  986. case JackParamInt:
  987. jack_controller_settings_set_sint_option(option_value, &value_int);
  988. value.i = value_int;
  989. break;
  990. case JackParamUInt:
  991. jack_controller_settings_set_uint_option(option_value, &value_uint);
  992. value.ui = value_uint;
  993. break;
  994. case JackParamChar:
  995. jack_controller_settings_set_char_option(option_value, &value.c);
  996. break;
  997. case JackParamString:
  998. jack_controller_settings_set_string_option(option_value, value.str, sizeof(value.str));
  999. break;
  1000. case JackParamBool:
  1001. jack_controller_settings_set_bool_option(option_value, &value_int);
  1002. value.i = value_int;
  1003. break;
  1004. default:
  1005. jack_error("Engine parameter \"%s\" is of unknown type %d",
  1006. jackctl_parameter_get_name(parameter),
  1007. type);
  1008. }
  1009. jackctl_parameter_set_value(parameter, &value);
  1010. }
  1011. static
  1012. bool
  1013. jack_controller_settings_save_options(
  1014. void *context,
  1015. const JSList * parameters_list,
  1016. void *dbus_call_context_ptr)
  1017. {
  1018. jackctl_parameter_t *parameter;
  1019. jackctl_param_type_t type;
  1020. union jackctl_parameter_value value;
  1021. const char * name;
  1022. char value_str[50];
  1023. while (parameters_list != NULL)
  1024. {
  1025. parameter = (jackctl_parameter_t *)parameters_list->data;
  1026. if (jackctl_parameter_is_set(parameter))
  1027. {
  1028. type = jackctl_parameter_get_type(parameter);
  1029. value = jackctl_parameter_get_value(parameter);
  1030. name = jackctl_parameter_get_name(parameter);
  1031. switch (type)
  1032. {
  1033. case JackParamInt:
  1034. sprintf(value_str, "%d", (int)value.i);
  1035. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  1036. {
  1037. return false;
  1038. }
  1039. break;
  1040. case JackParamUInt:
  1041. sprintf(value_str, "%u", (unsigned int)value.ui);
  1042. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  1043. {
  1044. return false;
  1045. }
  1046. break;
  1047. case JackParamChar:
  1048. sprintf(value_str, "%c", (char)value.c);
  1049. if (!jack_controller_settings_write_option(context, name, value_str, dbus_call_context_ptr))
  1050. {
  1051. return false;
  1052. }
  1053. break;
  1054. case JackParamString:
  1055. if (!jack_controller_settings_write_option(context, name, value.str, dbus_call_context_ptr))
  1056. {
  1057. return false;
  1058. }
  1059. break;
  1060. case JackParamBool:
  1061. if (!jack_controller_settings_write_option(context, name, value.b ? "true" : "false", dbus_call_context_ptr))
  1062. {
  1063. return false;
  1064. }
  1065. break;
  1066. default:
  1067. jack_error("parameter of unknown type %d", type);
  1068. }
  1069. }
  1070. parameters_list = jack_slist_next(parameters_list);
  1071. }
  1072. return true;
  1073. }
  1074. bool
  1075. jack_controller_settings_save_engine_options(
  1076. void *context,
  1077. struct jack_controller *controller_ptr,
  1078. void *dbus_call_context_ptr)
  1079. {
  1080. if (controller_ptr->driver != NULL)
  1081. {
  1082. if (!jack_controller_settings_write_option(
  1083. context,
  1084. "driver",
  1085. jackctl_driver_get_name(controller_ptr->driver),
  1086. dbus_call_context_ptr))
  1087. {
  1088. return false;
  1089. }
  1090. }
  1091. return jack_controller_settings_save_options(context, jackctl_server_get_parameters(controller_ptr->server), dbus_call_context_ptr);
  1092. }
  1093. bool
  1094. jack_controller_settings_save_driver_options(
  1095. void *context,
  1096. jackctl_driver_t *driver,
  1097. void *dbus_call_context_ptr)
  1098. {
  1099. return jack_controller_settings_save_options(context, jackctl_driver_get_parameters(driver), dbus_call_context_ptr);
  1100. }