NMActRequest * nm_act_request_new (NMConnection *connection, const char *specific_object, gboolean user_requested, gboolean assumed, gpointer *device) { GObject *object; NMActRequestPrivate *priv; 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); 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), NM_ACT_REQUEST (object)); priv->user_requested = user_requested; priv->assumed = assumed; return NM_ACT_REQUEST (object); }
static void finalize (GObject *object) { clear_share_rules (NM_ACT_REQUEST (object)); G_OBJECT_CLASS (nm_act_request_parent_class)->finalize (object); }
static void device_state_changed (NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { NMActRequest *self = NM_ACT_REQUEST (user_data); NMActiveConnectionState new_ac_state; /* Set NMActiveConnection state based on the device's state */ switch (new_state) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_IP_CHECK: case NM_DEVICE_STATE_SECONDARIES: new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; break; case NM_DEVICE_STATE_ACTIVATED: new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; break; case NM_DEVICE_STATE_DEACTIVATING: new_ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATING; break; default: new_ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; nm_active_connection_set_default (NM_ACTIVE_CONNECTION (self), FALSE); nm_active_connection_set_default6 (NM_ACTIVE_CONNECTION (self), FALSE); break; } nm_active_connection_set_state (NM_ACTIVE_CONNECTION (self), new_ac_state); }
static void dispose (GObject *object) { NMActRequest *self = NM_ACT_REQUEST (object); NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (self); /* Kill any in-progress secrets requests */ while (priv->secrets_calls) _do_cancel_secrets (self, priv->secrets_calls->data, TRUE); /* Clear any share rules */ if (priv->share_rules) { nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE); clear_share_rules (NM_ACT_REQUEST (object)); } G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); }
static void dispose (GObject *object) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); GSList *iter; if (priv->disposed) { G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); return; } priv->disposed = TRUE; g_signal_handlers_disconnect_by_func (G_OBJECT (priv->device), G_CALLBACK (device_state_changed), NM_ACT_REQUEST (object)); /* Clear any share rules */ nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE); /* Kill any in-progress secrets requests */ g_assert (priv->connection); for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) { GetSecretsInfo *info = iter->data; nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id); g_free (info); } g_slist_free (priv->secrets_calls); g_object_unref (priv->connection); g_free (priv->dbus_sender); if (priv->dep) { g_object_weak_unref (G_OBJECT (priv->dep), (GWeakNotify) dep_gone, object); g_signal_handler_disconnect (priv->dep, priv->dep_state_id); priv->dep = NULL; priv->dep_state_id = 0; } G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); }
/** * 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 * @dbus_sender: if @user_requested is %TRUE, the D-BUS sender 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 * @dependency: 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, const char *dbus_sender, gboolean assumed, gpointer *device, NMActiveConnection *dependency) { GObject *object; NMActRequestPrivate *priv; 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, 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); priv->device = NM_DEVICE (device); g_signal_connect (device, "state-changed", G_CALLBACK (device_state_changed), NM_ACT_REQUEST (object)); priv->user_uid = user_uid; priv->user_requested = user_requested; priv->dbus_sender = g_strdup (dbus_sender); priv->assumed = assumed; if (dependency) { priv->dep = dependency; g_object_weak_ref (G_OBJECT (dependency), (GWeakNotify) dep_gone, object); priv->dep_state_id = g_signal_connect (dependency, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (dep_state_changed), 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 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); }
static void dispose (GObject *object) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); if (priv->disposed) { G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); return; } priv->disposed = TRUE; g_assert (priv->connection); g_signal_handlers_disconnect_by_func (G_OBJECT (priv->device), G_CALLBACK (device_state_changed), NM_ACT_REQUEST (object)); /* Clear any share rules */ nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE); g_object_unref (priv->connection); G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); }
static void dispose (GObject *object) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); GSList *iter; if (priv->device && priv->device_state_id) { g_signal_handler_disconnect (priv->device, priv->device_state_id); priv->device_state_id = 0; } /* Clear any share rules */ if (priv->share_rules) { nm_act_request_set_shared (NM_ACT_REQUEST (object), FALSE); clear_share_rules (NM_ACT_REQUEST (object)); } /* Kill any in-progress secrets requests */ for (iter = priv->secrets_calls; iter; iter = g_slist_next (iter)) { GetSecretsInfo *info = iter->data; g_assert (priv->connection); nm_settings_connection_cancel_secrets (NM_SETTINGS_CONNECTION (priv->connection), info->call_id); g_free (info); } g_slist_free (priv->secrets_calls); priv->secrets_calls = NULL; g_free (priv->dbus_sender); priv->dbus_sender = NULL; g_clear_object (&priv->device); g_clear_object (&priv->connection); G_OBJECT_CLASS (nm_act_request_parent_class)->dispose (object); }
static void device_state_changed (NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, 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) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; 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; default: new_ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; 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); } }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); NMDevice *master; switch (prop_id) { case PROP_MASTER: if (priv->dep && NM_IS_ACT_REQUEST (priv->dep)) { master = NM_DEVICE (nm_act_request_get_device (NM_ACT_REQUEST (priv->dep))); g_assert (master); g_value_set_boxed (value, nm_device_get_path (master)); } else g_value_set_boxed (value, "/"); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void constructed (GObject *object) { NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object); NMConnection *connection; NMDevice *device; G_OBJECT_CLASS (nm_act_request_parent_class)->constructed (object); connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (object)); priv->connection = g_object_ref (connection); device = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object)); if (device) { priv->device = g_object_ref (device); priv->device_state_id = g_signal_connect (priv->device, "notify::" NM_DEVICE_STATE, G_CALLBACK (device_state_changed), NM_ACT_REQUEST (object)); } }