~ubuntu-branches/ubuntu/precise/network-manager/precise

« back to all changes in this revision

Viewing changes to libnm-glib/nm-dbus-utils.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-02-09 16:45:41 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20120209164541-4h90zknlsfdb7x35
Tags: 0.9.2.0+git201202091925.c721477-0ubuntu1
* upstream snapshot 2012-02-09 19:25:59 (GMT)
  + c721477d11d4fe144111d6d2eec8f93f2e9186c9
* debian/patches/avoid-periodic-disk-wakeups.patch: refreshed.
* debian/patches/nl3-default-ip6-route.patch: refreshed.
* debian/libnm-glib4.symbols: add symbols:
  + nm_active_connection_get_master@Base
  + nm_client_new_async@Base
  + nm_client_new_finish@Base
  + nm_remote_settings_new_async@Base
  + nm_remote_settings_new_finish@Base
  + nm_device_get_state_reason@Base
* debian/libnm-util2.symbols: add symbols:
  + nm_setting_802_1x_get_pac_file@Base
  + nm_setting_infiniband_get_transport_mode@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
 
/*
3
 
 * libnm_glib -- Access network status & information from glib applications
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Lesser General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the
17
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301 USA.
19
 
 *
20
 
 * Copyright (C) 2007 - 2008 Novell, Inc.
21
 
 */
22
 
 
23
 
#include "nm-dbus-utils.h"
24
 
 
25
 
char *
26
 
_nm_dbus_get_string_property (DBusGProxy *proxy,
27
 
                                                         const char *interface,
28
 
                                                         const char *prop_name)
29
 
{
30
 
        GError *err = NULL;
31
 
        char *str = NULL;
32
 
        GValue value = {0,};
33
 
 
34
 
        g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
35
 
 
36
 
        if (dbus_g_proxy_call (proxy, "Get", &err,
37
 
                                                   G_TYPE_STRING, interface,
38
 
                                                   G_TYPE_STRING, prop_name,
39
 
                                                   G_TYPE_INVALID,
40
 
                                                   G_TYPE_VALUE, &value,
41
 
                                                   G_TYPE_INVALID)) {
42
 
                str = g_strdup (g_value_get_string (&value));
43
 
        } else {
44
 
                g_warning ("Error in device_get_property: %s\n", err->message);
45
 
                g_error_free (err);
46
 
        }
47
 
 
48
 
        return str;
49
 
}
50
 
 
51
 
char *
52
 
_nm_dbus_get_object_path_property (DBusGProxy *proxy,
53
 
                                                                  const char *interface,
54
 
                                                                  const char *prop_name)
55
 
{
56
 
        GError *err = NULL;
57
 
        char *path = NULL;
58
 
        GValue value = {0,};
59
 
 
60
 
        g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), NULL);
61
 
 
62
 
        if (dbus_g_proxy_call (proxy, "Get", &err,
63
 
                                                   G_TYPE_STRING, interface,
64
 
                                                   G_TYPE_STRING, prop_name,
65
 
                                                   G_TYPE_INVALID,
66
 
                                                   G_TYPE_VALUE, &value,
67
 
                                                   G_TYPE_INVALID)) {
68
 
                path = g_strdup (g_value_get_boxed (&value));
69
 
        } else {
70
 
                g_warning ("Error in device_get_property: %s\n", err->message);
71
 
                g_error_free (err);
72
 
        }
73
 
 
74
 
        return path;
75
 
}
76
 
 
77
 
gint32
78
 
_nm_dbus_get_int_property (DBusGProxy *proxy,
79
 
                                                  const char *interface,
80
 
                                                  const char *prop_name)
81
 
{
82
 
        GError *err = NULL;
83
 
        gint32 i = 0;
84
 
        GValue value = {0,};
85
 
 
86
 
        g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), 0);
87
 
 
88
 
        if (dbus_g_proxy_call (proxy, "Get", &err,
89
 
                                                   G_TYPE_STRING, interface,
90
 
                                                   G_TYPE_STRING, prop_name,
91
 
                                                   G_TYPE_INVALID,
92
 
                                                   G_TYPE_VALUE, &value,
93
 
                                                   G_TYPE_INVALID)) {
94
 
                i = g_value_get_int (&value);
95
 
        } else {
96
 
                g_warning ("Error in device_get_property: %s\n", err->message);
97
 
                g_error_free (err);
98
 
        }
99
 
 
100
 
        return i;
101
 
}
102
 
 
103
 
guint32
104
 
_nm_dbus_get_uint_property (DBusGProxy *proxy,
105
 
                                                   const char *interface,
106
 
                                                   const char *prop_name)
107
 
{
108
 
        GError *err = NULL;
109
 
        guint32 i = 0;
110
 
        GValue value = {0,};
111
 
 
112
 
        g_return_val_if_fail (DBUS_IS_G_PROXY (proxy), 0);
113
 
 
114
 
        if (dbus_g_proxy_call (proxy, "Get", &err,
115
 
                                                   G_TYPE_STRING, interface,
116
 
                                                   G_TYPE_STRING, prop_name,
117
 
                                                   G_TYPE_INVALID,
118
 
                                                   G_TYPE_VALUE, &value,
119
 
                                                   G_TYPE_INVALID)) {
120
 
                i = g_value_get_uint (&value);
121
 
        } else {
122
 
                g_warning ("Error in device_get_property: %s\n", err->message);
123
 
                g_error_free (err);
124
 
        }
125
 
 
126
 
        return i;
127
 
}
128
 
 
129
 
gboolean
130
 
_nm_dbus_get_property (DBusGProxy *proxy,
131
 
                                          const char *interface,
132
 
                                          const char *prop_name,
133
 
                                          GValue *value)
134
 
{
135
 
        DBusGProxy *properties_proxy;
136
 
        GError *err = NULL;
137
 
        gboolean ret = TRUE;
138
 
 
139
 
        g_return_val_if_fail (proxy != NULL, FALSE);
140
 
        g_return_val_if_fail (interface != NULL, FALSE);
141
 
        g_return_val_if_fail (prop_name != NULL, FALSE);
142
 
 
143
 
        properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
144
 
                                                                                                        "org.freedesktop.DBus.Properties",
145
 
                                                                                                        dbus_g_proxy_get_path (proxy));
146
 
 
147
 
        if (!dbus_g_proxy_call (properties_proxy, "Get", &err,
148
 
                                                        G_TYPE_STRING, interface,
149
 
                                                        G_TYPE_STRING, prop_name,
150
 
                                                        G_TYPE_INVALID,
151
 
                                                        G_TYPE_VALUE, value,
152
 
                                                        G_TYPE_INVALID)) {
153
 
                g_warning ("Error in device_get_property: %s\n", err->message);
154
 
                g_error_free (err);
155
 
                ret = FALSE;
156
 
        }
157
 
 
158
 
        g_object_unref (properties_proxy);
159
 
 
160
 
        return ret;
161
 
}
162
 
 
163
 
void
164
 
_nm_dbus_set_property (DBusGProxy *proxy,
165
 
                                          const char *interface,
166
 
                                          const char *prop_name,
167
 
                                          GValue *value)
168
 
{
169
 
        DBusGProxy *properties_proxy;
170
 
 
171
 
        g_return_if_fail (proxy != NULL);
172
 
        g_return_if_fail (interface != NULL);
173
 
        g_return_if_fail (prop_name != NULL);
174
 
 
175
 
        properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
176
 
                                                                                                        "org.freedesktop.DBus.Properties",
177
 
                                                                                                        dbus_g_proxy_get_path (proxy));
178
 
 
179
 
        dbus_g_proxy_call_no_reply (properties_proxy, "Set",
180
 
                                                                G_TYPE_STRING, interface,
181
 
                                                                G_TYPE_STRING, prop_name,
182
 
                                                                G_TYPE_VALUE, value,
183
 
                                                                G_TYPE_INVALID);
184
 
 
185
 
        g_object_unref (properties_proxy);
186
 
}
187
 
 
188
 
char *
189
 
_nm_dbus_introspect (DBusGConnection *connection,
190
 
                                        const char *interface,
191
 
                                        const char *path)
192
 
{
193
 
        DBusGProxy *remote_object_introspectable;
194
 
        char *introspect_data = NULL;
195
 
        GError *err = NULL;
196
 
 
197
 
        g_return_val_if_fail (connection != NULL, NULL);
198
 
        g_return_val_if_fail (interface != NULL, NULL);
199
 
        g_return_val_if_fail (path != NULL, NULL);
200
 
 
201
 
        remote_object_introspectable = dbus_g_proxy_new_for_name (connection,
202
 
                                                                                                                          interface,
203
 
                                                                                                                          path,
204
 
                                                                                                                          "org.freedesktop.DBus.Introspectable");
205
 
        if (!dbus_g_proxy_call (remote_object_introspectable, "Introspect", &err,
206
 
                                                        G_TYPE_INVALID,
207
 
                                                        G_TYPE_STRING, &introspect_data, G_TYPE_INVALID)) {
208
 
                g_error ("Failed to complete Introspect %s", err->message);
209
 
                g_error_free (err);
210
 
        }
211
 
 
212
 
        g_object_unref (G_OBJECT (remote_object_introspectable));
213
 
 
214
 
        return introspect_data;
215
 
}