summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Lewandowski <k.lewandowsk@samsung.com>2022-07-27 01:15:20 +0200
committerKarol Lewandowski <k.lewandowsk@samsung.com>2022-07-28 15:28:32 +0200
commit510e31bd3e8e071e32fb663399341ba5ab807d93 (patch)
tree2397479e1a5bc0ead41f2af486bde299bb811543
parent6bc3aac333907fe7e1643cff9662b0a6187cb0b6 (diff)
downloadsessiond-510e31bd3e8e071e32fb663399341ba5ab807d93.tar.gz
sessiond-510e31bd3e8e071e32fb663399341ba5ab807d93.tar.bz2
sessiond-510e31bd3e8e071e32fb663399341ba5ab807d93.zip
library: Rename async method call to follow method_call_<sync/async> convention
Additional style fixes along the way. Change-Id: I6eb43013019a0a701cc191ff25e1dd0463526124
-rw-r--r--libsessiond/src/lib.c93
1 files changed, 35 insertions, 58 deletions
diff --git a/libsessiond/src/lib.c b/libsessiond/src/lib.c
index 8a87664..2af553b 100644
--- a/libsessiond/src/lib.c
+++ b/libsessiond/src/lib.c
@@ -563,39 +563,33 @@ static void callbacks_data_remove_client_data(client_callbacks_data_t *callbacks
static void async_method_reply_handler(GObject *source_obj, GAsyncResult *res, gpointer userdata)
{
- g_autofree reply_client_data_t * reply_info = (reply_client_data_t *) userdata;
- GDBusConnection *const connection = (GDBusConnection *) source_obj;
-
- g_autoptr(GError) err = NULL;
- g_autoptr(GVariant) ret = g_dbus_connection_call_finish
- ( connection
- , res
- , &err
- );
- if(err != NULL) {
- LOGE("Dbus error: %s map to: %d", g_dbus_error_get_remote_error(err), map_dbus_call_error_to_return_value(err));
+ assert(userdata);
+ assert(source_obj);
- }
+ g_autofree reply_client_data_t *reply_info = (reply_client_data_t *)userdata;
+ GDBusConnection *const connection = (GDBusConnection *)source_obj;
- /* The reply contains nothing useful, we only use it
- * to receive information about the error, really. */
+ g_autoptr(GError) g_err = NULL;
+ // ret's GVariant is unused, we are interested only if method call resulted in error or not
+ g_autoptr(GVariant) ret = g_dbus_connection_call_finish(connection, res, &g_err);
+ subsession_error_e s_err = map_dbus_call_error_to_return_value(g_err);
+ if (g_err)
+ LOGI("DBus method call returned error: %s (SUBSESSION_ERROR code: %d)", g_dbus_error_get_remote_error(g_err), s_err);
- reply_info->reply_callback
- ( err
- ? map_dbus_call_error_to_return_value(err)
- : SUBSESSION_ERROR_NONE
- , reply_info->reply_data
- );
+ assert(reply_info->reply_callback);
+ reply_info->reply_callback(s_err, reply_info->reply_data);
}
-static int call_method_async(gchar *method, GVariant *params, subsession_reply_callback cb, void *cb_data) {
+static int method_call_async(gchar *method, GVariant *params, subsession_reply_callback cb, void *cb_data)
+{
+ assert(method);
if (!params)
return SUBSESSION_ERROR_OUT_OF_MEMORY;
MAKE_SURE_CONNECTION_IS_NOT_NULL();
- reply_client_data_t *reply_info;
+ reply_client_data_t *reply_info = NULL;
if (cb) {
reply_info = g_malloc(sizeof *reply_info); // freed in the callback
if (!reply_info)
@@ -604,66 +598,49 @@ static int call_method_async(gchar *method, GVariant *params, subsession_reply_c
reply_info->reply_data = cb_data;
}
- g_dbus_connection_call
- ( conn_config_
- , method
- , params
- , NULL
- , G_DBUS_CALL_FLAGS_NONE
- , libsessiond_default_timeout
- , NULL
- , cb
- ? async_method_reply_handler
- : NULL
- , cb
- ? reply_info
- : NULL
+ g_dbus_connection_call(
+ conn_config_,
+ method,
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ libsessiond_default_timeout,
+ NULL,
+ cb ? async_method_reply_handler : NULL,
+ cb ? reply_info : NULL
);
return SUBSESSION_ERROR_NONE;
}
-EXPORT_API int subsession_add_user(int session_uid, const subsession_user_t user, subsession_reply_callback cb, void *cb_data) {
-
+EXPORT_API int subsession_add_user(int session_uid, const subsession_user_t user, subsession_reply_callback cb, void *cb_data)
+{
return_if(
session_uid_is_not_valid(session_uid,
user_id_is_not_valid(user))
)
-
- return_with_log_error_result_(call_method_async
- ( dbus_method_call.AddUser
- , g_variant_new("(is)", session_uid, user)
- , cb, cb_data
- ))
+ return_with_log_error_result_(method_call_async(dbus_method_call.AddUser, g_variant_new("(is)", session_uid, user), cb, cb_data))
}
-EXPORT_API int subsession_remove_user(int session_uid, const subsession_user_t user, subsession_reply_callback cb, void *cb_data) {
-
+EXPORT_API int subsession_remove_user(int session_uid, const subsession_user_t user, subsession_reply_callback cb, void *cb_data)
+{
return_if(
session_uid_is_not_valid(session_uid,
user_id_is_not_valid(user))
)
- return_with_log_error_result_(call_method_async
- ( dbus_method_call.RemoveUser
- , g_variant_new("(is)", session_uid, user)
- , cb, cb_data
- ))
+ return_with_log_error_result_(method_call_async(dbus_method_call.RemoveUser, g_variant_new("(is)", session_uid, user), cb, cb_data))
}
-EXPORT_API int subsession_switch_user(int session_uid, const subsession_user_t next_user, subsession_reply_callback cb, void *cb_data) {
-
+EXPORT_API int subsession_switch_user(int session_uid, const subsession_user_t next_user, subsession_reply_callback cb, void *cb_data)
+{
return_if(
switched_user_is_not_valid(next_user,
session_uid_is_not_valid(session_uid))
)
- return_with_log_error_result_(call_method_async
- ( dbus_method_call.SwitchUser
- , g_variant_new("(is)", session_uid, next_user)
- , cb, cb_data
- ))
+ return_with_log_error_result_(method_call_async(dbus_method_call.SwitchUser, g_variant_new("(is)", session_uid, next_user), cb, cb_data))
}
static int callbacks_data_push(client_callbacks_data_t *callbacks_data, GVariant *params, subsession_event_callback cb, void *cb_data, signal_client_data_t **client_data)