1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2011 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-connection.h"
26 #include "nm-setting-connection.h"
27 #include "nm-setting-wimax.h"
28 #include "nm-wimax-nsp.h"
29 #include "NetworkManager.h"
30 #include "nm-types-private.h"
31 #include "nm-object-private.h"
33 G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, NM_TYPE_OBJECT)
35 #define NM_WIMAX_NSP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_WIMAX_NSP, NMWimaxNspPrivate))
41 guint32 signal_quality;
42 NMWimaxNspNetworkType network_type;
56 * @connection: the #DBusGConnection
57 * @path: the D-Bus object path of the WiMAX NSP
59 * Creates a new #NMWimaxNsp.
61 * Returns: (transfer full): a new WiMAX NSP
64 nm_wimax_nsp_new (DBusGConnection *connection, const char *path)
66 g_return_val_if_fail (connection != NULL, NULL);
67 g_return_val_if_fail (path != NULL, NULL);
69 return (GObject *) g_object_new (NM_TYPE_WIMAX_NSP,
70 NM_OBJECT_DBUS_CONNECTION, connection,
71 NM_OBJECT_DBUS_PATH, path,
76 * nm_wimax_nsp_get_name:
79 * Gets the name of the wimax NSP
84 nm_wimax_nsp_get_name (NMWimaxNsp *nsp)
86 g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NULL);
88 _nm_object_ensure_inited (NM_OBJECT (nsp));
89 return NM_WIMAX_NSP_GET_PRIVATE (nsp)->name;
93 * nm_wimax_nsp_get_signal_quality:
96 * Gets the WPA signal quality of the wimax NSP.
98 * Returns: the signal quality
101 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp)
103 g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), 0);
105 _nm_object_ensure_inited (NM_OBJECT (nsp));
106 return NM_WIMAX_NSP_GET_PRIVATE (nsp)->signal_quality;
110 * nm_wimax_nsp_get_network_type:
111 * @nsp: a #NMWimaxNsp
113 * Gets the network type of the wimax NSP.
115 * Returns: the network type
117 NMWimaxNspNetworkType
118 nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp)
120 g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN);
122 _nm_object_ensure_inited (NM_OBJECT (nsp));
123 return NM_WIMAX_NSP_GET_PRIVATE (nsp)->network_type;
127 * nm_wimax_nsp_connection_valid:
128 * @nsp: an #NMWimaxNsp to validate @connection against
129 * @connection: an #NMConnection to validate against @nsp
131 * Validates a given connection against a given WiMAX NSP to ensure that the
132 * connection may be activated with that NSP. The connection must match the
133 * @nsp's network name and other attributes.
135 * Returns: %TRUE if the connection may be activated with this WiMAX NSP,
136 * %FALSE if it cannot be.
139 nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection)
141 NMSettingConnection *s_con;
142 NMSettingWimax *s_wimax;
144 const char *nsp_name;
145 const char *setting_name;
147 s_con = nm_connection_get_setting_connection (connection);
149 ctype = nm_setting_connection_get_connection_type (s_con);
150 if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0)
153 s_wimax = nm_connection_get_setting_wimax (connection);
157 setting_name = nm_setting_wimax_get_network_name (s_wimax);
161 nsp_name = nm_wimax_nsp_get_name (nsp);
162 g_warn_if_fail (nsp_name != NULL);
163 if (g_strcmp0 (nsp_name, setting_name) != 0)
170 * nm_wimax_nsp_filter_connections:
171 * @nsp: an #NMWimaxNsp to filter connections for
172 * @connections: (element-type NMConnection): a list of
173 * #NMConnection objects to filter
175 * Filters a given list of connections for a given #NMWimaxNsp object and
176 * return connections which may be activated with the access point. Any
177 * returned connections will match the @nsp's network name and other attributes.
179 * Returns: (transfer container) (element-type NMConnection): a
180 * list of #NMConnection objects that could be activated with the given @nsp.
181 * The elements of the list are owned by their creator and should not be freed
182 * by the caller, but the returned list itself is owned by the caller and should
183 * be freed with g_slist_free() when it is no longer required.
186 nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GSList *connections)
188 GSList *filtered = NULL;
191 for (iter = connections; iter; iter = g_slist_next (iter)) {
192 NMConnection *candidate = NM_CONNECTION (iter->data);
194 if (nm_wimax_nsp_connection_valid (nsp, candidate))
195 filtered = g_slist_prepend (filtered, candidate);
198 return g_slist_reverse (filtered);
201 /************************************************************/
204 nm_wimax_nsp_init (NMWimaxNsp *nsp)
209 dispose (GObject *object)
211 NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object);
213 g_clear_object (&priv->proxy);
215 G_OBJECT_CLASS (nm_wimax_nsp_parent_class)->dispose (object);
219 finalize (GObject *object)
221 NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object);
225 G_OBJECT_CLASS (nm_wimax_nsp_parent_class)->finalize (object);
229 get_property (GObject *object,
234 NMWimaxNsp *nsp = NM_WIMAX_NSP (object);
236 _nm_object_ensure_inited (NM_OBJECT (object));
240 g_value_set_string (value, nm_wimax_nsp_get_name (nsp));
242 case PROP_SIGNAL_QUALITY:
243 g_value_set_uint (value, nm_wimax_nsp_get_signal_quality (nsp));
245 case PROP_NETWORK_TYPE:
246 g_value_set_uint (value, nm_wimax_nsp_get_network_type (nsp));
249 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255 register_properties (NMWimaxNsp *nsp)
257 NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (nsp);
258 const NMPropertiesInfo property_info[] = {
259 { NM_WIMAX_NSP_NAME, &priv->name },
260 { NM_WIMAX_NSP_SIGNAL_QUALITY, &priv->signal_quality },
261 { NM_WIMAX_NSP_NETWORK_TYPE, &priv->network_type },
265 _nm_object_register_properties (NM_OBJECT (nsp),
271 constructed (GObject *object)
273 NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object);
275 G_OBJECT_CLASS (nm_wimax_nsp_parent_class)->constructed (object);
277 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_WIMAX_NSP);
278 register_properties (NM_WIMAX_NSP (object));
283 nm_wimax_nsp_class_init (NMWimaxNspClass *nsp_class)
285 GObjectClass *object_class = G_OBJECT_CLASS (nsp_class);
287 g_type_class_add_private (nsp_class, sizeof (NMWimaxNspPrivate));
289 /* virtual methods */
290 object_class->constructed = constructed;
291 object_class->get_property = get_property;
292 object_class->dispose = dispose;
293 object_class->finalize = finalize;
300 * The name of the WiMAX NSP.
302 g_object_class_install_property
303 (object_class, PROP_NAME,
304 g_param_spec_string (NM_WIMAX_NSP_NAME, "", "",
307 G_PARAM_STATIC_STRINGS));
310 * NMWimaxNsp:signal-quality:
312 * The signal quality of the WiMAX NSP.
314 g_object_class_install_property
315 (object_class, PROP_SIGNAL_QUALITY,
316 g_param_spec_uint (NM_WIMAX_NSP_SIGNAL_QUALITY, "", "",
319 G_PARAM_STATIC_STRINGS));
322 * NMWimaxNsp:network-type:
324 * The network type of the WiMAX NSP.
326 g_object_class_install_property
327 (object_class, PROP_NETWORK_TYPE,
328 g_param_spec_uint (NM_WIMAX_NSP_NETWORK_TYPE, "", "",
331 G_PARAM_STATIC_STRINGS));