4 on_bus_acquired (GDBusConnection
*connection
,
8 /* This is where we'd export some objects on the bus */
12 on_name_acquired (GDBusConnection
*connection
,
16 g_print ("Acquired the name %s on the session bus\n", name
);
20 on_name_lost (GDBusConnection
*connection
,
24 g_print ("Lost the name %s on the session bus\n", name
);
28 main (int argc
, char *argv
[])
32 GBusNameOwnerFlags flags
;
34 gboolean opt_allow_replacement
;
36 GOptionContext
*opt_context
;
38 GOptionEntry opt_entries
[] =
40 { "replace", 'r', 0, G_OPTION_ARG_NONE
, &opt_replace
, "Replace existing name if possible", NULL
},
41 { "allow-replacement", 'a', 0, G_OPTION_ARG_NONE
, &opt_allow_replacement
, "Allow replacement", NULL
},
42 { "name", 'n', 0, G_OPTION_ARG_STRING
, &opt_name
, "Name to acquire", NULL
},
49 opt_allow_replacement
= FALSE
;
50 opt_context
= g_option_context_new ("g_bus_own_name() example");
51 g_option_context_add_main_entries (opt_context
, opt_entries
, NULL
);
52 if (!g_option_context_parse (opt_context
, &argc
, &argv
, &error
))
54 g_printerr ("Error parsing options: %s", error
->message
);
59 g_printerr ("Incorrect usage, try --help.\n");
63 flags
= G_BUS_NAME_OWNER_FLAGS_NONE
;
65 flags
|= G_BUS_NAME_OWNER_FLAGS_REPLACE
;
66 if (opt_allow_replacement
)
67 flags
|= G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
;
69 owner_id
= g_bus_own_name (G_BUS_TYPE_SESSION
,
78 loop
= g_main_loop_new (NULL
, FALSE
);
79 g_main_loop_run (loop
);
81 g_bus_unown_name (owner_id
);