From: Sangjung Woo Date: Mon, 18 Jul 2022 05:32:03 +0000 (+0900) Subject: [daemon] Add command-line option for DBus bus type X-Git-Tag: accepted/tizen/unified/20220811.135945~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0ff6fe362a1e6f106f8f48605717ed7720b5078;p=platform%2Fcore%2Fapi%2Fmachine-learning.git [daemon] Add command-line option for DBus bus type To run the unit tests in the GBS environment, the session type of the DBus is required. This patch adds the command-line option to support the session bus. Signed-off-by: Sangjung Woo --- diff --git a/daemon/gdbus-util.c b/daemon/gdbus-util.c index 3f76994..c7f3858 100644 --- a/daemon/gdbus-util.c +++ b/daemon/gdbus-util.c @@ -146,13 +146,15 @@ gdbus_put_instance_pipeline (MachinelearningServicePipeline ** instance) * @brief Connect to the DBus message bus, which type is SYSTEM. */ int -gdbus_get_system_connection (void) +gdbus_get_system_connection (gboolean is_session) { GError *error = NULL; + GBusType bus_type = is_session ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; - g_dbus_sys_conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + g_dbus_sys_conn = g_bus_get_sync (bus_type, NULL, &error); if (g_dbus_sys_conn == NULL) { _E ("cannot connect to the system message bus: %s\n", error->message); + g_clear_error(&error); return -ENOSYS; } diff --git a/daemon/includes/gdbus-util.h b/daemon/includes/gdbus-util.h index d55d22d..818b09d 100644 --- a/daemon/includes/gdbus-util.h +++ b/daemon/includes/gdbus-util.h @@ -86,10 +86,11 @@ MachinelearningServicePipeline *gdbus_get_instance_pipeline (void); void gdbus_put_instance_pipeline (MachinelearningServicePipeline ** instance); /** - * @brief Connect to the DBus message bus, which type is SYSTEM. + * @brief Connect to the DBus message bus + * @param is_session Ture is DBus Bus type is session. * @return @c 0 on success. Otherwise a negative error value. */ -int gdbus_get_system_connection (void); +int gdbus_get_system_connection (gboolean is_session); /** * @brief Disconnect the DBus message bus. diff --git a/daemon/main.c b/daemon/main.c index af613a7..2262af0 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -22,6 +22,8 @@ #include "dbus-interface.h" static GMainLoop *g_mainloop; +static gboolean verbose = FALSE; +static gboolean is_session = FALSE; /** * @brief Handle the SIGTERM signal and quit the main loop @@ -52,13 +54,56 @@ postinit (void) } /** + * @brief Parse commandline option. + * @return @c 0 on success. Otherwise a negative error value. + */ +static int +parse_args (gint *argc, gchar ***argv) +{ + GError *err; + GOptionContext *context = NULL; + gboolean ret; + + static GOptionEntry entries[] = { + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, + { "session", 's', 0, G_OPTION_ARG_NONE, &is_session, "Bus type is session", NULL }, + { NULL } + }; + + context = g_option_context_new (NULL); + if (!context) { + _E ("Failed to call g_option_context_new\n"); + return -ENOMEM; + } + + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_set_help_enabled (context, TRUE); + g_option_context_set_ignore_unknown_options (context, TRUE); + + err = NULL; + ret = g_option_context_parse (context, argc, argv, &err); + g_option_context_free(context); + if (!ret) { + _E ("Fail to option parsing: %s", err->message); + g_clear_error(&err); + return -EINVAL; + } + + return 0; +} + +/** * @brief main function of the Machine Learning agent daemon. */ int main (int argc, char **argv) { + if (parse_args(&argc, &argv)) { + return -EINVAL; + } + g_mainloop = g_main_loop_new (NULL, FALSE); - gdbus_get_system_connection (); + gdbus_get_system_connection (is_session); init_modules (NULL); if (postinit () < 0)