* @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;
}
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.
#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
}
/**
+ * @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)