summaryrefslogtreecommitdiff
path: root/test/interfaces/test-dup-prop.c
blob: 0400a738612175af84c7ee4015590ae4308f0628 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later */

#ifdef HAVE_CONFIG_H
#	include <config.h>
#	undef G_DISABLE_ASSERT
#endif
#include "test-dup-prop.h"

#include "test-dup-prop-a-glue.h"
#include "test-dup-prop-b-glue.h"

#define TEST_A_FOOBAR "a-foobar"
#define TEST_B_FOOBAR "b-foobar"

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

	g_object_interface_install_property (g_iface,
	    g_param_spec_uint (TEST_A_FOOBAR,
	                       "A Foobar",
	                       "A description of something",
	                       0, G_MAXUINT, 0,
	                       G_PARAM_READWRITE));

	dbus_g_object_type_install_info (iface_type,
					 &dbus_glib_test_dup_prop_a_object_info);
	dbus_g_object_type_register_shadow_property (iface_type,
	                                             "Foobar",
	                                             TEST_A_FOOBAR);
}

GType
test_a_get_type (void)
{
	static GType the_type = 0;

	if (G_UNLIKELY (the_type == 0)) {
		static const GTypeInfo info = {
			sizeof (TestAIface),
			NULL, NULL,
			(GClassInitFunc) test_a_class_init,
			NULL, NULL, 0, 0, NULL
		};

		the_type = g_type_register_static (G_TYPE_INTERFACE,
						   "TestA",
						   &info, 0);
		g_type_interface_add_prerequisite (the_type, G_TYPE_OBJECT);
	}
	return the_type;
}


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

	g_object_interface_install_property (g_iface,
	    g_param_spec_uint (TEST_B_FOOBAR,
	                       "B Foobar",
	                       "A description of something",
	                       0, G_MAXUINT, 0,
	                       G_PARAM_READWRITE));

	dbus_g_object_type_install_info (iface_type,
					 &dbus_glib_test_dup_prop_b_object_info);
	dbus_g_object_type_register_shadow_property (iface_type,
	                                             "Foobar",
	                                             TEST_B_FOOBAR);
}

GType
test_b_get_type (void)
{
	static GType the_type = 0;

	if (G_UNLIKELY (the_type == 0)) {
		static const GTypeInfo info = {
			sizeof (TestBIface),
			NULL, NULL,
			(GClassInitFunc) test_b_class_init,
			NULL, NULL, 0, 0, NULL
		};

		the_type = g_type_register_static (G_TYPE_INTERFACE,
						   "TestB",
						   &info, 0);
		g_type_interface_add_prerequisite (the_type, G_TYPE_OBJECT);
	}
	return the_type;
}



static void test_a_init (TestAIface *a_class);
static void test_b_init (TestBIface *b_class);

G_DEFINE_TYPE_EXTENDED (TestDpObj, test_dp_obj, G_TYPE_OBJECT, 0,
                        G_IMPLEMENT_INTERFACE (TEST_TYPE_A, test_a_init)
                        G_IMPLEMENT_INTERFACE (TEST_TYPE_B, test_b_init))

#define TEST_DP_OBJ_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TEST_TYPE_DP_OBJ, TestDpObjPrivate))

enum {
	PROP_0,
	PROP_A_FOOBAR,
	PROP_B_FOOBAR
};

typedef struct {
	guint32 a_foobar;
	guint32 b_foobar;
} TestDpObjPrivate;

TestDpObj *
test_dp_obj_new (void)
{
	return TEST_DP_OBJ (g_object_new (TEST_TYPE_DP_OBJ, NULL));
}

static void
test_a_init (TestAIface *a_class)
{
}

static void
test_b_init (TestBIface *b_class)
{
}

static void
test_dp_obj_init (TestDpObj *self)
{
}

static void
set_property (GObject *object, guint prop_id,
              const GValue *value, GParamSpec *pspec)
{
	TestDpObjPrivate *priv = TEST_DP_OBJ_GET_PRIVATE (object);

	switch (prop_id) {
	case PROP_A_FOOBAR:
		priv->a_foobar = g_value_get_uint (value);
		break;
	case PROP_B_FOOBAR:
		priv->b_foobar = g_value_get_uint (value);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
get_property (GObject *object, guint prop_id,
              GValue *value, GParamSpec *pspec)
{
	TestDpObjPrivate *priv = TEST_DP_OBJ_GET_PRIVATE (object);

	switch (prop_id) {
	case PROP_A_FOOBAR:
		g_value_set_uint (value, priv->a_foobar);
		break;
	case PROP_B_FOOBAR:
		g_value_set_uint (value, priv->b_foobar);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
test_dp_obj_class_init (TestDpObjClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	g_type_class_add_private (object_class, sizeof (TestDpObjPrivate));

	object_class->get_property = get_property;
	object_class->set_property = set_property;

	/* Properties */
	g_object_class_override_property (object_class,
	                                  PROP_A_FOOBAR,
	                                  TEST_A_FOOBAR);

	g_object_class_override_property (object_class,
	                                  PROP_B_FOOBAR,
	                                  TEST_B_FOOBAR);
}