diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index 9d28d803a0..dfe0b54a59 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -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 - 2011 Red Hat, Inc. + * Copyright (C) 2005 - 2012 Red Hat, Inc. * Copyright (C) 2007 - 2008 Novell, Inc. */ @@ -34,25 +34,16 @@ #include "nm-setting-8021x.h" #include "nm-dbus-manager.h" #include "nm-device.h" -#include "nm-properties-changed-signal.h" #include "nm-active-connection.h" -#include "nm-dbus-glib-types.h" -#include "nm-active-connection-glue.h" #include "nm-settings-connection.h" -G_DEFINE_TYPE (NMActRequest, nm_act_request, G_TYPE_OBJECT) +G_DEFINE_TYPE (NMActRequest, nm_act_request, NM_TYPE_ACTIVE_CONNECTION) #define NM_ACT_REQUEST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ NM_TYPE_ACT_REQUEST, \ NMActRequestPrivate)) -enum { - PROPERTIES_CHANGED, - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL] = { 0 }; - typedef struct { char *table; char *rule; @@ -65,35 +56,18 @@ typedef struct { GSList *secrets_calls; - char *specific_object; NMDevice *device; gboolean user_requested; gulong user_uid; - NMActiveConnectionState state; - gboolean is_default; - gboolean is_default6; gboolean shared; GSList *share_rules; - char *ac_path; - gboolean assumed; } NMActRequestPrivate; enum { - PROP_0, - PROP_CONNECTION, - PROP_UUID, - PROP_SPECIFIC_OBJECT, - PROP_DEVICES, - PROP_STATE, - PROP_DEFAULT, - PROP_DEFAULT6, - PROP_VPN, - PROP_MASTER, - - LAST_PROP + PROP_MASTER = 2000, }; /*******************************************************************/ @@ -200,29 +174,6 @@ nm_act_request_get_connection (NMActRequest *req) return NM_ACT_REQUEST_GET_PRIVATE (req)->connection; } -const char * -nm_act_request_get_specific_object (NMActRequest *req) -{ - g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL); - - return NM_ACT_REQUEST_GET_PRIVATE (req)->specific_object; -} - -void -nm_act_request_set_specific_object (NMActRequest *req, - const char *specific_object) -{ - NMActRequestPrivate *priv; - - g_return_if_fail (NM_IS_ACT_REQUEST (req)); - g_return_if_fail (specific_object != NULL); - - priv = NM_ACT_REQUEST_GET_PRIVATE (req); - - g_free (priv->specific_object); - priv->specific_object = g_strdup (specific_object); -} - gboolean nm_act_request_get_user_requested (NMActRequest *req) { @@ -231,60 +182,6 @@ nm_act_request_get_user_requested (NMActRequest *req) return NM_ACT_REQUEST_GET_PRIVATE (req)->user_requested; } -const char * -nm_act_request_get_active_connection_path (NMActRequest *req) -{ - g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NULL); - - return NM_ACT_REQUEST_GET_PRIVATE (req)->ac_path; -} - -void -nm_act_request_set_default (NMActRequest *req, gboolean is_default) -{ - NMActRequestPrivate *priv; - - g_return_if_fail (NM_IS_ACT_REQUEST (req)); - - priv = NM_ACT_REQUEST_GET_PRIVATE (req); - if (priv->is_default == is_default) - return; - - priv->is_default = is_default; - g_object_notify (G_OBJECT (req), NM_ACTIVE_CONNECTION_DEFAULT); -} - -gboolean -nm_act_request_get_default (NMActRequest *req) -{ - g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE); - - return NM_ACT_REQUEST_GET_PRIVATE (req)->is_default; -} - -void -nm_act_request_set_default6 (NMActRequest *req, gboolean is_default6) -{ - NMActRequestPrivate *priv; - - g_return_if_fail (NM_IS_ACT_REQUEST (req)); - - priv = NM_ACT_REQUEST_GET_PRIVATE (req); - if (priv->is_default6 == is_default6) - return; - - priv->is_default6 = is_default6; - g_object_notify (G_OBJECT (req), NM_ACTIVE_CONNECTION_DEFAULT6); -} - -gboolean -nm_act_request_get_default6 (NMActRequest *req) -{ - g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE); - - return NM_ACT_REQUEST_GET_PRIVATE (req)->is_default6; -} - GObject * nm_act_request_get_device (NMActRequest *req) { @@ -424,9 +321,7 @@ device_state_changed (NMDevice *device, gpointer user_data) { NMActRequest *self = NM_ACT_REQUEST (user_data); - NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (self); NMActiveConnectionState new_ac_state; - gboolean new_default = FALSE, new_default6 = FALSE; /* Set NMActiveConnection state based on the device's state */ switch (new_state) { @@ -440,32 +335,18 @@ device_state_changed (NMDevice *device, break; case NM_DEVICE_STATE_ACTIVATED: new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; - new_default = priv->is_default; - new_default6 = priv->is_default6; break; case NM_DEVICE_STATE_DEACTIVATING: new_ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING; break; default: new_ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; - new_default = new_default6 = FALSE; + nm_active_connection_set_default (NM_ACTIVE_CONNECTION (self), FALSE); + nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (self), FALSE); break; } - if (new_ac_state != priv->state) { - priv->state = new_ac_state; - g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_STATE); - } - - if (new_default != priv->is_default) { - priv->is_default = new_default; - g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_DEFAULT); - } - - if (new_default6 != priv->is_default6) { - priv->is_default6 = new_default6; - g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_DEFAULT6); - } + nm_active_connection_set_state (NM_ACTIVE_CONNECTION (self), new_ac_state); } /********************************************************************/ @@ -484,16 +365,15 @@ nm_act_request_new (NMConnection *connection, g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_DEVICE (device), NULL); - object = g_object_new (NM_TYPE_ACT_REQUEST, NULL); + object = g_object_new (NM_TYPE_ACT_REQUEST, + NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, + NULL); if (!object) return NULL; priv = NM_ACT_REQUEST_GET_PRIVATE (object); priv->connection = g_object_ref (connection); - if (specific_object) - priv->specific_object = g_strdup (specific_object); - priv->device = NM_DEVICE (device); g_signal_connect (device, "state-changed", G_CALLBACK (device_state_changed), @@ -503,23 +383,19 @@ nm_act_request_new (NMConnection *connection, priv->user_requested = user_requested; priv->assumed = assumed; - return NM_ACT_REQUEST (object); + if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (object), + connection, + nm_device_get_path (NM_DEVICE (device)))) { + g_object_unref (object); + object = NULL; + } + + return (NMActRequest *) object; } static void nm_act_request_init (NMActRequest *req) { - NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (req); - NMDBusManager *dbus_mgr; - - priv->ac_path = nm_active_connection_get_next_object_path (); - priv->state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; - - dbus_mgr = nm_dbus_manager_get (); - dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr), - priv->ac_path, - G_OBJECT (req)); - g_object_unref (dbus_mgr); } static void @@ -527,38 +403,8 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); - GPtrArray *devices; switch (prop_id) { - case PROP_CONNECTION: - g_value_set_boxed (value, nm_connection_get_path (priv->connection)); - break; - case PROP_UUID: - g_value_set_string (value, nm_connection_get_uuid (priv->connection)); - break; - case PROP_SPECIFIC_OBJECT: - if (priv->specific_object) - g_value_set_boxed (value, priv->specific_object); - else - g_value_set_boxed (value, "/"); - break; - case PROP_DEVICES: - devices = g_ptr_array_sized_new (1); - g_ptr_array_add (devices, g_strdup (nm_device_get_path (priv->device))); - g_value_take_boxed (value, devices); - break; - case PROP_STATE: - g_value_set_uint (value, priv->state); - break; - case PROP_DEFAULT: - g_value_set_boolean (value, priv->is_default); - break; - case PROP_DEFAULT6: - g_value_set_boolean (value, priv->is_default6); - break; - case PROP_VPN: - g_value_set_boolean (value, FALSE); - break; case PROP_MASTER: g_value_set_string (value, nm_device_get_master_path (priv->device)); break; @@ -605,11 +451,6 @@ dispose (GObject *object) static void finalize (GObject *object) { - NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); - - g_free (priv->specific_object); - g_free (priv->ac_path); - clear_share_rules (NM_ACT_REQUEST (object)); G_OBJECT_CLASS (nm_act_request_parent_class)->finalize (object); @@ -627,24 +468,6 @@ nm_act_request_class_init (NMActRequestClass *req_class) object_class->dispose = dispose; object_class->finalize = finalize; - /* properties */ - nm_active_connection_install_properties (object_class, - PROP_CONNECTION, - PROP_UUID, - PROP_SPECIFIC_OBJECT, - PROP_DEVICES, - PROP_STATE, - PROP_DEFAULT, - PROP_DEFAULT6, - PROP_VPN, - PROP_MASTER); - - /* Signals */ - signals[PROPERTIES_CHANGED] = - nm_properties_changed_signal_new (object_class, - G_STRUCT_OFFSET (NMActRequestClass, properties_changed)); - - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (req_class), - &dbus_glib_nm_active_connection_object_info); + g_object_class_override_property (object_class, PROP_MASTER, NM_ACTIVE_CONNECTION_MASTER); } diff --git a/src/nm-activation-request.h b/src/nm-activation-request.h index dac9d89af6..9445790475 100644 --- a/src/nm-activation-request.h +++ b/src/nm-activation-request.h @@ -55,23 +55,9 @@ NMActRequest *nm_act_request_new (NMConnection *connection, gpointer *device); /* An NMDevice */ NMConnection *nm_act_request_get_connection (NMActRequest *req); -const char * nm_act_request_get_specific_object (NMActRequest *req); - -void nm_act_request_set_specific_object (NMActRequest *req, - const char *specific_object); gboolean nm_act_request_get_user_requested (NMActRequest *req); -const char * nm_act_request_get_active_connection_path (NMActRequest *req); - -void nm_act_request_set_default (NMActRequest *req, gboolean is_default); - -gboolean nm_act_request_get_default (NMActRequest *req); - -void nm_act_request_set_default6 (NMActRequest *req, gboolean is_default6); - -gboolean nm_act_request_get_default6 (NMActRequest *req); - gboolean nm_act_request_get_shared (NMActRequest *req); void nm_act_request_set_shared (NMActRequest *req, gboolean shared); diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index f27ad70dbc..63cae3a1d0 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -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) 2008 - 2010 Red Hat, Inc. + * Copyright (C) 2008 - 2012 Red Hat, Inc. */ #include @@ -23,56 +23,300 @@ #include "NetworkManager.h" #include "nm-logging.h" #include "nm-dbus-glib-types.h" +#include "nm-dbus-manager.h" +#include "nm-properties-changed-signal.h" -char * -nm_active_connection_get_next_object_path (void) +#include "nm-active-connection-glue.h" + +/* Base class for anything implementing the Connection.Active D-Bus interface */ +G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, G_TYPE_OBJECT) + +#define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + NM_TYPE_ACTIVE_CONNECTION, \ + NMActiveConnectionPrivate)) + +typedef struct { + gboolean disposed; + + NMConnection *connection; + char *path; + char *specific_object; + char *device_path; + gboolean is_default; + gboolean is_default6; + NMActiveConnectionState state; + gboolean vpn; +} NMActiveConnectionPrivate; + +enum { + PROP_0, + PROP_CONNECTION, + PROP_UUID, + PROP_SPECIFIC_OBJECT, + PROP_DEVICES, + PROP_STATE, + PROP_DEFAULT, + PROP_DEFAULT6, + PROP_VPN, + PROP_MASTER, + + LAST_PROP +}; + +enum { + PROPERTIES_CHANGED, + LAST_SIGNAL +}; +static guint signals[LAST_SIGNAL] = { 0 }; + +/****************************************************************/ + +void +nm_active_connection_set_state (NMActiveConnection *self, + NMActiveConnectionState new_state) { - static guint32 counter = 0; + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); - return g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++); + if (priv->state != new_state) { + priv->state = new_state; + g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_STATE); + } +} + +NMConnection * +nm_active_connection_get_connection (NMActiveConnection *self) +{ + return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->connection; +} + +const char * +nm_active_connection_get_path (NMActiveConnection *self) +{ + return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->path; +} + +const char * +nm_active_connection_get_specific_object (NMActiveConnection *self) +{ + return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->specific_object; } void -nm_active_connection_install_properties (GObjectClass *object_class, - guint prop_connection, - guint prop_uuid, - guint prop_specific_object, - guint prop_devices, - guint prop_state, - guint prop_default, - guint prop_default6, - guint prop_vpn, - guint prop_master) +nm_active_connection_set_specific_object (NMActiveConnection *self, + const char *specific_object) { - g_object_class_install_property (object_class, prop_connection, + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); + + if (g_strcmp0 (priv->specific_object, specific_object) == 0) + return; + + g_free (priv->specific_object); + priv->specific_object = g_strdup (specific_object); + g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT); +} + +void +nm_active_connection_set_default (NMActiveConnection *self, gboolean is_default) +{ + NMActiveConnectionPrivate *priv; + + g_return_if_fail (NM_IS_ACTIVE_CONNECTION (self)); + + priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); + if (priv->is_default == is_default) + return; + + priv->is_default = is_default; + g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_DEFAULT); +} + +gboolean +nm_active_connection_get_default (NMActiveConnection *self) +{ + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), FALSE); + + return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->is_default; +} + +void +nm_active_connection_set_default6 (NMActiveConnection *self, gboolean is_default6) +{ + NMActiveConnectionPrivate *priv; + + g_return_if_fail (NM_IS_ACTIVE_CONNECTION (self)); + + priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); + if (priv->is_default6 == is_default6) + return; + + priv->is_default6 = is_default6; + g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_DEFAULT6); +} + +gboolean +nm_active_connection_get_default6 (NMActiveConnection *self) +{ + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), FALSE); + + return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->is_default6; +} + +gboolean +nm_active_connection_export (NMActiveConnection *self, + NMConnection *connection, + const char *devpath) +{ + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); + NMDBusManager *dbus_mgr; + static guint32 counter = 0; + + g_return_val_if_fail (connection != NULL, FALSE); + g_return_val_if_fail (devpath != NULL, FALSE); + + priv->connection = g_object_ref (connection); + priv->path = g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++); + priv->device_path = g_strdup (devpath); + + dbus_mgr = nm_dbus_manager_get (); + dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr), + priv->path, G_OBJECT (self)); + g_object_unref (dbus_mgr); + return TRUE; +} + +/****************************************************************/ + +static void +nm_active_connection_init (NMActiveConnection *self) +{ +} + +static void +dispose (GObject *object) +{ + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); + + if (!priv->disposed) { + priv->disposed = TRUE; + + g_free (priv->path); + g_free (priv->specific_object); + g_free (priv->device_path); + g_object_unref (priv->connection); + } + + G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object); +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_SPECIFIC_OBJECT: + priv->specific_object = g_value_dup_boxed (value); + break; + case PROP_DEFAULT: + priv->is_default = g_value_get_boolean (value); + break; + case PROP_DEFAULT6: + priv->is_default6 = g_value_get_boolean (value); + break; + case PROP_VPN: + priv->vpn = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); + GPtrArray *devices; + + switch (prop_id) { + case PROP_CONNECTION: + g_value_set_boxed (value, nm_connection_get_path (priv->connection)); + break; + case PROP_UUID: + g_value_set_string (value, nm_connection_get_uuid (priv->connection)); + break; + case PROP_SPECIFIC_OBJECT: + g_value_set_boxed (value, priv->specific_object ? priv->specific_object : "/"); + break; + case PROP_DEVICES: + devices = g_ptr_array_sized_new (1); + g_ptr_array_add (devices, g_strdup (priv->device_path)); + g_value_take_boxed (value, devices); + break; + case PROP_STATE: + g_value_set_uint (value, priv->state); + break; + case PROP_DEFAULT: + g_value_set_boolean (value, priv->is_default); + break; + case PROP_DEFAULT6: + g_value_set_boolean (value, priv->is_default6); + break; + case PROP_VPN: + g_value_set_boolean (value, priv->vpn); + break; + case PROP_MASTER: + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +nm_active_connection_class_init (NMActiveConnectionClass *vpn_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (vpn_class); + + g_type_class_add_private (vpn_class, sizeof (NMActiveConnectionPrivate)); + + /* virtual methods */ + object_class->get_property = get_property; + object_class->set_property = set_property; + object_class->dispose = dispose; + + /* properties */ + g_object_class_install_property (object_class, PROP_CONNECTION, g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION, "Connection", "Connection", DBUS_TYPE_G_OBJECT_PATH, G_PARAM_READABLE)); - g_object_class_install_property (object_class, prop_uuid, + g_object_class_install_property (object_class, PROP_UUID, g_param_spec_string (NM_ACTIVE_CONNECTION_UUID, "Connection UUID", "Connection UUID", NULL, G_PARAM_READABLE)); - g_object_class_install_property (object_class, prop_specific_object, + g_object_class_install_property (object_class, PROP_SPECIFIC_OBJECT, g_param_spec_boxed (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "Specific object", "Specific object", DBUS_TYPE_G_OBJECT_PATH, - G_PARAM_READABLE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, prop_devices, + g_object_class_install_property (object_class, PROP_DEVICES, g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "Devices", "Devices", DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_PARAM_READABLE)); - g_object_class_install_property (object_class, prop_state, + g_object_class_install_property (object_class, PROP_STATE, g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE, "State", "State", @@ -81,32 +325,40 @@ nm_active_connection_install_properties (GObjectClass *object_class, NM_ACTIVE_CONNECTION_STATE_UNKNOWN, G_PARAM_READABLE)); - g_object_class_install_property (object_class, prop_default, + g_object_class_install_property (object_class, PROP_DEFAULT, g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, "Default", "Is the default IPv4 active connection", FALSE, - G_PARAM_READABLE)); + G_PARAM_READWRITE)); - g_object_class_install_property (object_class, prop_default6, + g_object_class_install_property (object_class, PROP_DEFAULT6, g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT6, "Default6", "Is the default IPv6 active connection", FALSE, - G_PARAM_READABLE)); + G_PARAM_READWRITE)); - g_object_class_install_property (object_class, prop_vpn, + g_object_class_install_property (object_class, PROP_VPN, g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, "VPN", "Is a VPN connection", FALSE, - G_PARAM_READABLE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, prop_master, + g_object_class_install_property (object_class, PROP_MASTER, g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER, "Master", "Path of master device", NULL, G_PARAM_READABLE)); + + /* Signals */ + signals[PROPERTIES_CHANGED] = + nm_properties_changed_signal_new (object_class, + G_STRUCT_OFFSET (NMActiveConnectionClass, properties_changed)); + + dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (vpn_class), + &dbus_glib_nm_active_connection_object_info); } diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index f18f9c14db..e00c0a6e2a 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -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) 2008 - 2010 Red Hat, Inc. + * Copyright (C) 2008 - 2012 Red Hat, Inc. */ #ifndef NM_ACTIVE_CONNECTION_H @@ -24,27 +24,61 @@ #include #include "nm-connection.h" -#define NM_ACTIVE_CONNECTION_CONNECTION "connection" -#define NM_ACTIVE_CONNECTION_UUID "uuid" +#define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ()) +#define NM_ACTIVE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnection)) +#define NM_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass)) +#define NM_IS_ACTIVE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_ACTIVE_CONNECTION)) +#define NM_IS_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_ACTIVE_CONNECTION)) +#define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass)) + +/* Properties */ +#define NM_ACTIVE_CONNECTION_CONNECTION "connection" +#define NM_ACTIVE_CONNECTION_UUID "uuid" #define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object" -#define NM_ACTIVE_CONNECTION_DEVICES "devices" -#define NM_ACTIVE_CONNECTION_STATE "state" -#define NM_ACTIVE_CONNECTION_DEFAULT "default" -#define NM_ACTIVE_CONNECTION_DEFAULT6 "default6" -#define NM_ACTIVE_CONNECTION_VPN "vpn" -#define NM_ACTIVE_CONNECTION_MASTER "master" +#define NM_ACTIVE_CONNECTION_DEVICES "devices" +#define NM_ACTIVE_CONNECTION_STATE "state" +#define NM_ACTIVE_CONNECTION_DEFAULT "default" +#define NM_ACTIVE_CONNECTION_DEFAULT6 "default6" +#define NM_ACTIVE_CONNECTION_VPN "vpn" +#define NM_ACTIVE_CONNECTION_MASTER "master" -char *nm_active_connection_get_next_object_path (void); +typedef struct { + GObject parent; +} NMActiveConnection; -void nm_active_connection_install_properties (GObjectClass *object_class, - guint prop_connection, - guint prop_uuid, - guint prop_specific_object, - guint prop_devices, - guint prop_state, - guint prop_default, - guint prop_default6, - guint prop_vpn, - guint prop_master); +typedef struct { + GObjectClass parent; + + /* Signals */ + void (*properties_changed) (NMActiveConnection *req, GHashTable *properties); +} NMActiveConnectionClass; + +GType nm_active_connection_get_type (void); + +gboolean nm_active_connection_export (NMActiveConnection *self, + NMConnection *connection, + const char *devpath); + +NMConnection *nm_active_connection_get_connection (NMActiveConnection *self); + +const char * nm_active_connection_get_path (NMActiveConnection *self); + +const char * nm_active_connection_get_specific_object (NMActiveConnection *self); + +void nm_active_connection_set_specific_object (NMActiveConnection *self, + const char *specific_object); + +void nm_active_connection_set_default (NMActiveConnection *self, + gboolean is_default); + +gboolean nm_active_connection_get_default (NMActiveConnection *self); + +void nm_active_connection_set_default6 (NMActiveConnection *self, + gboolean is_default6); + +gboolean nm_active_connection_get_default6 (NMActiveConnection *self); + +void nm_active_connection_set_state (NMActiveConnection *self, + NMActiveConnectionState state); #endif /* NM_ACTIVE_CONNECTION_H */ diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index f89b8fdf48..1cdb36b25e 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -1720,7 +1720,7 @@ cull_scan_list (NMDeviceWifi *self) req = nm_device_get_act_request (NM_DEVICE (self)); if (req) - cur_ap_path = nm_act_request_get_specific_object (req); + cur_ap_path = nm_active_connection_get_specific_object (NM_ACTIVE_CONNECTION (req)); nm_log_dbg (LOGD_WIFI_SCAN, "(%s): checking scan list for outdated APs", nm_device_get_iface (NM_DEVICE (self))); @@ -2573,7 +2573,7 @@ real_act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) g_signal_emit (self, signals[ACCESS_POINT_ADDED], 0, ap); } - nm_act_request_set_specific_object (req, nm_ap_get_dbus_path (ap)); + nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_ap_get_dbus_path (ap)); done: set_current_ap (self, ap); @@ -2873,7 +2873,8 @@ activation_success_handler (NMDevice *dev) if (!ssid || nm_utils_is_empty_ssid (ssid->data, ssid->len)) nm_ap_set_ssid (tmp_ap, nm_ap_get_ssid (ap)); - nm_act_request_set_specific_object (req, nm_ap_get_dbus_path (tmp_ap)); + nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), + nm_ap_get_dbus_path (tmp_ap)); priv->ap_list = g_slist_remove (priv->ap_list, ap); g_object_unref (ap); @@ -3036,7 +3037,7 @@ nm_device_wifi_get_activation_ap (NMDeviceWifi *self) if (!req) return NULL; - ap_path = nm_act_request_get_specific_object (req); + ap_path = nm_active_connection_get_specific_object (NM_ACTIVE_CONNECTION (req)); return ap_path ? get_ap_by_path (self, ap_path) : NULL; } diff --git a/src/nm-device.c b/src/nm-device.c index 7789054724..8042fb0311 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -2869,7 +2869,7 @@ clear_act_request (NMDevice *self) priv->secrets_failed_id = 0; } - nm_act_request_set_default (priv->act_request, FALSE); + nm_active_connection_set_default (NM_ACTIVE_CONNECTION (priv->act_request), FALSE); g_object_unref (priv->act_request); priv->act_request = NULL; @@ -3708,7 +3708,7 @@ get_property (GObject *object, guint prop_id, break; case PROP_ACTIVE_CONNECTION: if (priv->act_request) - ac_path = nm_act_request_get_active_connection_path (priv->act_request); + ac_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (priv->act_request)); g_value_set_boxed (value, ac_path ? ac_path : "/"); break; case PROP_DEVICE_TYPE: diff --git a/src/nm-manager.c b/src/nm-manager.c index a53dab81d6..50010b6362 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -920,7 +920,7 @@ get_active_connections (NMManager *manager, NMConnection *filter) continue; if (!filter || (nm_act_request_get_connection (req) == filter)) { - path = nm_act_request_get_active_connection_path (req); + path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)); g_ptr_array_add (active, g_strdup (path)); } } @@ -2123,7 +2123,7 @@ nm_manager_get_act_request_by_path (NMManager *manager, if (!req) continue; - ac_path = nm_act_request_get_active_connection_path (req); + ac_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)); if (!strcmp (path, ac_path)) { *device = NM_DEVICE (iter->data); return req; @@ -2172,7 +2172,7 @@ internal_activate_device (NMManager *manager, success = nm_device_activate (device, req, error); g_object_unref (req); - return success ? nm_act_request_get_active_connection_path (req) : NULL; + return success ? nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)) : NULL; } const char * @@ -2239,7 +2239,7 @@ nm_manager_activate_connection (NMManager *manager, NMActRequest *candidate_req; candidate_req = nm_device_get_act_request (candidate); - if (candidate_req && nm_act_request_get_default (candidate_req)) { + if (candidate_req && nm_active_connection_get_default (NM_ACTIVE_CONNECTION (candidate_req))) { device = candidate; parent_req = candidate_req; break; @@ -2257,12 +2257,12 @@ nm_manager_activate_connection (NMManager *manager, vpn_connection = nm_vpn_manager_activate_connection (priv->vpn_manager, connection, device, - nm_act_request_get_active_connection_path (parent_req), + nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)), TRUE, sender_uid, error); if (vpn_connection) - path = nm_vpn_connection_get_active_connection_path (vpn_connection); + path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (vpn_connection)); } else { NMDeviceState state; @@ -2472,7 +2472,7 @@ nm_manager_deactivate_connection (NMManager *manager, if (!req) continue; - if (!strcmp (connection_path, nm_act_request_get_active_connection_path (req))) { + if (!strcmp (connection_path, nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)))) { nm_device_state_changed (device, NM_DEVICE_STATE_DISCONNECTED, reason); @@ -2551,7 +2551,7 @@ impl_manager_deactivate_connection (NMManager *self, req = nm_device_get_act_request (NM_DEVICE (iter->data)); if (req) - req_path = nm_act_request_get_active_connection_path (req); + req_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)); if (req_path && !strcmp (active_path, req_path)) { connection = nm_act_request_get_connection (req); diff --git a/src/nm-policy.c b/src/nm-policy.c index 4d31189e20..12bb43aca5 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -534,7 +534,7 @@ update_ip4_routing_and_dns (NMPolicy *policy, gboolean force_update) req = nm_device_get_act_request (dev); if (req && (req != best_req)) - nm_act_request_set_default (req, FALSE); + nm_active_connection_set_default (NM_ACTIVE_CONNECTION (req), FALSE); } dns_mgr = nm_dns_manager_get (NULL); @@ -545,7 +545,7 @@ update_ip4_routing_and_dns (NMPolicy *policy, gboolean force_update) * if the connection is shared dnsmasq picks up the right stuff. */ if (best_req) - nm_act_request_set_default (best_req, TRUE); + nm_active_connection_set_default (NM_ACTIVE_CONNECTION (best_req), TRUE); if (connection) s_con = nm_connection_get_setting_connection (connection); @@ -661,7 +661,7 @@ update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update) req = nm_device_get_act_request (dev); if (req && (req != best_req)) - nm_act_request_set_default6 (req, FALSE); + nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (req), FALSE); } dns_mgr = nm_dns_manager_get (NULL); @@ -672,7 +672,7 @@ update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update) * if the connection is shared dnsmasq picks up the right stuff. */ if (best_req) - nm_act_request_set_default6 (best_req, TRUE); + nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (best_req), TRUE); if (connection) s_con = nm_connection_get_setting_connection (connection); @@ -832,7 +832,9 @@ auto_activate_device (gpointer user_data) NULL, &error)) { nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s", - nm_connection_get_id (best_connection), error->code, error->message); + nm_connection_get_id (best_connection), + error ? error->code : -1, + error ? error->message : "(none)"); g_error_free (error); } } diff --git a/src/vpn-manager/Makefile.am b/src/vpn-manager/Makefile.am index c4c7b3ed48..d487439fb2 100644 --- a/src/vpn-manager/Makefile.am +++ b/src/vpn-manager/Makefile.am @@ -17,8 +17,6 @@ libvpn_manager_la_SOURCES = \ nm-vpn-manager.h \ nm-vpn-service.c \ nm-vpn-service.h \ - nm-vpn-connection-base.c \ - nm-vpn-connection-base.h \ nm-vpn-connection.c \ nm-vpn-connection.h @@ -36,9 +34,6 @@ libvpn_manager_la_LIBADD = \ $(DBUS_LIBS) \ $(GLIB_LIBS) -nm-vpn-connection-base-glue.h: $(top_srcdir)/introspection/nm-active-connection.xml - $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_connection_base --mode=glib-server --output=$@ $< - nm-vpn-connection-glue.h: $(top_srcdir)/introspection/nm-vpn-connection.xml $(AM_V_GEN) dbus-binding-tool --prefix=nm_vpn_connection --mode=glib-server --output=$@ $< diff --git a/src/vpn-manager/nm-vpn-connection-base.c b/src/vpn-manager/nm-vpn-connection-base.c deleted file mode 100644 index d53ea63a51..0000000000 --- a/src/vpn-manager/nm-vpn-connection-base.c +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * 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 - 2011 Red Hat, Inc. - * Copyright (C) 2007 - 2008 Novell, Inc. - */ - -#include "NetworkManager.h" -#include "nm-vpn-connection-base.h" -#include "nm-active-connection.h" -#include "nm-vpn-connection-base-glue.h" -#include "nm-dbus-manager.h" - -G_DEFINE_ABSTRACT_TYPE (NMVpnConnectionBase, nm_vpn_connection_base, G_TYPE_OBJECT) - -#define NM_VPN_CONNECTION_BASE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - NM_TYPE_VPN_CONNECTION_BASE, \ - NMVpnConnectionBasePrivate)) - -typedef struct { - gboolean disposed; - - NMConnection *connection; - char *ac_path; - char *specific_object; - gboolean is_default; - gboolean is_default6; - NMActiveConnectionState state; -} NMVpnConnectionBasePrivate; - -enum { - PROP_0, - PROP_CONNECTION, - PROP_UUID, - PROP_SPECIFIC_OBJECT, - PROP_DEVICES, - PROP_STATE, - PROP_DEFAULT, - PROP_DEFAULT6, - PROP_VPN, - PROP_MASTER, - - LAST_PROP -}; - -/****************************************************************/ - -void -nm_vpn_connection_base_set_state (NMVpnConnectionBase *self, - NMVPNConnectionState vpn_state) -{ - NMVpnConnectionBasePrivate *priv = NM_VPN_CONNECTION_BASE_GET_PRIVATE (self); - NMActiveConnectionState new_ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; - - /* Set the NMActiveConnection state based on VPN state */ - switch (vpn_state) { - case NM_VPN_CONNECTION_STATE_PREPARE: - case NM_VPN_CONNECTION_STATE_NEED_AUTH: - case NM_VPN_CONNECTION_STATE_CONNECT: - case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: - new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; - break; - case NM_VPN_CONNECTION_STATE_ACTIVATED: - new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; - break; - default: - break; - } - - if (new_ac_state != priv->state) { - priv->state = new_ac_state; - g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_STATE); - } -} - -const char * -nm_vpn_connection_base_get_ac_path (NMVpnConnectionBase *self) -{ - return NM_VPN_CONNECTION_BASE_GET_PRIVATE (self)->ac_path; -} - -const char * -nm_vpn_connection_base_get_specific_object (NMVpnConnectionBase *self) -{ - return NM_VPN_CONNECTION_BASE_GET_PRIVATE (self)->specific_object; -} - -void -nm_vpn_connection_base_export (NMVpnConnectionBase *self, - NMConnection *connection, - const char *specific_object) -{ - NMVpnConnectionBasePrivate *priv = NM_VPN_CONNECTION_BASE_GET_PRIVATE (self); - NMDBusManager *dbus_mgr; - - g_return_if_fail (priv->connection == NULL); - - priv->connection = g_object_ref (connection); - priv->specific_object = g_strdup (specific_object); - - dbus_mgr = nm_dbus_manager_get (); - dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr), - priv->ac_path, G_OBJECT (self)); - g_object_unref (dbus_mgr); -} - -/****************************************************************/ - -static void -nm_vpn_connection_base_init (NMVpnConnectionBase *self) -{ - NMVpnConnectionBasePrivate *priv = NM_VPN_CONNECTION_BASE_GET_PRIVATE (self); - - priv->state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; - priv->ac_path = nm_active_connection_get_next_object_path (); -} - -static void -dispose (GObject *object) -{ - NMVpnConnectionBasePrivate *priv = NM_VPN_CONNECTION_BASE_GET_PRIVATE (object); - - if (!priv->disposed) { - priv->disposed = TRUE; - - g_free (priv->ac_path); - g_free (priv->specific_object); - g_object_unref (priv->connection); - } - - G_OBJECT_CLASS (nm_vpn_connection_base_parent_class)->dispose (object); -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - NMVpnConnectionBasePrivate *priv = NM_VPN_CONNECTION_BASE_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_CONNECTION: - g_value_set_boxed (value, nm_connection_get_path (priv->connection)); - break; - case PROP_UUID: - g_value_set_string (value, nm_connection_get_uuid (priv->connection)); - break; - case PROP_SPECIFIC_OBJECT: - g_value_set_boxed (value, priv->specific_object); - break; - case PROP_DEVICES: - g_value_take_boxed (value, g_ptr_array_new ()); - break; - case PROP_STATE: - g_value_set_uint (value, priv->state); - break; - case PROP_DEFAULT: - g_value_set_boolean (value, priv->is_default); - break; - case PROP_DEFAULT6: - g_value_set_boolean (value, priv->is_default6); - break; - case PROP_VPN: - g_value_set_boolean (value, TRUE); - break; - case PROP_MASTER: - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -nm_vpn_connection_base_class_init (NMVpnConnectionBaseClass *vpn_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (vpn_class); - - g_type_class_add_private (vpn_class, sizeof (NMVpnConnectionBasePrivate)); - - /* virtual methods */ - object_class->get_property = get_property; - object_class->dispose = dispose; - - /* properties */ - nm_active_connection_install_properties (object_class, - PROP_CONNECTION, - PROP_UUID, - PROP_SPECIFIC_OBJECT, - PROP_DEVICES, - PROP_STATE, - PROP_DEFAULT, - PROP_DEFAULT6, - PROP_VPN, - PROP_MASTER); - - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (vpn_class), - &dbus_glib_nm_vpn_connection_base_object_info); -} - diff --git a/src/vpn-manager/nm-vpn-connection-base.h b/src/vpn-manager/nm-vpn-connection-base.h deleted file mode 100644 index 6f19e7c53c..0000000000 --- a/src/vpn-manager/nm-vpn-connection-base.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * (C) Copyright 2005 - 2011 Red Hat, Inc. - */ - -#ifndef NM_VPN_CONNECTION_BASE_H -#define NM_VPN_CONNECTION_BASE_H - -#include -#include "NetworkManagerVPN.h" -#include "nm-connection.h" - -#define NM_TYPE_VPN_CONNECTION_BASE (nm_vpn_connection_base_get_type ()) -#define NM_VPN_CONNECTION_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_CONNECTION_BASE, NMVpnConnectionBase)) -#define NM_VPN_CONNECTION_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_VPN_CONNECTION_BASE, NMVpnConnectionBaseClass)) -#define NM_IS_VPN_CONNECTION_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_VPN_CONNECTION_BASE)) -#define NM_IS_VPN_CONNECTION_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_VPN_CONNECTION_BASE)) -#define NM_VPN_CONNECTION_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_VPN_CONNECTION_BASE, NMVpnConnectionBaseClass)) - -typedef struct { - GObject parent; -} NMVpnConnectionBase; - -typedef struct { - GObjectClass parent; -} NMVpnConnectionBaseClass; - -GType nm_vpn_connection_base_get_type (void); - -const char *nm_vpn_connection_base_get_ac_path (NMVpnConnectionBase *self); - -const char *nm_vpn_connection_base_get_specific_object (NMVpnConnectionBase *self); - -void nm_vpn_connection_base_export (NMVpnConnectionBase *self, - NMConnection *connection, - const char *specific_object); - -void nm_vpn_connection_base_set_state (NMVpnConnectionBase *self, - NMVPNConnectionState vpn_state); - -#endif /* NM_VPN_CONNECTION_BASE_H */ - diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 91f5bd2f98..9d71f308e0 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -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 - 2011 Red Hat, Inc. + * Copyright (C) 2005 - 2012 Red Hat, Inc. * Copyright (C) 2006 - 2008 Novell, Inc. */ @@ -51,7 +51,7 @@ #include "nm-vpn-connection-glue.h" -G_DEFINE_TYPE (NMVPNConnection, nm_vpn_connection, NM_TYPE_VPN_CONNECTION_BASE) +G_DEFINE_TYPE (NMVPNConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) typedef enum { /* Only system secrets */ @@ -113,6 +113,24 @@ enum { static void get_secrets (NMVPNConnection *self, SecretsReq secrets_idx); +static NMActiveConnectionState +ac_state_from_vpn_state (NMVPNConnectionState vpn_state) +{ + /* Set the NMActiveConnection state based on VPN state */ + switch (vpn_state) { + case NM_VPN_CONNECTION_STATE_PREPARE: + case NM_VPN_CONNECTION_STATE_NEED_AUTH: + case NM_VPN_CONNECTION_STATE_CONNECT: + case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: + return NM_ACTIVE_CONNECTION_STATE_ACTIVATING; + case NM_VPN_CONNECTION_STATE_ACTIVATED: + return NM_ACTIVE_CONNECTION_STATE_ACTIVATED; + default: + break; + } + return NM_ACTIVE_CONNECTION_STATE_UNKNOWN; +} + static void nm_vpn_connection_set_vpn_state (NMVPNConnection *connection, NMVPNConnectionState vpn_state, @@ -133,7 +151,8 @@ nm_vpn_connection_set_vpn_state (NMVPNConnection *connection, priv->vpn_state = vpn_state; /* Update active connection base class state */ - nm_vpn_connection_base_set_state (NM_VPN_CONNECTION_BASE (connection), vpn_state); + nm_active_connection_set_state (NM_ACTIVE_CONNECTION (connection), + ac_state_from_vpn_state (vpn_state)); /* Save ip_iface since when the VPN goes down it may get freed * before we're done with it. @@ -230,7 +249,10 @@ nm_vpn_connection_new (NMConnection *connection, g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_DEVICE (parent_device), NULL); - self = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION, NULL); + self = (NMVPNConnection *) g_object_new (NM_TYPE_VPN_CONNECTION, + NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object, + NM_ACTIVE_CONNECTION_VPN, TRUE, + NULL); if (!self) return NULL; @@ -249,7 +271,12 @@ nm_vpn_connection_new (NMConnection *connection, G_CALLBACK (device_ip4_config_changed), self); - nm_vpn_connection_base_export (NM_VPN_CONNECTION_BASE (self), connection, specific_object); + if (!nm_active_connection_export (NM_ACTIVE_CONNECTION (self), + connection, + nm_device_get_path (parent_device))) { + g_object_unref (self); + self = NULL; + } return self; } @@ -735,14 +762,6 @@ nm_vpn_connection_activate (NMVPNConnection *connection) NM_VPN_CONNECTION_STATE_REASON_NONE); } -const char * -nm_vpn_connection_get_active_connection_path (NMVPNConnection *connection) -{ - g_return_val_if_fail (NM_IS_VPN_CONNECTION (connection), NULL); - - return nm_vpn_connection_base_get_ac_path (NM_VPN_CONNECTION_BASE (connection)); -} - const char * nm_vpn_connection_get_name (NMVPNConnection *connection) { @@ -1198,10 +1217,6 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class) G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); - signals[PROPERTIES_CHANGED] = - nm_properties_changed_signal_new (object_class, - G_STRUCT_OFFSET (NMVPNConnectionClass, properties_changed)); - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (object_class), &dbus_glib_nm_vpn_connection_object_info); } diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn-manager/nm-vpn-connection.h index c0d15f8af9..93cc06d166 100644 --- a/src/vpn-manager/nm-vpn-connection.h +++ b/src/vpn-manager/nm-vpn-connection.h @@ -26,7 +26,6 @@ #include #include "NetworkManagerVPN.h" #include "nm-device.h" -#include "nm-vpn-connection-base.h" #define NM_TYPE_VPN_CONNECTION (nm_vpn_connection_get_type ()) #define NM_VPN_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VPN_CONNECTION, NMVPNConnection)) @@ -39,18 +38,16 @@ #define NM_VPN_CONNECTION_BANNER "banner" typedef struct { - NMVpnConnectionBase parent; + NMActiveConnection parent; } NMVPNConnection; typedef struct { - NMVpnConnectionBaseClass parent; + NMActiveConnectionClass parent; /* Signals */ void (*vpn_state_changed) (NMVPNConnection *connection, NMVPNConnectionState state, NMVPNConnectionStateReason reason); - - void (*properties_changed) (NMVPNConnection *connection, GHashTable *properties); } NMVPNConnectionClass; GType nm_vpn_connection_get_type (void); @@ -63,8 +60,6 @@ NMVPNConnection * nm_vpn_connection_new (NMConnection *connection, void nm_vpn_connection_activate (NMVPNConnection *connection); NMConnection * nm_vpn_connection_get_connection (NMVPNConnection *connection); -const char * nm_vpn_connection_get_active_connection_path (NMVPNConnection *connection); -const char * nm_vpn_connection_get_specific_object_path (NMVPNConnection *connection); const char * nm_vpn_connection_get_name (NMVPNConnection *connection); NMVPNConnectionState nm_vpn_connection_get_vpn_state (NMVPNConnection *connection); const char * nm_vpn_connection_get_banner (NMVPNConnection *connection); diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index c359a39bb9..b30eca9f5d 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -243,7 +243,7 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self, NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data); const char *vpn_path; - vpn_path = nm_vpn_connection_get_active_connection_path (vpn); + vpn_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (vpn)); if (!strcmp (path, vpn_path)) { nm_vpn_connection_disconnect (vpn, reason); success = TRUE; @@ -279,7 +279,7 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self, const char *path; if (!filter || (nm_vpn_connection_get_connection (vpn) == filter)) { - path = nm_vpn_connection_get_active_connection_path (vpn); + path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (vpn)); g_ptr_array_add (array, g_strdup (path)); } } @@ -326,7 +326,7 @@ nm_vpn_manager_get_vpn_connection_for_active (NMVPNManager *manager, NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data); const char *ac_path; - ac_path = nm_vpn_connection_get_active_connection_path (vpn); + ac_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (vpn)); if (ac_path && !strcmp (ac_path, active_path)) return vpn; } diff --git a/src/wimax/nm-device-wimax.c b/src/wimax/nm-device-wimax.c index 3cf65085a0..c7df7e5c07 100644 --- a/src/wimax/nm-device-wimax.c +++ b/src/wimax/nm-device-wimax.c @@ -728,7 +728,7 @@ real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) if (!req) return NM_ACT_STAGE_RETURN_FAILURE; - path = nm_act_request_get_specific_object (req); + path = nm_active_connection_get_specific_object (NM_ACTIVE_CONNECTION (req)); if (!path) return NM_ACT_STAGE_RETURN_FAILURE;