core: use NMActiveConnection objects throughout activation paths

They are the basic class that tracks active connections, and we're
going to use them for connection dependencies.  So use the fact that
both NMVPNConnection and NMActRequest have the same base class
instead of using object paths.
This commit is contained in:
Dan Williams
2012-02-23 10:00:08 -06:00
parent 65a13f9d8a
commit 7aa2a8271d
6 changed files with 87 additions and 61 deletions

View File

@@ -351,13 +351,35 @@ device_state_changed (NMDevice *device,
/********************************************************************/ /********************************************************************/
/**
* nm_act_request_new:
*
* @connection: the connection to activate @device with
* @specific_object: the object path of the specific object (ie, WiFi access point,
* etc) that will be used to activate @connection and @device
* @user_requested: pass %TRUE if the activation was requested via D-Bus,
* otherwise %FALSE if requested internally by NM (ie, autoconnect)
* @user_uid: if @user_requested is %TRUE, the Unix UID of the user that requested
* the activation
* @assumed: pass %TRUE if the activation should "assume" (ie, taking over) an
* existing connection made before this instance of NM started
* @device: the device/interface to configure according to @connection
* @master: if the activation depends on another device (ie, VLAN slave, bond
* slave, etc) pass the #NMActiveConnection that this activation request
* should wait for before proceeding
*
* Begins activation of @device using the given @connection and other details.
*
* Returns: the new activation request on success, %NULL on error.
*/
NMActRequest * NMActRequest *
nm_act_request_new (NMConnection *connection, nm_act_request_new (NMConnection *connection,
const char *specific_object, const char *specific_object,
gboolean user_requested, gboolean user_requested,
gulong user_uid, gulong user_uid,
gboolean assumed, gboolean assumed,
gpointer *device) gpointer *device,
NMActiveConnection *master)
{ {
GObject *object; GObject *object;
NMActRequestPrivate *priv; NMActRequestPrivate *priv;

View File

@@ -52,7 +52,8 @@ NMActRequest *nm_act_request_new (NMConnection *connection,
gboolean user_requested, gboolean user_requested,
gulong user_uid, gulong user_uid,
gboolean assumed, gboolean assumed,
gpointer *device); /* An NMDevice */ gpointer *device, /* An NMDevice */
NMActiveConnection *master);
NMConnection *nm_act_request_get_connection (NMActRequest *req); NMConnection *nm_act_request_get_connection (NMActRequest *req);

View File

@@ -144,13 +144,14 @@ static void add_device (NMManager *self, NMDevice *device);
static void hostname_provider_init (NMHostnameProvider *provider_class); static void hostname_provider_init (NMHostnameProvider *provider_class);
static const char *internal_activate_device (NMManager *manager, static NMActiveConnection *internal_activate_device (NMManager *manager,
NMDevice *device, NMDevice *device,
NMConnection *connection, NMConnection *connection,
const char *specific_object, const char *specific_object,
gboolean user_requested, gboolean user_requested,
gulong sender_uid, gulong sender_uid,
gboolean assumed, gboolean assumed,
NMActiveConnection *master,
GError **error); GError **error);
static NMDevice *find_device_by_ip_iface (NMManager *self, const gchar *iface); static NMDevice *find_device_by_ip_iface (NMManager *self, const gchar *iface);
@@ -853,19 +854,21 @@ pending_activation_check_authorized (PendingActivation *pending,
static void static void
pending_activation_destroy (PendingActivation *pending, pending_activation_destroy (PendingActivation *pending,
GError *error, GError *error,
const char *ac_path) NMActiveConnection *ac)
{ {
g_return_if_fail (pending != NULL); g_return_if_fail (pending != NULL);
if (error) if (error)
dbus_g_method_return_error (pending->context, error); dbus_g_method_return_error (pending->context, error);
else if (ac_path) { else if (ac) {
if (pending->connection) { if (pending->connection) {
dbus_g_method_return (pending->context, dbus_g_method_return (pending->context,
pending->connection_path, pending->connection_path,
ac_path); nm_active_connection_get_path (ac));
} else } else {
dbus_g_method_return (pending->context, ac_path); dbus_g_method_return (pending->context,
nm_active_connection_get_path (ac));
}
} }
g_free (pending->connection_path); g_free (pending->connection_path);
@@ -1768,14 +1771,14 @@ add_device (NMManager *self, NMDevice *device)
/* If the device has a connection it can assume, do that now */ /* If the device has a connection it can assume, do that now */
if (existing && managed && nm_device_is_available (device)) { if (existing && managed && nm_device_is_available (device)) {
const char *ac_path; NMActiveConnection *ac;
GError *error = NULL; GError *error = NULL;
nm_log_dbg (LOGD_DEVICE, "(%s): will attempt to assume existing connection", nm_log_dbg (LOGD_DEVICE, "(%s): will attempt to assume existing connection",
nm_device_get_iface (device)); nm_device_get_iface (device));
ac_path = internal_activate_device (self, device, existing, NULL, FALSE, 0, TRUE, &error); ac = internal_activate_device (self, device, existing, NULL, FALSE, 0, TRUE, NULL, &error);
if (ac_path) if (ac)
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS); g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
else { else {
nm_log_warn (LOGD_DEVICE, "assumed connection %s failed to activate: (%d) %s", nm_log_warn (LOGD_DEVICE, "assumed connection %s failed to activate: (%d) %s",
@@ -2319,7 +2322,7 @@ nm_manager_get_act_request_by_path (NMManager *manager,
return NULL; return NULL;
} }
static const char * static NMActiveConnection *
internal_activate_device (NMManager *manager, internal_activate_device (NMManager *manager,
NMDevice *device, NMDevice *device,
NMConnection *connection, NMConnection *connection,
@@ -2327,6 +2330,7 @@ internal_activate_device (NMManager *manager,
gboolean user_requested, gboolean user_requested,
gulong sender_uid, gulong sender_uid,
gboolean assumed, gboolean assumed,
NMActiveConnection *master,
GError **error) GError **error)
{ {
NMActRequest *req; NMActRequest *req;
@@ -2354,14 +2358,15 @@ internal_activate_device (NMManager *manager,
user_requested, user_requested,
sender_uid, sender_uid,
assumed, assumed,
(gpointer) device); (gpointer) device,
master);
success = nm_device_activate (device, req, error); success = nm_device_activate (device, req, error);
g_object_unref (req); g_object_unref (req);
return success ? nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)) : NULL; return success ? NM_ACTIVE_CONNECTION (req) : NULL;
} }
const char * NMActiveConnection *
nm_manager_activate_connection (NMManager *manager, nm_manager_activate_connection (NMManager *manager,
NMConnection *connection, NMConnection *connection,
const char *specific_object, const char *specific_object,
@@ -2372,8 +2377,6 @@ nm_manager_activate_connection (NMManager *manager,
NMManagerPrivate *priv; NMManagerPrivate *priv;
NMDevice *device = NULL; NMDevice *device = NULL;
NMSettingConnection *s_con; NMSettingConnection *s_con;
NMVPNConnection *vpn_connection;
const char *path = NULL;
gulong sender_uid = 0; gulong sender_uid = 0;
DBusError dbus_error; DBusError dbus_error;
@@ -2440,15 +2443,13 @@ nm_manager_activate_connection (NMManager *manager,
return NULL; return NULL;
} }
vpn_connection = nm_vpn_manager_activate_connection (priv->vpn_manager, return nm_vpn_manager_activate_connection (priv->vpn_manager,
connection, connection,
device, device,
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)), nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)),
TRUE, TRUE,
sender_uid, sender_uid,
error); error);
if (vpn_connection)
path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (vpn_connection));
} else { } else {
NMDeviceState state; NMDeviceState state;
char *iface; char *iface;
@@ -2518,17 +2519,18 @@ nm_manager_activate_connection (NMManager *manager,
} }
} }
path = internal_activate_device (manager, return internal_activate_device (manager,
device, device,
connection, connection,
specific_object, specific_object,
dbus_sender ? TRUE : FALSE, dbus_sender ? TRUE : FALSE,
dbus_sender ? sender_uid : 0, dbus_sender ? sender_uid : 0,
FALSE, FALSE,
NULL,
error); error);
} }
return path; return NULL;
} }
/* /*
@@ -2542,7 +2544,7 @@ pending_activate (NMManager *self, PendingActivation *pending)
{ {
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMSettingsConnection *connection; NMSettingsConnection *connection;
const char *path = NULL; NMActiveConnection *ac = NULL;
GError *error = NULL; GError *error = NULL;
char *sender; char *sender;
@@ -2558,7 +2560,7 @@ pending_activate (NMManager *self, PendingActivation *pending)
sender = dbus_g_method_get_sender (pending->context); sender = dbus_g_method_get_sender (pending->context);
g_assert (sender); g_assert (sender);
path = nm_manager_activate_connection (self, ac = nm_manager_activate_connection (self,
NM_CONNECTION (connection), NM_CONNECTION (connection),
pending->specific_object_path, pending->specific_object_path,
pending->device_path, pending->device_path,
@@ -2566,16 +2568,17 @@ pending_activate (NMManager *self, PendingActivation *pending)
&error); &error);
g_free (sender); g_free (sender);
if (!path) { if (ac)
g_object_notify (G_OBJECT (pending->manager), NM_MANAGER_ACTIVE_CONNECTIONS);
else {
nm_log_warn (LOGD_CORE, "connection %s failed to activate: (%d) %s", nm_log_warn (LOGD_CORE, "connection %s failed to activate: (%d) %s",
pending->connection_path, pending->connection_path,
error ? error->code : -1, error ? error->code : -1,
error && error->message ? error->message : "(unknown)"); error && error->message ? error->message : "(unknown)");
} else }
g_object_notify (G_OBJECT (pending->manager), NM_MANAGER_ACTIVE_CONNECTIONS);
out: out:
pending_activation_destroy (pending, error, path); pending_activation_destroy (pending, error, ac);
g_clear_error (&error); g_clear_error (&error);
} }

View File

@@ -102,7 +102,7 @@ NMDevice *nm_manager_get_device_by_master (NMManager *manager,
const char *master, const char *master,
const char *driver); const char *driver);
const char * nm_manager_activate_connection (NMManager *manager, NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
NMConnection *connection, NMConnection *connection,
const char *specific_object, const char *specific_object,
const char *device_path, const char *device_path,

View File

@@ -134,7 +134,7 @@ connection_vpn_state_changed (NMVPNConnection *connection,
} }
} }
NMVPNConnection * NMActiveConnection *
nm_vpn_manager_activate_connection (NMVPNManager *manager, nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection, NMConnection *connection,
NMDevice *device, NMDevice *device,
@@ -193,7 +193,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
manager); manager);
} }
return vpn; return (NMActiveConnection *) vpn;
} }
gboolean gboolean

View File

@@ -65,7 +65,7 @@ GType nm_vpn_manager_get_type (void);
NMVPNManager *nm_vpn_manager_get (void); NMVPNManager *nm_vpn_manager_get (void);
NMVPNConnection *nm_vpn_manager_activate_connection (NMVPNManager *manager, NMActiveConnection *nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection, NMConnection *connection,
NMDevice *device, NMDevice *device,
const char *specific_object, const char *specific_object,