Clean up options/config file parsing

* Pass a options_t, not session_t
* Slightly improve error handling when setting vsync method via dbus

The goal here is to limit the scope of what a given function can access.
And session_t contains basically everything, so don't pass it around.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2018-12-21 16:25:28 +00:00
parent ee2be09958
commit cb7d852b0f
12 changed files with 729 additions and 609 deletions

View File

@ -1183,15 +1183,27 @@ cdbus_process_opts_set(session_t *ps, DBusMessage *msg) {
if (!cdbus_msg_get_arg(msg, 1, DBUS_TYPE_STRING, &val))
return false;
vsync_deinit(ps);
if (!parse_vsync(ps, val)) {
log_error(CDBUS_ERROR_BADARG_S, 1, "Value invalid.");
cdbus_reply_err(ps, msg, CDBUS_ERROR_BADARG, CDBUS_ERROR_BADARG_S, 1, "Value invalid.");
auto tmp_vsync = parse_vsync(val);
if (tmp_vsync >= NUM_VSYNC) {
log_error("Failed to parse vsync: invalid value %s.", val);
cdbus_reply_err(ps, msg, CDBUS_ERROR_BADARG, CDBUS_ERROR_BADARG_S, 1,
"Value invalid.");
return true;
}
else if (!vsync_init(ps)) {
log_error(CDBUS_ERROR_CUSTOM_S, "Failed to initialize specified VSync method.");
cdbus_reply_err(ps, msg, CDBUS_ERROR_CUSTOM, CDBUS_ERROR_CUSTOM_S, "Failed to initialize specified VSync method.");
}
else
auto old_vsync = ps->o.vsync;
ps->o.vsync = tmp_vsync;
if (!vsync_init(ps)) {
// Trying to revert back to original vsync values
log_error("Failed to initialize specified VSync method.");
ps->o.vsync = old_vsync;
if (!vsync_init(ps)) {
log_error("Failed to revert back to original VSync method.");
ps->o.vsync = VSYNC_NONE;
}
cdbus_reply_err(ps, msg, CDBUS_ERROR_CUSTOM, CDBUS_ERROR_CUSTOM_S,
"Failed to initialize specified VSync method.");
} else
goto cdbus_process_opts_set_success;
return true;
}