cli: new --test-session option to use the session bus
This commit is contained in:
31
cli/mmcli.c
31
cli/mmcli.c
@@ -43,7 +43,7 @@
|
|||||||
static GMainLoop *loop;
|
static GMainLoop *loop;
|
||||||
static GCancellable *cancellable;
|
static GCancellable *cancellable;
|
||||||
|
|
||||||
/* Context */
|
/* Main context */
|
||||||
static gboolean output_keyvalue_flag;
|
static gboolean output_keyvalue_flag;
|
||||||
static gboolean output_json_flag;
|
static gboolean output_json_flag;
|
||||||
static gboolean verbose_flag;
|
static gboolean verbose_flag;
|
||||||
@@ -79,6 +79,31 @@ static GOptionEntry main_entries[] = {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Test context */
|
||||||
|
static gboolean test_session_flag;
|
||||||
|
|
||||||
|
static GOptionEntry test_entries[] = {
|
||||||
|
{ "test-session", 0, 0, G_OPTION_ARG_NONE, &test_session_flag,
|
||||||
|
"Run in session DBus",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static GOptionGroup *
|
||||||
|
test_get_option_group (void)
|
||||||
|
{
|
||||||
|
GOptionGroup *group;
|
||||||
|
|
||||||
|
group = g_option_group_new ("test",
|
||||||
|
"Test options:",
|
||||||
|
"Show test options",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
g_option_group_add_entries (group, test_entries);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
signals_handler (int signum)
|
signals_handler (int signum)
|
||||||
{
|
{
|
||||||
@@ -243,6 +268,8 @@ main (gint argc, gchar **argv)
|
|||||||
mmcli_sms_get_option_group ());
|
mmcli_sms_get_option_group ());
|
||||||
g_option_context_add_group (context,
|
g_option_context_add_group (context,
|
||||||
mmcli_call_get_option_group ());
|
mmcli_call_get_option_group ());
|
||||||
|
g_option_context_add_group (context,
|
||||||
|
test_get_option_group ());
|
||||||
g_option_context_add_main_entries (context, main_entries, NULL);
|
g_option_context_add_main_entries (context, main_entries, NULL);
|
||||||
g_option_context_parse (context, &argc, &argv, NULL);
|
g_option_context_parse (context, &argc, &argv, NULL);
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
@@ -281,7 +308,7 @@ main (gint argc, gchar **argv)
|
|||||||
signal (SIGTERM, signals_handler);
|
signal (SIGTERM, signals_handler);
|
||||||
|
|
||||||
/* Setup dbus connection to use */
|
/* Setup dbus connection to use */
|
||||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
connection = g_bus_get_sync (test_session_flag ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
g_printerr ("error: couldn't get bus: %s\n",
|
g_printerr ("error: couldn't get bus: %s\n",
|
||||||
error ? error->message : "unknown error");
|
error ? error->message : "unknown error");
|
||||||
|
Reference in New Issue
Block a user