Commit 7aa2a827 authored by Dan Williams's avatar Dan Williams

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.
parent 65a13f9d
......@@ -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 *
nm_act_request_new (NMConnection *connection,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
gboolean assumed,
gpointer *device)
gpointer *device,
NMActiveConnection *master)
{
GObject *object;
NMActRequestPrivate *priv;
......
......@@ -52,7 +52,8 @@ NMActRequest *nm_act_request_new (NMConnection *connection,
gboolean user_requested,
gulong user_uid,
gboolean assumed,
gpointer *device); /* An NMDevice */
gpointer *device, /* An NMDevice */
NMActiveConnection *master);
NMConnection *nm_act_request_get_connection (NMActRequest *req);
......
......@@ -144,14 +144,15 @@ static void add_device (NMManager *self, NMDevice *device);
static void hostname_provider_init (NMHostnameProvider *provider_class);
static const char *internal_activate_device (NMManager *manager,
NMDevice *device,
NMConnection *connection,
const char *specific_object,
gboolean user_requested,
gulong sender_uid,
gboolean assumed,
GError **error);
static NMActiveConnection *internal_activate_device (NMManager *manager,
NMDevice *device,
NMConnection *connection,
const char *specific_object,
gboolean user_requested,
gulong sender_uid,
gboolean assumed,
NMActiveConnection *master,
GError **error);
static NMDevice *find_device_by_ip_iface (NMManager *self, const gchar *iface);
......@@ -853,19 +854,21 @@ pending_activation_check_authorized (PendingActivation *pending,
static void
pending_activation_destroy (PendingActivation *pending,
GError *error,
const char *ac_path)
NMActiveConnection *ac)
{
g_return_if_fail (pending != NULL);
if (error)
dbus_g_method_return_error (pending->context, error);
else if (ac_path) {
else if (ac) {
if (pending->connection) {
dbus_g_method_return (pending->context,
pending->connection_path,
ac_path);
} else
dbus_g_method_return (pending->context, ac_path);
nm_active_connection_get_path (ac));
} else {
dbus_g_method_return (pending->context,
nm_active_connection_get_path (ac));
}
}
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 (existing && managed && nm_device_is_available (device)) {
const char *ac_path;
NMActiveConnection *ac;
GError *error = NULL;
nm_log_dbg (LOGD_DEVICE, "(%s): will attempt to assume existing connection",
nm_device_get_iface (device));
ac_path = internal_activate_device (self, device, existing, NULL, FALSE, 0, TRUE, &error);
if (ac_path)
ac = internal_activate_device (self, device, existing, NULL, FALSE, 0, TRUE, NULL, &error);
if (ac)
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
else {
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;
}
static const char *
static NMActiveConnection *
internal_activate_device (NMManager *manager,
NMDevice *device,
NMConnection *connection,
......@@ -2327,6 +2330,7 @@ internal_activate_device (NMManager *manager,
gboolean user_requested,
gulong sender_uid,
gboolean assumed,
NMActiveConnection *master,
GError **error)
{
NMActRequest *req;
......@@ -2354,14 +2358,15 @@ internal_activate_device (NMManager *manager,
user_requested,
sender_uid,
assumed,
(gpointer) device);
(gpointer) device,
master);
success = nm_device_activate (device, req, error);
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,
NMConnection *connection,
const char *specific_object,
......@@ -2372,8 +2377,6 @@ nm_manager_activate_connection (NMManager *manager,
NMManagerPrivate *priv;
NMDevice *device = NULL;
NMSettingConnection *s_con;
NMVPNConnection *vpn_connection;
const char *path = NULL;
gulong sender_uid = 0;
DBusError dbus_error;
......@@ -2440,15 +2443,13 @@ nm_manager_activate_connection (NMManager *manager,
return NULL;
}
vpn_connection = nm_vpn_manager_activate_connection (priv->vpn_manager,
connection,
device,
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)),
TRUE,
sender_uid,
error);
if (vpn_connection)
path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (vpn_connection));
return nm_vpn_manager_activate_connection (priv->vpn_manager,
connection,
device,
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (parent_req)),
TRUE,
sender_uid,
error);
} else {
NMDeviceState state;
char *iface;
......@@ -2518,17 +2519,18 @@ nm_manager_activate_connection (NMManager *manager,
}
}
path = internal_activate_device (manager,
return internal_activate_device (manager,
device,
connection,
specific_object,
dbus_sender ? TRUE : FALSE,
dbus_sender ? sender_uid : 0,
FALSE,
NULL,
error);
}
return path;
return NULL;
}
/*
......@@ -2542,7 +2544,7 @@ pending_activate (NMManager *self, PendingActivation *pending)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
NMSettingsConnection *connection;
const char *path = NULL;
NMActiveConnection *ac = NULL;
GError *error = NULL;
char *sender;
......@@ -2558,24 +2560,25 @@ pending_activate (NMManager *self, PendingActivation *pending)
sender = dbus_g_method_get_sender (pending->context);
g_assert (sender);
path = nm_manager_activate_connection (self,
NM_CONNECTION (connection),
pending->specific_object_path,
pending->device_path,
sender,
&error);
ac = nm_manager_activate_connection (self,
NM_CONNECTION (connection),
pending->specific_object_path,
pending->device_path,
sender,
&error);
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",
pending->connection_path,
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
} else
g_object_notify (G_OBJECT (pending->manager), NM_MANAGER_ACTIVE_CONNECTIONS);
}
out:
pending_activation_destroy (pending, error, path);
pending_activation_destroy (pending, error, ac);
g_clear_error (&error);
}
......
......@@ -102,12 +102,12 @@ NMDevice *nm_manager_get_device_by_master (NMManager *manager,
const char *master,
const char *driver);
const char * nm_manager_activate_connection (NMManager *manager,
NMConnection *connection,
const char *specific_object,
const char *device_path,
const char *dbus_sender, /* NULL if automatic */
GError **error);
NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
NMConnection *connection,
const char *specific_object,
const char *device_path,
const char *dbus_sender, /* NULL if automatic */
GError **error);
gboolean nm_manager_deactivate_connection (NMManager *manager,
const char *connection_path,
......
......@@ -134,7 +134,7 @@ connection_vpn_state_changed (NMVPNConnection *connection,
}
}
NMVPNConnection *
NMActiveConnection *
nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection,
NMDevice *device,
......@@ -193,7 +193,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
manager);
}
return vpn;
return (NMActiveConnection *) vpn;
}
gboolean
......
......@@ -65,13 +65,13 @@ GType nm_vpn_manager_get_type (void);
NMVPNManager *nm_vpn_manager_get (void);
NMVPNConnection *nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
GError **error);
NMActiveConnection *nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
gboolean user_requested,
gulong user_uid,
GError **error);
gboolean nm_vpn_manager_deactivate_connection (NMVPNManager *manager,
const char *path,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment