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 2007 - 2008 Novell, Inc.
19 * Copyright 2007 - 2012 Red Hat, Inc.
22 #include "nm-default.h"
26 #include "nm-vpn-connection.h"
27 #include "NetworkManager.h"
29 #include "nm-object-private.h"
30 #include "nm-active-connection.h"
32 G_DEFINE_TYPE (NMVPNConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION)
34 #define NM_VPN_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_VPN_CONNECTION, NMVPNConnectionPrivate))
39 NMVPNConnectionState vpn_state;
40 } NMVPNConnectionPrivate;
56 static guint signals[LAST_SIGNAL] = { 0 };
60 * nm_vpn_connection_new:
61 * @connection: the #DBusGConnection
62 * @path: the DBus object path of the new connection
64 * Creates a new #NMVPNConnection.
66 * Returns: (transfer full): a new connection object
69 nm_vpn_connection_new (DBusGConnection *connection, const char *path)
71 g_return_val_if_fail (connection != NULL, NULL);
72 g_return_val_if_fail (path != NULL, NULL);
74 return g_object_new (NM_TYPE_VPN_CONNECTION,
75 NM_OBJECT_DBUS_CONNECTION, connection,
76 NM_OBJECT_DBUS_PATH, path,
81 * nm_vpn_connection_get_banner:
82 * @vpn: a #NMVPNConnection
84 * Gets the VPN login banner of the active #NMVPNConnection.
86 * Returns: the VPN login banner of the VPN connection. This is the internal
87 * string used by the connection, and must not be modified.
90 nm_vpn_connection_get_banner (NMVPNConnection *vpn)
92 NMVPNConnectionPrivate *priv;
94 g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NULL);
96 priv = NM_VPN_CONNECTION_GET_PRIVATE (vpn);
98 /* We need to update vpn_state first in case it's unknown. */
99 _nm_object_ensure_inited (NM_OBJECT (vpn));
101 if (priv->vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED)
108 * nm_vpn_connection_get_vpn_state:
109 * @vpn: a #NMVPNConnection
111 * Gets the current #NMVPNConnection state.
113 * Returns: the VPN state of the active VPN connection.
116 nm_vpn_connection_get_vpn_state (NMVPNConnection *vpn)
118 g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_CONNECTION_STATE_UNKNOWN);
120 _nm_object_ensure_inited (NM_OBJECT (vpn));
121 return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->vpn_state;
125 vpn_state_changed_proxy (DBusGProxy *proxy,
126 NMVPNConnectionState vpn_state,
127 NMVPNConnectionStateReason reason,
130 NMVPNConnection *connection = NM_VPN_CONNECTION (user_data);
131 NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
133 if (priv->vpn_state != vpn_state) {
134 priv->vpn_state = vpn_state;
135 g_signal_emit (connection, signals[VPN_STATE_CHANGED], 0, vpn_state, reason);
136 g_object_notify (G_OBJECT (connection), NM_VPN_CONNECTION_VPN_STATE);
140 /*****************************************************************************/
143 nm_vpn_connection_init (NMVPNConnection *connection)
145 NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
147 priv->vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN;
151 register_properties (NMVPNConnection *connection)
153 NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
154 const NMPropertiesInfo property_info[] = {
155 { NM_VPN_CONNECTION_BANNER, &priv->banner },
156 { NM_VPN_CONNECTION_VPN_STATE, &priv->vpn_state },
160 _nm_object_register_properties (NM_OBJECT (connection),
166 constructed (GObject *object)
168 NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object);
170 G_OBJECT_CLASS (nm_vpn_connection_parent_class)->constructed (object);
172 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_VPN_CONNECTION);
174 dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
176 G_TYPE_UINT, G_TYPE_UINT,
178 dbus_g_proxy_add_signal (priv->proxy, "VpnStateChanged", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID);
179 dbus_g_proxy_connect_signal (priv->proxy,
181 G_CALLBACK (vpn_state_changed_proxy),
185 register_properties (NM_VPN_CONNECTION (object));
189 finalize (GObject *object)
191 NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object);
193 g_free (priv->banner);
194 g_object_unref (priv->proxy);
196 G_OBJECT_CLASS (nm_vpn_connection_parent_class)->finalize (object);
200 get_property (GObject *object,
205 NMVPNConnection *self = NM_VPN_CONNECTION (object);
207 _nm_object_ensure_inited (NM_OBJECT (object));
211 g_value_set_uint (value, nm_vpn_connection_get_vpn_state (self));
214 g_value_set_string (value, nm_vpn_connection_get_banner (self));
217 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
223 nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class)
225 GObjectClass *object_class = G_OBJECT_CLASS (connection_class);
227 g_type_class_add_private (connection_class, sizeof (NMVPNConnectionPrivate));
229 /* virtual methods */
230 object_class->constructed = constructed;
231 object_class->get_property = get_property;
232 object_class->finalize = finalize;
237 * NMVPNConnection:vpn-state:
239 * The VPN state of the active VPN connection.
241 g_object_class_install_property
242 (object_class, PROP_VPN_STATE,
243 g_param_spec_uint (NM_VPN_CONNECTION_VPN_STATE, "", "",
244 NM_VPN_CONNECTION_STATE_UNKNOWN,
245 NM_VPN_CONNECTION_STATE_DISCONNECTED,
246 NM_VPN_CONNECTION_STATE_UNKNOWN,
248 G_PARAM_STATIC_STRINGS));
251 * NMVPNConnection:banner:
253 * The VPN login banner of the active VPN connection.
255 g_object_class_install_property
256 (object_class, PROP_BANNER,
257 g_param_spec_string (NM_VPN_CONNECTION_BANNER, "", "",
260 G_PARAM_STATIC_STRINGS));
263 signals[VPN_STATE_CHANGED] =
264 g_signal_new ("vpn-state-changed",
265 G_OBJECT_CLASS_TYPE (object_class),
267 G_STRUCT_OFFSET (NMVPNConnectionClass, vpn_state_changed),
270 G_TYPE_UINT, G_TYPE_UINT);