Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[config] Send D-Bus change notifications on setting changes
Changing setting values and broadcasting changes on D-Bus are handled
separately. This leads to a situation where some code paths that modify
settings do it silently without sending D-Bus notifications.

Send setting change notification from configuration layer, so that each
and every setting change does result in D-Bus notification signal.

Remove all case-by-case signal emitting code made redundant by these
changes.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Apr 9, 2019
1 parent b5a8e8b commit 8a6390e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
11 changes: 7 additions & 4 deletions src/usb_moded-config.c
Expand Up @@ -415,6 +415,7 @@ set_config_result_t config_set_config_setting(const char *entry, const char *key
if( g_strcmp0(prev, value) ) {
g_key_file_set_string(active_ini, entry, key, value);
ret = SET_CONFIG_UPDATED;
umdbus_send_config_signal(entry, key, value);
}

/* Filter out dynamic data that matches static values */
Expand All @@ -436,7 +437,11 @@ set_config_result_t config_set_mode_setting(const char *mode)

if (strcmp(mode, MODE_ASK) && common_valid_mode(mode))
return SET_CONFIG_ERROR;
return config_set_config_setting(MODE_SETTING_ENTRY, MODE_SETTING_KEY, mode);

int ret = config_set_config_setting(MODE_SETTING_ENTRY,
MODE_SETTING_KEY, mode);

return ret;
}

/* Builds the string used for hidden modes, when hide set to one builds the
Expand Down Expand Up @@ -588,9 +593,7 @@ set_config_result_t config_set_mode_in_whitelist(const char *mode, int allowed)

char *whitelist = config_make_modes_string(MODE_WHITELIST_KEY, mode, allowed);

if (whitelist) {
ret = config_set_mode_whitelist(whitelist);
}
ret = config_set_mode_whitelist(whitelist ?: "");

g_free(whitelist);

Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-dbus-private.h
Expand Up @@ -57,6 +57,7 @@ typedef void (*usb_moded_get_name_owner_fn)(const char *owner);
* UMDBUS
* ------------------------------------------------------------------------- */

void umdbus_send_config_signal (const char *section, const char *key, const char *value);
DBusConnection *umdbus_get_connection (void);
gboolean umdbus_init_connection (void);
gboolean umdbus_init_service (void);
Expand Down
22 changes: 2 additions & 20 deletions src/usb_moded-dbus.c
Expand Up @@ -59,7 +59,7 @@
* UMDBUS
* ------------------------------------------------------------------------- */

static void umdbus_send_config_signal (const char *section, const char *key, const char *value);
void umdbus_send_config_signal (const char *section, const char *key, const char *value);
static DBusHandlerResult umdbus_msg_handler (DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data);
DBusConnection *umdbus_get_connection (void);
gboolean umdbus_init_connection (void);
Expand Down Expand Up @@ -233,7 +233,7 @@ static const char umdbus_introspect_usbmoded[] =
/**
* Issues "sig_usb_config_ind" signal.
*/
static void umdbus_send_config_signal(const char *section, const char *key, const char *value)
void umdbus_send_config_signal(const char *section, const char *key, const char *value)
{
LOG_REGISTER_CONTEXT;

Expand Down Expand Up @@ -384,8 +384,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
{
/* error checking is done when setting configuration */
int ret = config_set_mode_setting(config);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_SETTING_KEY, config);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
Expand All @@ -407,8 +405,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
{
/* error checking is done when setting configuration */
int ret = config_set_hide_mode_setting(config);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_HIDE_KEY, config);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
Expand All @@ -430,8 +426,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
{
/* error checking is done when setting configuration */
int ret = config_set_unhide_mode_setting(config);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_HIDE_KEY, config);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
Expand Down Expand Up @@ -462,8 +456,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
{
/* error checking is done when setting configuration */
int ret = config_set_network_setting(config, setting);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(NETWORK_ENTRY, config, setting);
if (SET_CONFIG_OK(ret))
{
if((reply = dbus_message_new_method_return(msg)))
Expand Down Expand Up @@ -549,8 +541,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
else
{
int ret = config_set_mode_whitelist(whitelist);
if (ret == SET_CONFIG_UPDATED)
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_WHITELIST_KEY, whitelist);
if (SET_CONFIG_OK(ret))
{
if ((reply = dbus_message_new_method_return(msg)))
Expand All @@ -572,14 +562,6 @@ static DBusHandlerResult umdbus_msg_handler(DBusConnection *const connection, DB
else
{
int ret = config_set_mode_in_whitelist(mode, enabled);
if (ret == SET_CONFIG_UPDATED)
{
char *whitelist = config_get_mode_whitelist();
if (!whitelist)
whitelist = g_strdup(MODE_UNDEFINED);
umdbus_send_config_signal(MODE_SETTING_ENTRY, MODE_WHITELIST_KEY, whitelist);
g_free(whitelist);
}
if (SET_CONFIG_OK(ret))
reply = dbus_message_new_method_return(msg);
else
Expand Down

0 comments on commit 8a6390e

Please sign in to comment.