mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 11:12:11 +01:00
Add gdbus-daemon test app
This commit is contained in:
parent
058e3926dc
commit
2515a69e2e
@ -119,6 +119,7 @@ SAMPLE_PROGS = \
|
|||||||
gapplication-example-cmdline2 \
|
gapplication-example-cmdline2 \
|
||||||
gapplication-example-cmdline3 \
|
gapplication-example-cmdline3 \
|
||||||
gapplication-example-actions \
|
gapplication-example-actions \
|
||||||
|
gdbus-daemon \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
if OS_UNIX
|
if OS_UNIX
|
||||||
@ -264,6 +265,9 @@ gsettings_LDADD = $(progs_ldadd)
|
|||||||
gschema_compile_SOURCES = gschema-compile.c
|
gschema_compile_SOURCES = gschema-compile.c
|
||||||
gschema_compile_LDADD = $(progs_ldadd)
|
gschema_compile_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
|
gdbus_daemon_SOURCES = gdbus-daemon.c $(top_srcdir)/gio/gdbusdaemon.c $(top_srcdir)/gio/gdbus-daemon-generated.c
|
||||||
|
gdbus_daemon_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
if HAVE_DBUS1
|
if HAVE_DBUS1
|
||||||
TEST_PROGS += gdbus-serialization
|
TEST_PROGS += gdbus-serialization
|
||||||
gdbus_serialization_SOURCES = gdbus-serialization.c gdbus-tests.h gdbus-tests.c
|
gdbus_serialization_SOURCES = gdbus-serialization.c gdbus-tests.h gdbus-tests.c
|
||||||
|
72
gio/tests/gdbus-daemon.c
Normal file
72
gio/tests/gdbus-daemon.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "gdbusdaemon.h"
|
||||||
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
GDBusDaemon *daemon;
|
||||||
|
GMainLoop *loop;
|
||||||
|
const char *address = NULL;
|
||||||
|
const char *config_file = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
gboolean print_address = FALSE;
|
||||||
|
gboolean print_env = FALSE;
|
||||||
|
GOptionContext *context;
|
||||||
|
GOptionEntry entries[] = {
|
||||||
|
{ "address", 0, 0, G_OPTION_ARG_STRING, &address, N_("Address to listen on"), NULL },
|
||||||
|
{ "config-file", 0, 0, G_OPTION_ARG_STRING, &config_file, N_("Ignored, for compat with GTestDbus"), NULL },
|
||||||
|
{ "print-address", 0, 0, G_OPTION_ARG_NONE, &print_address, N_("Print address"), NULL },
|
||||||
|
{ "print-env", 0, 0, G_OPTION_ARG_NONE, &print_env, N_("Print address in shell mode"), NULL },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
g_type_init ();
|
||||||
|
|
||||||
|
context = g_option_context_new ("");
|
||||||
|
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
|
||||||
|
g_option_context_set_summary (context,
|
||||||
|
N_("Run a dbus service"));
|
||||||
|
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
|
if (!g_option_context_parse (context, &argc, &argv, &error))
|
||||||
|
{
|
||||||
|
g_printerr ("%s\n", error->message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_option_context_free (context);
|
||||||
|
|
||||||
|
if (argc != 1)
|
||||||
|
{
|
||||||
|
g_printerr (_("Wrong args\n"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
|
if (argc >= 2)
|
||||||
|
address = argv[1];
|
||||||
|
|
||||||
|
daemon = _g_dbus_daemon_new (address, NULL, &error);
|
||||||
|
if (daemon == NULL)
|
||||||
|
{
|
||||||
|
g_printerr ("Can't init bus: %s\n", error->message);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (print_env)
|
||||||
|
g_print ("export DBUS_SESSION_BUS_ADDRESS=\"%s\"\n", _g_dbus_daemon_get_address (daemon));
|
||||||
|
|
||||||
|
if (print_address)
|
||||||
|
g_print ("%s\n", _g_dbus_daemon_get_address (daemon));
|
||||||
|
|
||||||
|
g_main_loop_run (loop);
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user