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)
26 #include <sys/types.h>
32 #include <dbus/dbus.h>
35 #include "controller_internal.h"
39 jack_controller_settings_write_string(int fd
, const char * string
, void *dbus_call_context_ptr
)
45 if (write(fd
, string
, len
) != len
)
47 jack_dbus_error(dbus_call_context_ptr
, JACK_DBUS_ERROR_GENERIC
, "write() failed to write config file.");
60 #define save_context_ptr ((struct save_context *)context)
61 #define fd (save_context_ptr->fd)
64 jack_controller_settings_write_option(
68 void *dbus_call_context_ptr
)
70 if (!jack_controller_settings_write_string(fd
, save_context_ptr
->indent
, dbus_call_context_ptr
))
75 if (!jack_controller_settings_write_string(fd
, "<option name=\"", dbus_call_context_ptr
))
80 if (!jack_controller_settings_write_string(fd
, name
, dbus_call_context_ptr
))
85 if (!jack_controller_settings_write_string(fd
, "\">", dbus_call_context_ptr
))
90 if (!jack_controller_settings_write_string(fd
, content
, dbus_call_context_ptr
))
95 if (!jack_controller_settings_write_string(fd
, "</option>\n", dbus_call_context_ptr
))
106 jack_controller_settings_save(
107 struct jack_controller
* controller_ptr
,
108 void *dbus_call_context_ptr
)
115 char timestamp_str
[26];
116 struct save_context context
;
117 const JSList
* node_ptr
;
118 jackctl_driver_t
*driver
;
119 jackctl_internal_t
*internal
;
122 ctime_r(×tamp
, timestamp_str
);
123 timestamp_str
[24] = 0;
127 conf_len
= strlen(JACKDBUS_CONF
);
129 filename
= malloc(g_jackdbus_config_dir_len
+ conf_len
+ 1);
130 if (filename
== NULL
)
132 jack_error("Out of memory.");
136 memcpy(filename
, g_jackdbus_config_dir
, g_jackdbus_config_dir_len
);
137 memcpy(filename
+ g_jackdbus_config_dir_len
, JACKDBUS_CONF
, conf_len
);
138 filename
[g_jackdbus_config_dir_len
+ conf_len
] = 0;
140 jack_info("Saving settings to \"%s\" ...", filename
);
142 fd
= open(filename
, O_WRONLY
| O_TRUNC
| O_CREAT
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
);
145 jack_error("open() failed to open conf filename. error is %d (%s)", errno
, strerror(errno
));
146 goto exit_free_filename
;
151 if (!jack_controller_settings_write_string(fd
, "<?xml version=\"1.0\"?>\n", dbus_call_context_ptr
))
156 if (!jack_controller_settings_write_string(fd
, "<!--\n", dbus_call_context_ptr
))
161 if (!jack_controller_settings_write_string(fd
, JACK_CONF_HEADER_TEXT
, dbus_call_context_ptr
))
166 if (!jack_controller_settings_write_string(fd
, "-->\n", dbus_call_context_ptr
))
171 if (!jack_controller_settings_write_string(fd
, "<!-- ", dbus_call_context_ptr
))
176 if (!jack_controller_settings_write_string(fd
, timestamp_str
, dbus_call_context_ptr
))
181 if (!jack_controller_settings_write_string(fd
, " -->\n", dbus_call_context_ptr
))
186 if (!jack_controller_settings_write_string(fd
, "<jack>\n", dbus_call_context_ptr
))
193 if (!jack_controller_settings_write_string(fd
, " <engine>\n", dbus_call_context_ptr
))
198 context
.indent
= " ";
199 if (!jack_controller_settings_save_engine_options(&context
, controller_ptr
, dbus_call_context_ptr
))
204 if (!jack_controller_settings_write_string(fd
, " </engine>\n", dbus_call_context_ptr
))
211 if (!jack_controller_settings_write_string(fd
, " <drivers>\n", dbus_call_context_ptr
))
216 node_ptr
= jackctl_server_get_drivers_list(controller_ptr
->server
);
218 while (node_ptr
!= NULL
)
220 driver
= (jackctl_driver_t
*)node_ptr
->data
;
222 if (!jack_controller_settings_write_string(fd
, " <driver name=\"", dbus_call_context_ptr
))
227 if (!jack_controller_settings_write_string(fd
, jackctl_driver_get_name(driver
), dbus_call_context_ptr
))
232 if (!jack_controller_settings_write_string(fd
, "\">\n", dbus_call_context_ptr
))
237 context
.indent
= " ";
239 if (!jack_controller_settings_save_driver_options(&context
, driver
, dbus_call_context_ptr
))
244 if (!jack_controller_settings_write_string(fd
, " </driver>\n", dbus_call_context_ptr
))
249 node_ptr
= jack_slist_next(node_ptr
);
252 if (!jack_controller_settings_write_string(fd
, " </drivers>\n", dbus_call_context_ptr
))
259 if (!jack_controller_settings_write_string(fd
, " <internals>\n", dbus_call_context_ptr
))
264 node_ptr
= jackctl_server_get_internals_list(controller_ptr
->server
);
266 while (node_ptr
!= NULL
)
268 internal
= (jackctl_internal_t
*)node_ptr
->data
;
270 if (!jack_controller_settings_write_string(fd
, " <internal name=\"", dbus_call_context_ptr
))
275 if (!jack_controller_settings_write_string(fd
, jackctl_internal_get_name(internal
), dbus_call_context_ptr
))
280 if (!jack_controller_settings_write_string(fd
, "\">\n", dbus_call_context_ptr
))
285 context
.indent
= " ";
287 if (!jack_controller_settings_save_internal_options(&context
, internal
, dbus_call_context_ptr
))
292 if (!jack_controller_settings_write_string(fd
, " </internal>\n", dbus_call_context_ptr
))
297 node_ptr
= jack_slist_next(node_ptr
);
300 if (!jack_controller_settings_write_string(fd
, " </internals>\n", dbus_call_context_ptr
))
305 if (!jack_controller_settings_write_string(fd
, "</jack>\n", dbus_call_context_ptr
))
323 jack_controller_settings_save_auto(
324 struct jack_controller
* controller_ptr
)
326 jack_controller_settings_save(controller_ptr
, NULL
);