core: storing timestamps also for VPN connections (rh #725353)

This commit is contained in:
Jiří Klimeš 2011-09-15 14:21:45 +02:00
parent 91b93c1352
commit 53b85b13be
3 changed files with 57 additions and 15 deletions

View file

@ -214,7 +214,8 @@ typedef struct {
gboolean net_enabled;
NMVPNManager *vpn_manager;
guint vpn_manager_id;
gulong vpn_manager_activated_id;
gulong vpn_manager_deactivated_id;
NMModemManager *modem_manager;
guint modem_added_id;
@ -376,6 +377,18 @@ manager_sleeping (NMManager *self)
return FALSE;
}
static void
vpn_manager_connection_activated_cb (NMVPNManager *manager,
NMVPNConnection *vpn,
NMVPNConnectionState state,
NMVPNConnectionStateReason reason,
gpointer user_data)
{
/* Update timestamp for the VPN connection */
nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_vpn_connection_get_connection (vpn)),
(guint64) time (NULL));
}
static void
vpn_manager_connection_deactivated_cb (NMVPNManager *manager,
NMVPNConnection *vpn,
@ -3159,9 +3172,13 @@ dispose (GObject *object)
g_object_unref (priv->settings);
if (priv->vpn_manager_id) {
g_source_remove (priv->vpn_manager_id);
priv->vpn_manager_id = 0;
if (priv->vpn_manager_activated_id) {
g_source_remove (priv->vpn_manager_activated_id);
priv->vpn_manager_activated_id = 0;
}
if (priv->vpn_manager_deactivated_id) {
g_source_remove (priv->vpn_manager_deactivated_id);
priv->vpn_manager_deactivated_id = 0;
}
g_object_unref (priv->vpn_manager);
@ -3402,6 +3419,7 @@ static gboolean
periodic_update_active_connection_timestamps (gpointer user_data)
{
NMManager *manager = NM_MANAGER (user_data);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
GPtrArray *active;
int i;
@ -3416,6 +3434,15 @@ periodic_update_active_connection_timestamps (gpointer user_data)
if (device && nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED)
nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_act_request_get_connection (req)),
(guint64) time (NULL));
else {
/* The connection is probably VPN */
NMVPNConnection *vpn_con;
vpn_con = nm_vpn_manager_get_vpn_connection_for_active (priv->vpn_manager, active_path);
if (vpn_con && nm_vpn_connection_get_vpn_state (vpn_con) == NM_VPN_CONNECTION_STATE_ACTIVATED)
nm_settings_connection_update_timestamp (NM_SETTINGS_CONNECTION (nm_vpn_connection_get_connection (vpn_con)),
(guint64) time (NULL));
}
}
return TRUE;
@ -3426,7 +3453,7 @@ nm_manager_init (NMManager *manager)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
DBusGConnection *g_connection;
guint id, i;
guint i;
GFile *file;
/* Initialize rfkill structures and states */
@ -3471,9 +3498,10 @@ nm_manager_init (NMManager *manager)
G_CALLBACK (modem_removed), manager);
priv->vpn_manager = nm_vpn_manager_get ();
id = g_signal_connect (G_OBJECT (priv->vpn_manager), "connection-deactivated",
G_CALLBACK (vpn_manager_connection_deactivated_cb), manager);
priv->vpn_manager_id = id;
priv->vpn_manager_activated_id = g_signal_connect (G_OBJECT (priv->vpn_manager), "connection-activated",
G_CALLBACK (vpn_manager_connection_activated_cb), manager);
priv->vpn_manager_deactivated_id = g_signal_connect (G_OBJECT (priv->vpn_manager), "connection-deactivated",
G_CALLBACK (vpn_manager_connection_deactivated_cb), manager);
g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2005 - 2010 Red Hat, Inc.
* Copyright (C) 2005 - 2011 Red Hat, Inc.
* Copyright (C) 2006 - 2008 Novell, Inc.
*/
@ -306,9 +306,9 @@ nm_vpn_manager_get_active_connections (NMVPNManager *self)
return list;
}
NMConnection *
nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
const char *active_path)
NMVPNConnection *
nm_vpn_manager_get_vpn_connection_for_active (NMVPNManager *manager,
const char *active_path)
{
NMVPNManagerPrivate *priv;
GHashTableIter iter;
@ -327,13 +327,24 @@ nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
ac_path = nm_vpn_connection_get_active_connection_path (vpn);
if (ac_path && !strcmp (ac_path, active_path))
return nm_vpn_connection_get_connection (vpn);
return vpn;
}
}
return NULL;
}
NMConnection *
nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
const char *active_path)
{
NMVPNConnection *vpn_con;
vpn_con = nm_vpn_manager_get_vpn_connection_for_active (manager, active_path);
return vpn_con ? nm_vpn_connection_get_connection (vpn_con) : NULL;
}
static char *
service_name_from_file (const char *path)
{

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2005 - 2008 Red Hat, Inc.
* Copyright (C) 2005 - 2011 Red Hat, Inc.
* Copyright (C) 2006 - 2008 Novell, Inc.
*/
@ -83,7 +83,10 @@ void nm_vpn_manager_add_active_connections (NMVPNManager *manager,
GSList *nm_vpn_manager_get_active_connections (NMVPNManager *manager);
NMVPNConnection *nm_vpn_manager_get_vpn_connection_for_active (NMVPNManager *manager,
const char *active_path);
NMConnection *nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
const char *active_path);
#endif /* NM_VPN_VPN_MANAGER_H */
#endif /* NM_VPN_MANAGER_H */