summaryrefslogtreecommitdiff
path: root/libnm-glib/nm-dbus-utils.c
blob: 1620464c5d583359695ed918983d4cd2eda35255 (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
#include "nm-dbus-utils.h"

char *
nm_dbus_get_string_property (DBusGProxy *proxy,
							 const char *interface,
							 const char *prop_name)
{
	GError *err = NULL;
	char *str = NULL;
	GValue value = {0,};

	g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);

	if (dbus_g_proxy_call (proxy, "Get", &err,
						   G_TYPE_STRING, interface,
						   G_TYPE_STRING, prop_name,
						   G_TYPE_INVALID,
						   G_TYPE_VALUE, &value,
						   G_TYPE_INVALID)) {
		str = g_strdup (g_value_get_string (&value));
	} else {
		g_warning ("Error in device_get_property: %s\n", err->message);
		g_error_free (err);
	}

	return str;
}

char *
nm_dbus_get_object_path_property (DBusGProxy *proxy,
								  const char *interface,
								  const char *prop_name)
{
	GError *err = NULL;
	char *path = NULL;
	GValue value = {0,};

	g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);

	if (dbus_g_proxy_call (proxy, "Get", &err,
						   G_TYPE_STRING, interface,
						   G_TYPE_STRING, prop_name,
						   G_TYPE_INVALID,
						   G_TYPE_VALUE, &value,
						   G_TYPE_INVALID)) {
		path = g_strdup (g_value_get_boxed (&value));
	} else {
		g_warning ("Error in device_get_property: %s\n", err->message);
		g_error_free (err);
	}

	return path;
}

gint32
nm_dbus_get_int_property (DBusGProxy *proxy,
						  const char *interface,
						  const char *prop_name)
{
	GError *err = NULL;
	gint32 i = 0;
	GValue value = {0,};

	g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), 0);

	if (dbus_g_proxy_call (proxy, "Get", &err,
						   G_TYPE_STRING, interface,
						   G_TYPE_STRING, prop_name,
						   G_TYPE_INVALID,
						   G_TYPE_VALUE, &value,
						   G_TYPE_INVALID)) {
		i = g_value_get_int (&value);
	} else {
		g_warning ("Error in device_get_property: %s\n", err->message);
		g_error_free (err);
	}

	return i;
}

guint32
nm_dbus_get_uint_property (DBusGProxy *proxy,
						   const char *interface,
						   const char *prop_name)
{
	GError *err = NULL;
	guint32 i = 0;
	GValue value = {0,};

	g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), 0);

	if (dbus_g_proxy_call (proxy, "Get", &err,
						   G_TYPE_STRING, interface,
						   G_TYPE_STRING, prop_name,
						   G_TYPE_INVALID,
						   G_TYPE_VALUE, &value,
						   G_TYPE_INVALID)) {
		i = g_value_get_uint (&value);
	} else {
		g_warning ("Error in device_get_property: %s\n", err->message);
		g_error_free (err);
	}

	return i;
}

gboolean
nm_dbus_get_property (DBusGProxy *proxy,
					  const char *interface,
					  const char *prop_name,
					  GValue *value)
{
	DBusGProxy *properties_proxy;
	GError *err = NULL;
	gboolean ret = TRUE;

	g_return_val_if_fail (proxy != NULL, FALSE);
	g_return_val_if_fail (interface != NULL, FALSE);
	g_return_val_if_fail (prop_name != NULL, FALSE);

	properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
													"org.freedesktop.DBus.Properties",
													dbus_g_proxy_get_path (proxy));

	if (!dbus_g_proxy_call (properties_proxy, "Get", &err,
							G_TYPE_STRING, interface,
							G_TYPE_STRING, prop_name,
							G_TYPE_INVALID,
							G_TYPE_VALUE, value,
							G_TYPE_INVALID)) {
		g_warning ("Error in device_get_property: %s\n", err->message);
		g_error_free (err);
		ret = FALSE;
	}

	g_object_unref (properties_proxy);

	return ret;
}

void
nm_dbus_set_property (DBusGProxy *proxy,
					  const char *interface,
					  const char *prop_name,
					  GValue *value)
{
	DBusGProxy *properties_proxy;

	g_return_if_fail (proxy != NULL);
	g_return_if_fail (interface != NULL);
	g_return_if_fail (prop_name != NULL);

	properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
													"org.freedesktop.DBus.Properties",
													dbus_g_proxy_get_path (proxy));

	dbus_g_proxy_call_no_reply (properties_proxy, "Set",
								G_TYPE_STRING, interface,
								G_TYPE_STRING, prop_name,
								G_TYPE_VALUE, value,
								G_TYPE_INVALID);

	g_object_unref (properties_proxy);
}

char *
nm_dbus_introspect (DBusGConnection *connection,
					const char *interface,
					const char *path)
{
	DBusGProxy *remote_object_introspectable;
	char *introspect_data = NULL;
	GError *err = NULL;

	g_return_val_if_fail (connection != NULL, NULL);
	g_return_val_if_fail (interface != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);

	remote_object_introspectable = dbus_g_proxy_new_for_name (connection,
															  interface,
															  path,
															  "org.freedesktop.DBus.Introspectable");
	if (!dbus_g_proxy_call (remote_object_introspectable, "Introspect", &err,
							G_TYPE_INVALID,
							G_TYPE_STRING, &introspect_data, G_TYPE_INVALID)) {
		g_error ("Failed to complete Introspect %s", err->message);
		g_error_free (err);
	}

	g_object_unref (G_OBJECT (remote_object_introspectable));

	return introspect_data;
}