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"
29 #include "nm-wimax-nsp.h"
30 #include "nm-dbus-interface.h"
31 #include "nm-object-private.h"
32 #include "nm-enum-types.h"
34 G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, NM_TYPE_OBJECT)
36 #define NM_WIMAX_NSP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_WIMAX_NSP, NMWimaxNspPrivate))
40 guint32 signal_quality;
41 NMWimaxNspNetworkType network_type;
54 * nm_wimax_nsp_get_name:
57 * Gets the name of the wimax NSP
62 nm_wimax_nsp_get_name (NMWimaxNsp *nsp)
64 g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NULL);
66 return NM_WIMAX_NSP_GET_PRIVATE (nsp)->name;
70 * nm_wimax_nsp_get_signal_quality:
73 * Gets the WPA signal quality of the wimax NSP.
75 * Returns: the signal quality
78 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp)
80 g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), 0);
82 return NM_WIMAX_NSP_GET_PRIVATE (nsp)->signal_quality;
86 * nm_wimax_nsp_get_network_type:
89 * Gets the network type of the wimax NSP.
91 * Returns: the network type
94 nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp)
96 g_return_val_if_fail (NM_IS_WIMAX_NSP (nsp), NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN);
98 return NM_WIMAX_NSP_GET_PRIVATE (nsp)->network_type;
102 * nm_wimax_nsp_connection_valid:
103 * @nsp: an #NMWimaxNsp to validate @connection against
104 * @connection: an #NMConnection to validate against @nsp
106 * Validates a given connection against a given WiMAX NSP to ensure that the
107 * connection may be activated with that NSP. The connection must match the
108 * @nsp's network name and other attributes.
110 * Returns: %TRUE if the connection may be activated with this WiMAX NSP,
111 * %FALSE if it cannot be.
114 nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection)
116 NMSettingConnection *s_con;
117 NMSettingWimax *s_wimax;
119 const char *nsp_name;
120 const char *setting_name;
122 s_con = nm_connection_get_setting_connection (connection);
124 ctype = nm_setting_connection_get_connection_type (s_con);
125 if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0)
128 s_wimax = nm_connection_get_setting_wimax (connection);
132 setting_name = nm_setting_wimax_get_network_name (s_wimax);
136 nsp_name = nm_wimax_nsp_get_name (nsp);
137 g_warn_if_fail (nsp_name != NULL);
138 if (g_strcmp0 (nsp_name, setting_name) != 0)
145 * nm_wimax_nsp_filter_connections:
146 * @nsp: an #NMWimaxNsp to filter connections for
147 * @connections: (element-type NMConnection): an array of #NMConnections to
150 * Filters a given array of connections for a given #NMWimaxNsp object and
151 * return connections which may be activated with the NSP. Any returned
152 * connections will match the @nsp's network name and other attributes.
154 * Returns: (transfer container) (element-type NMConnection): an array of
155 * #NMConnections that could be activated with the given @nsp. The array should
156 * be freed with g_ptr_array_unref() when it is no longer required.
159 nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GPtrArray *connections)
164 filtered = g_ptr_array_new_with_free_func (g_object_unref);
165 for (i = 0; i < connections->len; i++) {
166 NMConnection *candidate = connections->pdata[i];
168 if (nm_wimax_nsp_connection_valid (nsp, candidate))
169 g_ptr_array_add (filtered, g_object_ref (candidate));
175 /************************************************************/
178 nm_wimax_nsp_init (NMWimaxNsp *nsp)
183 finalize (GObject *object)
185 NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object);
189 G_OBJECT_CLASS (nm_wimax_nsp_parent_class)->finalize (object);
193 get_property (GObject *object,
198 NMWimaxNsp *nsp = NM_WIMAX_NSP (object);
202 g_value_set_string (value, nm_wimax_nsp_get_name (nsp));
204 case PROP_SIGNAL_QUALITY:
205 g_value_set_uint (value, nm_wimax_nsp_get_signal_quality (nsp));
207 case PROP_NETWORK_TYPE:
208 g_value_set_enum (value, nm_wimax_nsp_get_network_type (nsp));
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
217 init_dbus (NMObject *object)
219 NMWimaxNspPrivate *priv = NM_WIMAX_NSP_GET_PRIVATE (object);
220 const NMPropertiesInfo property_info[] = {
221 { NM_WIMAX_NSP_NAME, &priv->name },
222 { NM_WIMAX_NSP_SIGNAL_QUALITY, &priv->signal_quality },
223 { NM_WIMAX_NSP_NETWORK_TYPE, &priv->network_type },
227 NM_OBJECT_CLASS (nm_wimax_nsp_parent_class)->init_dbus (object);
229 _nm_object_register_properties (object,
230 NM_DBUS_INTERFACE_WIMAX_NSP,
235 nm_wimax_nsp_class_init (NMWimaxNspClass *nsp_class)
237 GObjectClass *object_class = G_OBJECT_CLASS (nsp_class);
238 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (nsp_class);
240 g_type_class_add_private (nsp_class, sizeof (NMWimaxNspPrivate));
242 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_WIMAX_NSP);
244 /* virtual methods */
245 object_class->get_property = get_property;
246 object_class->finalize = finalize;
248 nm_object_class->init_dbus = init_dbus;
255 * The name of the WiMAX NSP.
257 g_object_class_install_property
258 (object_class, PROP_NAME,
259 g_param_spec_string (NM_WIMAX_NSP_NAME, "", "",
262 G_PARAM_STATIC_STRINGS));
265 * NMWimaxNsp:signal-quality:
267 * The signal quality of the WiMAX NSP.
269 g_object_class_install_property
270 (object_class, PROP_SIGNAL_QUALITY,
271 g_param_spec_uint (NM_WIMAX_NSP_SIGNAL_QUALITY, "", "",
274 G_PARAM_STATIC_STRINGS));
277 * NMWimaxNsp:network-type:
279 * The network type of the WiMAX NSP.
281 g_object_class_install_property
282 (object_class, PROP_NETWORK_TYPE,
283 g_param_spec_enum (NM_WIMAX_NSP_NETWORK_TYPE, "", "",
284 NM_TYPE_WIMAX_NSP_NETWORK_TYPE,
285 NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN,
287 G_PARAM_STATIC_STRINGS));