summaryrefslogtreecommitdiff
path: root/test/interfaces/test-interfaces.c
blob: de56669a145d70aadac18d1386873b49d3050cb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later */

#ifdef HAVE_CONFIG_H
#	include <config.h>
#endif
#include "test-interfaces.h"

static gboolean
test_hello_dbus_say_hello (TestHello  *hello,
			   gchar     **message,
			   GError    **error)
{
	*message = test_hello_say_hello (hello);
	return TRUE;
}

static gboolean
test_goodbye_dbus_say_goodbye (TestGoodbye  *goodbye,
			       gchar       **message,
			       GError      **error)
{
	*message = test_goodbye_say_goodbye (goodbye);
	return TRUE;
}

#include "test-hello-glue.h"
#include "test-goodbye-glue.h"

enum {
	GREETINGS,
	LAST_SIGNAL
};

static guint signals[LAST_SIGNAL];

static void
test_hello_class_init (gpointer g_iface)
{
	GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);

	signals[GREETINGS] =
		g_signal_new ("greetings",
			      iface_type,
			      G_SIGNAL_RUN_LAST,
			      G_STRUCT_OFFSET (TestHelloIface, greetings),
			      NULL, NULL,
			      g_cclosure_marshal_VOID__VOID,
			      G_TYPE_NONE,
			      0);

	dbus_g_object_type_install_info (iface_type,
					 &dbus_glib_test_hello_object_info);
}

GType
test_hello_get_type (void)
{
	static GType the_type = 0;
	
	if (G_UNLIKELY (the_type == 0)) {
		static const GTypeInfo info = {
			sizeof (TestHelloIface),
			NULL, NULL,
			(GClassInitFunc) test_hello_class_init,
			NULL, NULL, 0, 0, NULL
		};
		
		the_type = g_type_register_static (G_TYPE_INTERFACE,
						   "TestHello",
						   &info, 0);
		g_type_interface_add_prerequisite (the_type, G_TYPE_OBJECT);
	}
	return the_type;
}

gchar *
test_hello_say_hello (TestHello *hello)
{
	g_return_val_if_fail (TEST_IS_HELLO (hello), NULL);

	return (* TEST_HELLO_GET_IFACE (hello)->say_hello) (hello);
}

void
test_hello_greetings (TestHello *hello)
{
	g_return_if_fail (TEST_IS_HELLO (hello));

	g_signal_emit (hello, signals[GREETINGS], 0);
}

static void
test_goodbye_class_init (gpointer g_iface)
{
	GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);

	dbus_g_object_type_install_info (iface_type,
					 &dbus_glib_test_goodbye_object_info);
}

GType
test_goodbye_get_type (void)
{
	static GType the_type = 0;
	
	if (G_UNLIKELY (the_type == 0)) {
		static const GTypeInfo info = {
			sizeof (TestGoodbyeIface),
			NULL, NULL,
			(GClassInitFunc) test_goodbye_class_init,
			NULL, NULL, 0, 0, NULL
		};
		
		the_type = g_type_register_static (G_TYPE_INTERFACE,
						   "TestGoodbye",
						   &info, 0);
		g_type_interface_add_prerequisite (the_type, G_TYPE_OBJECT);
	}
	return the_type;
}

gchar *
test_goodbye_say_goodbye (TestGoodbye *goodbye)
{
	g_return_val_if_fail (TEST_IS_GOODBYE (goodbye), NULL);

	return (* TEST_GOODBYE_GET_IFACE (goodbye)->say_goodbye) (goodbye);
}