1 /* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later */
2 
3 #include <config.h>
4 #undef G_DISABLE_ASSERT
5 
6 #include <stdlib.h>
7 #include "dbus/dbus-glib.h"
8 #include "tools/dbus-glib-bindings.h"
9 #include "test-objects.h"
10 #include "test-dup-prop.h"
11 
12 #define TEST_NAMESPACE "org.freedesktop.DBus.GLib.Test.Interfaces"
13 #define TEST_OBJECT_PATH "/org/freedesktop/DBus/GLib/Test/Interfaces"
14 #define TEST_DP_OBJECT_PATH "/org/freedesktop/DBus/GLib/Test/DupPropInterfaces"
15 
16 static GMainLoop *loop = NULL;
17 
18 int
main(int argc,char ** argv)19 main (int    argc,
20       char **argv)
21 {
22 	DBusGConnection *connection;
23 	DBusGProxy *proxy;
24 	GError *error = NULL;
25 	guint32 ret;
26 	TestBeatlesSong *song;
27 	TestDpObj *dp_obj;
28 
29 	g_type_init ();
30 
31 	/* Get the connection and ensure the name is not used yet */
32 	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
33 	if (connection == NULL) {
34 		g_warning ("Failed to make connection to session bus: %s",
35 			   error->message);
36 		g_error_free (error);
37 		exit(1);
38 	}
39 
40 	proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS,
41 					   DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
42 	if (!org_freedesktop_DBus_request_name (proxy, TEST_NAMESPACE,
43 						0, &ret, &error)) {
44 		g_warning ("There was an error requesting the name: %s",
45 			   error->message);
46 		g_error_free (error);
47 		exit(1);
48 	}
49 
50 	if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
51 		/* Someone else registered the name before us */
52 		exit(1);
53 	}
54 
55 	song = test_beatles_song_new ();
56 
57 	/* Register the app on the bus */
58 	dbus_g_connection_register_g_object (connection,
59 					     TEST_OBJECT_PATH,
60 					     G_OBJECT (song));
61 
62 	dp_obj = test_dp_obj_new ();
63 	dbus_g_connection_register_g_object (connection,
64 					     TEST_DP_OBJECT_PATH,
65 					     G_OBJECT (dp_obj));
66 
67 	loop = g_main_loop_new (NULL, FALSE);
68 	g_main_loop_run (loop);
69 
70 	return 0;
71 }
72