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:
28
src/dbus.c
28
src/dbus.c
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user