Skip to content

Commit

Permalink
[dbus] Add method call for getting all mce settings. JB#34813
Browse files Browse the repository at this point in the history
If client needs to track multiple mce settings, getting the initial
values one by one via blocking dbus calls is slow and cumbersome/difficult
asynchronously (the number of available settings exceeds the default
maximum number of pending dbus calls allowed by system bus configuration).

Add com.nokia.mce.request.get_config_all() method call that can be used
to get current values of all mce settings at once.

Related constants are made available in mce-headers > 1.20.0.
  • Loading branch information
spiiroin committed Nov 10, 2016
1 parent 59881ef commit d48ca6a
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 13 deletions.
169 changes: 157 additions & 12 deletions mce-dbus.c
Expand Up @@ -1049,24 +1049,22 @@ static const char *value_signature(GConfValue *conf)

/** Helper for appending GConfValue to dbus message
*
* @param reply DBusMessage under construction
* @param conf GConfValue to be added to the reply
* @param iter Append iterator for DBusMessage under construction
* @param conf GConfValue to be added at the iterator
*
* @return TRUE if the value was succesfully appended, or FALSE on failure
* @return true if the value was succesfully appended, or false on failure
*/
static gboolean append_gconf_value_to_dbus_message(DBusMessage *reply, GConfValue *conf)
static bool append_gconf_value_to_dbus_iterator(DBusMessageIter *iter, GConfValue *conf)
{
const char *sig = 0;

DBusMessageIter body, variant, array;
DBusMessageIter variant, array;

if( !(sig = value_signature(conf)) ) {
goto bailout_message;
}

dbus_message_iter_init_append(reply, &body);

if( !dbus_message_iter_open_container(&body, DBUS_TYPE_VARIANT,
if( !dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
sig, &variant) ) {
goto bailout_message;
}
Expand Down Expand Up @@ -1177,19 +1175,114 @@ static gboolean append_gconf_value_to_dbus_message(DBusMessage *reply, GConfValu
goto bailout_variant;
}

if( !dbus_message_iter_close_container(&body, &variant) ) {
if( !dbus_message_iter_close_container(iter, &variant) ) {
goto bailout_message;
}
return TRUE;
return true;

bailout_array:
dbus_message_iter_abandon_container(&variant, &array);

bailout_variant:
dbus_message_iter_abandon_container(&body, &variant);
dbus_message_iter_abandon_container(iter, &variant);

bailout_message:
return FALSE;
return false;
}

/** Helper for appending GConfEntry to dbus message
*
* @param iter Append iterator for DBusMessage under construction
* @param entry GConfEntry to be added at the iterator
*
* @return true if the value was succesfully appended, or false on failure
*/
static bool append_gconf_entry_to_dbus_iterator(DBusMessageIter *iter, GConfEntry *entry)
{
DBusMessageIter sub;

if( !dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY,
0, &sub) ) {
goto bailout_message;
}

if( !dbus_message_iter_append_basic(&sub,
DBUS_TYPE_STRING, &entry->key) ) {
goto bailout_container;
}

if( !append_gconf_value_to_dbus_iterator(&sub, entry->value) ) {
goto bailout_container;
}

if( !dbus_message_iter_close_container(iter, &sub) ) {
goto bailout_message;
}

return true;

bailout_container:
dbus_message_iter_abandon_container(iter, &sub);

bailout_message:
return false;
}

/** Helper for appending list of GConfEntry objects to dbus message
*
* @param iter Append iterator for DBusMessage under construction
* @param entries GSList containing GConfEntry objects
*
* @return true if the value was succesfully appended, or false on failure
*/
static bool append_gconf_entries_to_dbus_iterator(DBusMessageIter *iter, GSList *entries)
{
DBusMessageIter sub;

if( !dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
&sub) ) {
goto bailout_message;
}

for( GSList *item = entries; item; item = item->next )
{
GConfEntry *entry = item->data;

if( !append_gconf_entry_to_dbus_iterator(&sub, entry) )
goto bailout_container;
}

if( !dbus_message_iter_close_container(iter, &sub) ) {
goto bailout_message;
}

return true;

bailout_container:
dbus_message_iter_abandon_container(iter, &sub);

bailout_message:
return false;
}

/** Helper for appending GConfValue to dbus message
*
* @param reply DBusMessage under construction
* @param conf GConfValue to be added to the reply
*
* @return true if the value was succesfully appended, or false on failure
*/
static bool append_gconf_value_to_dbus_message(DBusMessage *reply, GConfValue *conf)
{
DBusMessageIter body;

dbus_message_iter_init_append(reply, &body);

return append_gconf_value_to_dbus_iterator(&body, conf);
}

/**
Expand Down Expand Up @@ -1266,6 +1359,49 @@ static gboolean config_get_dbus_cb(DBusMessage *const msg)
return status;
}

/** D-Bus callback for the config get all -method call
*
* @param msg The D-Bus message to reply to
*
* @return TRUE
*/
static gboolean config_get_all_dbus_cb(DBusMessage *const req)
{
GConfClient *cli = 0;
DBusMessage *rsp = 0;

mce_log(LL_DEBUG, "Received configuration query request");

if( !(cli = gconf_client_get_default()) )
goto EXIT;

if( !(rsp = dbus_new_method_reply(req)) )
goto EXIT;

DBusMessageIter body;

dbus_message_iter_init_append(rsp, &body);

if( !append_gconf_entries_to_dbus_iterator(&body, cli->entries) ) {
dbus_message_unref(rsp), rsp = 0;
}

EXIT:

if( !dbus_message_get_no_reply(req) ) {
if( !rsp )
rsp = dbus_message_new_error(req, "com.nokia.mce.GConf.Error",
"unknown");
if( rsp )
dbus_send_message(rsp), rsp = 0;
}

if( rsp )
dbus_message_unref(rsp);

return TRUE;
}

/** Send configuration changed notification signal
*
* @param entry changed setting
Expand Down Expand Up @@ -3771,6 +3907,15 @@ static mce_dbus_handler_t mce_dbus_handlers[] =
" <arg direction=\"in\" name=\"key_name\" type=\"s\"/>\n"
" <arg direction=\"out\" name=\"key_value\" type=\"v\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CONFIG_GET_ALL,
.type = DBUS_MESSAGE_TYPE_METHOD_CALL,
.callback = config_get_all_dbus_cb,
.args =
" <arg direction=\"out\" name=\"values\" type=\"a{sv}\"/>\n"
" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QVariantMap\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CONFIG_SET,
Expand Down
3 changes: 3 additions & 0 deletions mce.conf
Expand Up @@ -64,6 +64,9 @@
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="reset_config"/>
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="get_config_all"/>

<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
Expand Down
2 changes: 1 addition & 1 deletion rpm/mce.spec
Expand Up @@ -19,7 +19,7 @@ BuildRequires: pkgconfig(dbus-glib-1)
BuildRequires: pkgconfig(dsme) >= 0.58
BuildRequires: pkgconfig(libiphb)
BuildRequires: pkgconfig(glib-2.0) >= 2.36.0
BuildRequires: pkgconfig(mce) >= 1.19.0
BuildRequires: pkgconfig(mce) >= 1.20.0
BuildRequires: pkgconfig(libngf0) >= 0.24
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: kernel-headers >= 2.6.32
Expand Down

0 comments on commit d48ca6a

Please sign in to comment.