2007-09-09 Dan Williams <dcbw@redhat.com>
* introspection/nm-device.xml - The 'Activate' method now takes 3 arguments, a service name for the settings service (user or system), the object path of the connection to activate, and the specific object to activate, if any * src/nm-device-interface.c - (nm_device_interface_error_quark, nm_device_interface_error_get_type): Add error bits - (impl_device_activate): adapt to new Activate arguments; validate the service name and get the Connection object from the NMManager before starting to activate the device with the specified connection * src/nm-device-802-3-ethernet.c - (real_get_best_connection): find the best connection, or create a default one if no existing connections can be used * src/NetworkManagerPolicy.c - (nm_policy_auto_get_best_device): Get the device's best connection and only pick the device if it has one - (nm_policy_device_change_check): disable wireless bits for now until wireless get_best_connection() can be implemented (replacing "best_ap"); don't create a default connection here as the device subclass will do that if needed * src/nm-manager.h src/nm-manager.c - (nm_manager_get): make NMManager a singleton and expose the getter internally - Rework internal NMManager connection handling to use the same routines for both the system and user settings services. Most calls take a new NMConnectionType argument specifying either system or user connections - (nm_manager_get_connection_by_object_path): new function; get a connection keyed on its object path * src/NetworkManager.c - (main): use nm_manager_get() git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2776 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
40
ChangeLog
40
ChangeLog
@@ -1,3 +1,43 @@
|
|||||||
|
2007-09-09 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
* introspection/nm-device.xml
|
||||||
|
- The 'Activate' method now takes 3 arguments, a service name for the
|
||||||
|
settings service (user or system), the object path of the connection
|
||||||
|
to activate, and the specific object to activate, if any
|
||||||
|
|
||||||
|
* src/nm-device-interface.c
|
||||||
|
- (nm_device_interface_error_quark, nm_device_interface_error_get_type):
|
||||||
|
Add error bits
|
||||||
|
- (impl_device_activate): adapt to new Activate arguments; validate
|
||||||
|
the service name and get the Connection object from the NMManager
|
||||||
|
before starting to activate the device with the specified connection
|
||||||
|
|
||||||
|
* src/nm-device-802-3-ethernet.c
|
||||||
|
- (real_get_best_connection): find the best connection, or create a
|
||||||
|
default one if no existing connections can be used
|
||||||
|
|
||||||
|
* src/NetworkManagerPolicy.c
|
||||||
|
- (nm_policy_auto_get_best_device): Get the device's best connection
|
||||||
|
and only pick the device if it has one
|
||||||
|
- (nm_policy_device_change_check): disable wireless bits for now until
|
||||||
|
wireless get_best_connection() can be implemented (replacing "best_ap");
|
||||||
|
don't create a default connection here as the device subclass will do
|
||||||
|
that if needed
|
||||||
|
|
||||||
|
* src/nm-manager.h
|
||||||
|
src/nm-manager.c
|
||||||
|
- (nm_manager_get): make NMManager a singleton and expose the getter
|
||||||
|
internally
|
||||||
|
- Rework internal NMManager connection handling to use the same
|
||||||
|
routines for both the system and user settings services. Most calls
|
||||||
|
take a new NMConnectionType argument specifying either system or user
|
||||||
|
connections
|
||||||
|
- (nm_manager_get_connection_by_object_path): new function; get a
|
||||||
|
connection keyed on its object path
|
||||||
|
|
||||||
|
* src/NetworkManager.c
|
||||||
|
- (main): use nm_manager_get()
|
||||||
|
|
||||||
2007-09-09 Dan Williams <dcbw@redhat.com>
|
2007-09-09 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* src/nm-device.h
|
* src/nm-device.h
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<interface name="org.freedesktop.NetworkManager.Device">
|
<interface name="org.freedesktop.NetworkManager.Device">
|
||||||
<method name="Activate">
|
<method name="Activate">
|
||||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_activate"/>
|
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_activate"/>
|
||||||
<arg name="connection" type="a{sa{sv}}o" direction="in"/>
|
<arg name="connection" type="soo" direction="in"/>
|
||||||
</method>
|
</method>
|
||||||
<method name="Deactivate">
|
<method name="Deactivate">
|
||||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_deactivate"/>
|
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_deactivate"/>
|
||||||
|
@@ -325,7 +325,7 @@ main (int argc, char *argv[])
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
manager = nm_manager_new ();
|
manager = nm_manager_get ();
|
||||||
if (manager == NULL) {
|
if (manager == NULL) {
|
||||||
nm_error ("Failed to initialize the network manager.");
|
nm_error ("Failed to initialize the network manager.");
|
||||||
goto done;
|
goto done;
|
||||||
|
@@ -64,48 +64,50 @@ static NMPolicy *global_policy;
|
|||||||
* "locked" on one device at this time.
|
* "locked" on one device at this time.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static NMDevice * nm_policy_auto_get_best_device (NMPolicy *policy, NMAccessPoint **ap)
|
static NMDevice *
|
||||||
|
nm_policy_auto_get_best_device (NMPolicy *policy,
|
||||||
|
NMConnection **connection)
|
||||||
{
|
{
|
||||||
GSList * elt;
|
GSList * elt;
|
||||||
NMDevice8023Ethernet * best_wired_dev = NULL;
|
NMDevice8023Ethernet * best_wired_dev = NULL;
|
||||||
guint best_wired_prio = 0;
|
guint best_wired_prio = 0;
|
||||||
|
NMConnection * best_wired_connection = NULL;
|
||||||
NMDevice80211Wireless * best_wireless_dev = NULL;
|
NMDevice80211Wireless * best_wireless_dev = NULL;
|
||||||
guint best_wireless_prio = 0;
|
guint best_wireless_prio = 0;
|
||||||
|
NMConnection * best_wireless_connection = NULL;
|
||||||
NMDevice * highest_priority_dev = NULL;
|
NMDevice * highest_priority_dev = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (ap != NULL, NULL);
|
g_return_val_if_fail (connection != NULL, NULL);
|
||||||
|
g_return_val_if_fail (*connection == NULL, NULL);
|
||||||
|
|
||||||
if (nm_manager_get_state (policy->manager) == NM_STATE_ASLEEP)
|
if (nm_manager_get_state (policy->manager) == NM_STATE_ASLEEP)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
|
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
|
||||||
gboolean link_active;
|
NMConnection *tmp_con = NULL;
|
||||||
guint prio = 0;
|
gboolean link_active;
|
||||||
NMDevice * dev = (NMDevice *)(elt->data);
|
guint prio = 0;
|
||||||
guint32 caps;
|
NMDevice * dev = (NMDevice *)(elt->data);
|
||||||
|
guint32 caps;
|
||||||
|
|
||||||
link_active = nm_device_has_active_link (dev);
|
link_active = nm_device_has_active_link (dev);
|
||||||
caps = nm_device_get_capabilities (dev);
|
caps = nm_device_get_capabilities (dev);
|
||||||
|
|
||||||
/* Don't use devices that SUCK */
|
tmp_con = nm_device_get_best_connection (dev);
|
||||||
if (!(caps & NM_DEVICE_CAP_NM_SUPPORTED))
|
if (tmp_con == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (NM_IS_DEVICE_802_3_ETHERNET (dev)) {
|
if (NM_IS_DEVICE_802_3_ETHERNET (dev)) {
|
||||||
/* We never automatically choose devices that don't support carrier detect */
|
|
||||||
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (link_active)
|
if (link_active)
|
||||||
prio += 1;
|
prio += 1;
|
||||||
|
|
||||||
if (nm_device_get_act_request (dev) && link_active)
|
if (nm_device_get_act_request (dev) && link_active)
|
||||||
prio += 1;
|
prio += 1;
|
||||||
|
|
||||||
if (prio > best_wired_prio)
|
if (prio > best_wired_prio) {
|
||||||
{
|
|
||||||
best_wired_dev = NM_DEVICE_802_3_ETHERNET (dev);
|
best_wired_dev = NM_DEVICE_802_3_ETHERNET (dev);
|
||||||
best_wired_prio = prio;
|
best_wired_prio = prio;
|
||||||
|
best_wired_connection = tmp_con;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (NM_IS_DEVICE_802_11_WIRELESS (dev) &&
|
else if (NM_IS_DEVICE_802_11_WIRELESS (dev) &&
|
||||||
@@ -119,40 +121,46 @@ static NMDevice * nm_policy_auto_get_best_device (NMPolicy *policy, NMAccessPoin
|
|||||||
if (nm_device_get_act_request (dev) && link_active)
|
if (nm_device_get_act_request (dev) && link_active)
|
||||||
prio += 3;
|
prio += 3;
|
||||||
|
|
||||||
if (prio > best_wireless_prio)
|
if (prio > best_wireless_prio) {
|
||||||
{
|
|
||||||
best_wireless_dev = NM_DEVICE_802_11_WIRELESS (dev);
|
best_wireless_dev = NM_DEVICE_802_11_WIRELESS (dev);
|
||||||
best_wireless_prio = prio;
|
best_wireless_prio = prio;
|
||||||
|
best_wireless_connection = tmp_con;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best_wired_dev)
|
if (best_wired_dev) {
|
||||||
highest_priority_dev = NM_DEVICE (best_wired_dev);
|
highest_priority_dev = NM_DEVICE (best_wired_dev);
|
||||||
else if (best_wireless_dev)
|
*connection = best_wired_connection;
|
||||||
{
|
} else if (best_wireless_dev) {
|
||||||
gboolean can_activate;
|
gboolean can_activate;
|
||||||
|
|
||||||
can_activate = nm_device_802_11_wireless_can_activate (best_wireless_dev);
|
can_activate = nm_device_802_11_wireless_can_activate (best_wireless_dev);
|
||||||
|
if (can_activate) {
|
||||||
*ap = nm_device_802_11_wireless_get_best_ap (best_wireless_dev);
|
|
||||||
/* If the device doesn't have a "best" ap, then we can't use it */
|
|
||||||
if (!*ap)
|
|
||||||
highest_priority_dev = NULL;
|
|
||||||
else if (can_activate == TRUE)
|
|
||||||
highest_priority_dev = NM_DEVICE (best_wireless_dev);
|
highest_priority_dev = NM_DEVICE (best_wireless_dev);
|
||||||
|
*connection = best_wireless_connection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
if (FALSE) {
|
if (FALSE) {
|
||||||
const GByteArray * ssid = (best_wireless_dev && *ap) ? nm_ap_get_ssid (*ap) : NULL;
|
char * con_name = g_strdup ("(none)");
|
||||||
|
|
||||||
nm_info ("AUTO: Best wired device = %s, best wireless device = %s (%s)",
|
if (*connection) {
|
||||||
|
NMSettingConnection * s_con;
|
||||||
|
|
||||||
|
s_con = (NMSettingConnection *) nm_connection_get_setting (*connection, "connection");
|
||||||
|
con_name = g_strdup (s_con->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
nm_info ("AUTO: Best wired device = %s, best wireless device = %s, best connection name = '%s'",
|
||||||
best_wired_dev ? nm_device_get_iface (NM_DEVICE (best_wired_dev)) : "(null)",
|
best_wired_dev ? nm_device_get_iface (NM_DEVICE (best_wired_dev)) : "(null)",
|
||||||
best_wireless_dev ? nm_device_get_iface (NM_DEVICE (best_wireless_dev)) : "(null)",
|
best_wireless_dev ? nm_device_get_iface (NM_DEVICE (best_wireless_dev)) : "(null)",
|
||||||
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "null" );
|
con_name);
|
||||||
|
g_free (con_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return highest_priority_dev;
|
return *connection ? highest_priority_dev : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMConnection *
|
static NMConnection *
|
||||||
@@ -214,10 +222,10 @@ nm_policy_device_change_check (gpointer user_data)
|
|||||||
{
|
{
|
||||||
NMPolicy *policy = (NMPolicy *) user_data;
|
NMPolicy *policy = (NMPolicy *) user_data;
|
||||||
GSList *iter;
|
GSList *iter;
|
||||||
NMAccessPoint * ap = NULL;
|
NMConnection * connection = NULL;
|
||||||
NMDevice * new_dev = NULL;
|
NMDevice * new_dev = NULL;
|
||||||
NMDevice * old_dev = NULL;
|
NMDevice * old_dev = NULL;
|
||||||
gboolean do_switch = FALSE;
|
gboolean do_switch = FALSE;
|
||||||
|
|
||||||
switch (nm_manager_get_state (policy->manager)) {
|
switch (nm_manager_get_state (policy->manager)) {
|
||||||
case NM_STATE_CONNECTED:
|
case NM_STATE_CONNECTED:
|
||||||
@@ -258,7 +266,7 @@ nm_policy_device_change_check (gpointer user_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_dev = nm_policy_auto_get_best_device (policy, &ap);
|
new_dev = nm_policy_auto_get_best_device (policy, &connection);
|
||||||
|
|
||||||
/* Four cases here:
|
/* Four cases here:
|
||||||
*
|
*
|
||||||
@@ -306,6 +314,7 @@ nm_policy_device_change_check (gpointer user_data)
|
|||||||
do_switch = TRUE;
|
do_switch = TRUE;
|
||||||
}
|
}
|
||||||
} else if (NM_IS_DEVICE_802_11_WIRELESS (old_dev)) {
|
} else if (NM_IS_DEVICE_802_11_WIRELESS (old_dev)) {
|
||||||
|
#if 0
|
||||||
/* Only switch if the old device's wireless config is invalid */
|
/* Only switch if the old device's wireless config is invalid */
|
||||||
if (NM_IS_DEVICE_802_11_WIRELESS (new_dev)) {
|
if (NM_IS_DEVICE_802_11_WIRELESS (new_dev)) {
|
||||||
NMAccessPoint *old_ap = nm_device_802_11_wireless_get_activation_ap (NM_DEVICE_802_11_WIRELESS (old_dev));
|
NMAccessPoint *old_ap = nm_device_802_11_wireless_get_activation_ap (NM_DEVICE_802_11_WIRELESS (old_dev));
|
||||||
@@ -352,6 +361,7 @@ nm_policy_device_change_check (gpointer user_data)
|
|||||||
if (!old_user_requested)
|
if (!old_user_requested)
|
||||||
do_switch = TRUE;
|
do_switch = TRUE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,18 +371,11 @@ nm_policy_device_change_check (gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (new_dev) {
|
if (new_dev) {
|
||||||
NMConnection *connection;
|
nm_device_interface_activate (NM_DEVICE_INTERFACE (new_dev),
|
||||||
|
connection, NULL, FALSE);
|
||||||
connection = create_connection (new_dev, ap);
|
|
||||||
if (connection)
|
|
||||||
nm_device_interface_activate (NM_DEVICE_INTERFACE (new_dev),
|
|
||||||
connection, NULL, FALSE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ap)
|
|
||||||
g_object_unref (ap);
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "nm-supplicant-manager.h"
|
#include "nm-supplicant-manager.h"
|
||||||
#include "nm-netlink-monitor.h"
|
#include "nm-netlink-monitor.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
#include "nm-manager.h"
|
||||||
|
|
||||||
#include "nm-device-802-3-ethernet-glue.h"
|
#include "nm-device-802-3-ethernet-glue.h"
|
||||||
|
|
||||||
@@ -344,6 +345,95 @@ real_check_connection (NMDevice *dev, NMConnection *connection)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct BestConnectionInfo {
|
||||||
|
NMDevice8023Ethernet * self;
|
||||||
|
NMConnection * found;
|
||||||
|
} BestConnectionInfo;
|
||||||
|
|
||||||
|
static void
|
||||||
|
find_best_connection (gpointer data, gpointer user_data)
|
||||||
|
{
|
||||||
|
BestConnectionInfo * info = (BestConnectionInfo *) user_data;
|
||||||
|
NMConnection *connection = NM_CONNECTION (data);
|
||||||
|
NMSettingConnection * s_con;
|
||||||
|
NMSettingWired * s_wired;
|
||||||
|
|
||||||
|
if (info->found)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, "connection");
|
||||||
|
if (s_con == NULL)
|
||||||
|
return;
|
||||||
|
if (strcmp (s_con->devtype, "802-3-ethernet"))
|
||||||
|
return;
|
||||||
|
if (!s_con->autoconnect)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s_wired = (NMSettingWired *) nm_connection_get_setting (connection, "802-3-ethernet");
|
||||||
|
if (s_wired == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
info->found = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NMConnection *
|
||||||
|
real_get_best_connection (NMDevice *dev)
|
||||||
|
{
|
||||||
|
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (dev);
|
||||||
|
NMManager *manager = nm_manager_get ();
|
||||||
|
GSList *connections = NULL;
|
||||||
|
BestConnectionInfo find_info;
|
||||||
|
guint32 caps;
|
||||||
|
gboolean link_active;
|
||||||
|
|
||||||
|
caps = nm_device_get_capabilities (dev);
|
||||||
|
|
||||||
|
/* FIXME: for now, non-carrier-detect devices don't have a best connection,
|
||||||
|
* the user needs to pick one. In the near-future, we want to instead
|
||||||
|
* honor the first 'autoconnect':True connection we find that applies
|
||||||
|
* to this device.
|
||||||
|
*/
|
||||||
|
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* System connections first */
|
||||||
|
connections = nm_manager_get_connections (manager, NM_CONNECTION_TYPE_SYSTEM);
|
||||||
|
memset (&find_info, 0, sizeof (BestConnectionInfo));
|
||||||
|
find_info.self = self;
|
||||||
|
g_slist_foreach (connections, find_best_connection, &find_info);
|
||||||
|
g_slist_free (connections);
|
||||||
|
|
||||||
|
/* Then user connections */
|
||||||
|
if (!find_info.found) {
|
||||||
|
connections = nm_manager_get_connections (manager, NM_CONNECTION_TYPE_USER);
|
||||||
|
find_info.self = self;
|
||||||
|
g_slist_foreach (connections, find_best_connection, &find_info);
|
||||||
|
g_slist_free (connections);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wired devices autoconnect with DHCP by default if they have a link */
|
||||||
|
link_active = nm_device_has_active_link (dev);
|
||||||
|
if (!find_info.found && link_active) {
|
||||||
|
NMConnection *connection;
|
||||||
|
NMSetting *setting;
|
||||||
|
NMSettingConnection *scon;
|
||||||
|
|
||||||
|
connection = nm_connection_new ();
|
||||||
|
setting = nm_setting_wired_new ();
|
||||||
|
nm_connection_add_setting (connection, setting);
|
||||||
|
|
||||||
|
scon = (NMSettingConnection *) nm_setting_connection_new ();
|
||||||
|
scon->name = g_strdup ("Auto");
|
||||||
|
scon->devtype = g_strdup (setting->name);
|
||||||
|
nm_connection_add_setting (connection, (NMSetting *) scon);
|
||||||
|
|
||||||
|
find_info.found = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
return find_info.found;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_device_802_3_ethernet_finalize (GObject *object)
|
nm_device_802_3_ethernet_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
@@ -400,6 +490,7 @@ nm_device_802_3_ethernet_class_init (NMDevice8023EthernetClass *klass)
|
|||||||
parent_class->can_interrupt_activation = real_can_interrupt_activation;
|
parent_class->can_interrupt_activation = real_can_interrupt_activation;
|
||||||
parent_class->set_hw_address = real_set_hw_address;
|
parent_class->set_hw_address = real_set_hw_address;
|
||||||
parent_class->check_connection = real_check_connection;
|
parent_class->check_connection = real_check_connection;
|
||||||
|
parent_class->get_best_connection = real_get_best_connection;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
g_object_class_install_property
|
g_object_class_install_property
|
||||||
|
@@ -1,16 +1,46 @@
|
|||||||
|
|
||||||
#include "nm-device-interface.h"
|
#include "nm-device-interface.h"
|
||||||
#include "nm-ip4-config.h"
|
#include "nm-ip4-config.h"
|
||||||
|
#include "nm-manager.h"
|
||||||
|
|
||||||
static gboolean impl_device_activate (NMDeviceInterface *device,
|
static gboolean impl_device_activate (NMDeviceInterface *device,
|
||||||
GHashTable *connection_hash,
|
const char *service_name,
|
||||||
const char *specific_object,
|
const char *connection_path,
|
||||||
GError **err);
|
const char *specific_object,
|
||||||
|
GError **err);
|
||||||
|
|
||||||
static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err);
|
static gboolean impl_device_deactivate (NMDeviceInterface *device, GError **err);
|
||||||
|
|
||||||
#include "nm-device-interface-glue.h"
|
#include "nm-device-interface-glue.h"
|
||||||
|
|
||||||
|
GQuark
|
||||||
|
nm_device_interface_error_quark (void)
|
||||||
|
{
|
||||||
|
static GQuark quark = 0;
|
||||||
|
if (!quark)
|
||||||
|
quark = g_quark_from_static_string ("nm_device_interface_error");
|
||||||
|
return quark;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This should really be standard. */
|
||||||
|
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
|
||||||
|
|
||||||
|
GType
|
||||||
|
nm_device_interface_error_get_type (void)
|
||||||
|
{
|
||||||
|
static GType etype = 0;
|
||||||
|
|
||||||
|
if (etype == 0) {
|
||||||
|
static const GEnumValue values[] = {
|
||||||
|
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_UNKNOWN_CONNECTION, "UnknownConnection"),
|
||||||
|
{ 0, 0, 0 }
|
||||||
|
};
|
||||||
|
etype = g_enum_register_static ("NMDeviceInterfaceError", values);
|
||||||
|
}
|
||||||
|
return etype;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_device_interface_init (gpointer g_iface)
|
nm_device_interface_init (gpointer g_iface)
|
||||||
{
|
{
|
||||||
@@ -164,18 +194,41 @@ nm_device_interface_activate (NMDeviceInterface *device,
|
|||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
impl_device_activate (NMDeviceInterface *device,
|
impl_device_activate (NMDeviceInterface *device,
|
||||||
GHashTable *connection_hash,
|
const char *service_name,
|
||||||
const char *specific_object,
|
const char *connection_path,
|
||||||
GError **err)
|
const char *specific_object,
|
||||||
|
GError **err)
|
||||||
{
|
{
|
||||||
|
NMManager *manager;
|
||||||
NMConnection *connection;
|
NMConnection *connection;
|
||||||
|
gboolean success = FALSE;
|
||||||
|
|
||||||
|
manager = nm_manager_get ();
|
||||||
|
if (!strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS)) {
|
||||||
|
connection = nm_manager_get_connection_by_object_path (manager,
|
||||||
|
NM_CONNECTION_TYPE_USER,
|
||||||
|
connection_path);
|
||||||
|
} else if (!strcmp (service_name, NM_DBUS_SERVICE_USER_SETTINGS)) {
|
||||||
|
connection = nm_manager_get_connection_by_object_path (manager,
|
||||||
|
NM_CONNECTION_TYPE_SYSTEM,
|
||||||
|
connection_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connection == NULL) {
|
||||||
|
g_set_error (err,
|
||||||
|
NM_DEVICE_INTERFACE_ERROR,
|
||||||
|
NM_DEVICE_INTERFACE_ERROR_UNKNOWN_CONNECTION,
|
||||||
|
"%s",
|
||||||
|
"Connection object or service unknown");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
connection = nm_connection_new_from_hash (connection_hash);
|
|
||||||
nm_connection_dump (connection);
|
nm_connection_dump (connection);
|
||||||
|
|
||||||
nm_device_interface_activate (device, connection, specific_object, TRUE);
|
nm_device_interface_activate (device, connection, specific_object, TRUE);
|
||||||
|
success = TRUE;
|
||||||
|
|
||||||
return TRUE;
|
out:
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
153
src/nm-manager.c
153
src/nm-manager.c
@@ -20,14 +20,19 @@ static gboolean impl_manager_legacy_state (NMManager *manager, GError **err);
|
|||||||
|
|
||||||
#include "nm-manager-glue.h"
|
#include "nm-manager-glue.h"
|
||||||
|
|
||||||
static void nm_manager_user_connections_destroy (NMManager *manager);
|
static void nm_manager_connections_destroy (NMManager *manager, NMConnectionType type);
|
||||||
static void manager_state_changed (NMManager *manager);
|
static void manager_state_changed (NMManager *manager);
|
||||||
static void manager_set_wireless_enabled (NMManager *manager, gboolean enabled);
|
static void manager_set_wireless_enabled (NMManager *manager, gboolean enabled);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GSList *devices;
|
GSList *devices;
|
||||||
|
|
||||||
GHashTable *user_connections;
|
GHashTable *user_connections;
|
||||||
DBusGProxy *user_proxy;
|
DBusGProxy *user_proxy;
|
||||||
|
|
||||||
|
GHashTable *system_connections;
|
||||||
|
DBusGProxy *system_proxy;
|
||||||
|
|
||||||
gboolean wireless_enabled;
|
gboolean wireless_enabled;
|
||||||
gboolean sleeping;
|
gboolean sleeping;
|
||||||
} NMManagerPrivate;
|
} NMManagerPrivate;
|
||||||
@@ -68,6 +73,11 @@ nm_manager_init (NMManager *manager)
|
|||||||
g_str_equal,
|
g_str_equal,
|
||||||
g_free,
|
g_free,
|
||||||
g_object_unref);
|
g_object_unref);
|
||||||
|
|
||||||
|
priv->system_connections = g_hash_table_new_full (g_str_hash,
|
||||||
|
g_str_equal,
|
||||||
|
g_free,
|
||||||
|
g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -76,10 +86,14 @@ finalize (GObject *object)
|
|||||||
NMManager *manager = NM_MANAGER (object);
|
NMManager *manager = NM_MANAGER (object);
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
|
|
||||||
nm_manager_user_connections_destroy (manager);
|
nm_manager_connections_destroy (manager, NM_CONNECTION_TYPE_USER);
|
||||||
g_hash_table_destroy (priv->user_connections);
|
g_hash_table_destroy (priv->user_connections);
|
||||||
priv->user_connections = NULL;
|
priv->user_connections = NULL;
|
||||||
|
|
||||||
|
nm_manager_connections_destroy (manager, NM_CONNECTION_TYPE_SYSTEM);
|
||||||
|
g_hash_table_destroy (priv->system_connections);
|
||||||
|
priv->system_connections = NULL;
|
||||||
|
|
||||||
while (g_slist_length (priv->devices))
|
while (g_slist_length (priv->devices))
|
||||||
nm_manager_remove_device (manager, NM_DEVICE (priv->devices->data));
|
nm_manager_remove_device (manager, NM_DEVICE (priv->devices->data));
|
||||||
|
|
||||||
@@ -400,43 +414,57 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
query_user_connections (NMManager *manager)
|
query_connections (NMManager *manager,
|
||||||
|
NMConnectionType type)
|
||||||
{
|
{
|
||||||
NMManagerPrivate *priv;
|
NMManagerPrivate *priv;
|
||||||
DBusGProxyCall *call;
|
DBusGProxyCall *call;
|
||||||
|
DBusGProxy ** proxy;
|
||||||
|
const char * service;
|
||||||
|
|
||||||
g_return_if_fail (NM_IS_MANAGER (manager));
|
g_return_if_fail (NM_IS_MANAGER (manager));
|
||||||
|
|
||||||
|
if (type == NM_CONNECTION_TYPE_USER) {
|
||||||
|
proxy = &priv->user_proxy;
|
||||||
|
service = NM_DBUS_SERVICE_USER_SETTINGS;
|
||||||
|
} else if (type == NM_CONNECTION_TYPE_SYSTEM) {
|
||||||
|
proxy = &priv->system_proxy;
|
||||||
|
service = NM_DBUS_SERVICE_SYSTEM_SETTINGS;
|
||||||
|
} else {
|
||||||
|
nm_warning ("Unknown NMConnectionType %d", type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
priv = NM_MANAGER_GET_PRIVATE (manager);
|
priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
if (!priv->user_proxy) {
|
if (!*proxy) {
|
||||||
NMDBusManager * dbus_mgr;
|
NMDBusManager * dbus_mgr;
|
||||||
DBusGConnection * g_connection;
|
DBusGConnection * g_connection;
|
||||||
|
|
||||||
dbus_mgr = nm_dbus_manager_get ();
|
dbus_mgr = nm_dbus_manager_get ();
|
||||||
g_connection = nm_dbus_manager_get_connection (dbus_mgr);
|
g_connection = nm_dbus_manager_get_connection (dbus_mgr);
|
||||||
priv->user_proxy = dbus_g_proxy_new_for_name (g_connection,
|
*proxy = dbus_g_proxy_new_for_name (g_connection,
|
||||||
NM_DBUS_SERVICE_USER_SETTINGS,
|
service,
|
||||||
NM_DBUS_PATH_SETTINGS,
|
NM_DBUS_PATH_SETTINGS,
|
||||||
NM_DBUS_IFACE_SETTINGS);
|
NM_DBUS_IFACE_SETTINGS);
|
||||||
g_object_unref (dbus_mgr);
|
g_object_unref (dbus_mgr);
|
||||||
if (!priv->user_proxy) {
|
if (!*proxy) {
|
||||||
nm_warning ("Error: could not init user settings proxy");
|
nm_warning ("Error: could not init settings proxy");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_g_proxy_add_signal (priv->user_proxy,
|
dbus_g_proxy_add_signal (*proxy,
|
||||||
"NewConnection",
|
"NewConnection",
|
||||||
DBUS_TYPE_G_OBJECT_PATH,
|
DBUS_TYPE_G_OBJECT_PATH,
|
||||||
G_TYPE_INVALID);
|
G_TYPE_INVALID);
|
||||||
|
|
||||||
dbus_g_proxy_connect_signal (priv->user_proxy, "NewConnection",
|
dbus_g_proxy_connect_signal (*proxy, "NewConnection",
|
||||||
G_CALLBACK (new_connection_cb),
|
G_CALLBACK (new_connection_cb),
|
||||||
manager,
|
manager,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* grab connections */
|
/* grab connections */
|
||||||
call = dbus_g_proxy_begin_call (priv->user_proxy, "ListConnections",
|
call = dbus_g_proxy_begin_call (*proxy, "ListConnections",
|
||||||
list_connections_cb,
|
list_connections_cb,
|
||||||
manager,
|
manager,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -457,10 +485,18 @@ nm_manager_name_owner_changed (NMDBusManager *mgr,
|
|||||||
if (strcmp (name, NM_DBUS_SERVICE_USER_SETTINGS) == 0) {
|
if (strcmp (name, NM_DBUS_SERVICE_USER_SETTINGS) == 0) {
|
||||||
if (!old_owner_good && new_owner_good) {
|
if (!old_owner_good && new_owner_good) {
|
||||||
/* User Settings service appeared, update stuff */
|
/* User Settings service appeared, update stuff */
|
||||||
query_user_connections (manager);
|
query_connections (manager, NM_CONNECTION_TYPE_USER);
|
||||||
} else {
|
} else {
|
||||||
/* User Settings service disappeared, throw them away (?) */
|
/* User Settings service disappeared, throw them away (?) */
|
||||||
nm_manager_user_connections_destroy (manager);
|
nm_manager_connections_destroy (manager, NM_CONNECTION_TYPE_USER);
|
||||||
|
}
|
||||||
|
} else if (strcmp (name, NM_DBUS_SERVICE_SYSTEM_SETTINGS) == 0) {
|
||||||
|
if (!old_owner_good && new_owner_good) {
|
||||||
|
/* System Settings service appeared, update stuff */
|
||||||
|
query_connections (manager, NM_CONNECTION_TYPE_SYSTEM);
|
||||||
|
} else {
|
||||||
|
/* System Settings service disappeared, throw them away (?) */
|
||||||
|
nm_manager_connections_destroy (manager, NM_CONNECTION_TYPE_SYSTEM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -472,13 +508,17 @@ initial_get_connections (gpointer user_data)
|
|||||||
|
|
||||||
if (nm_dbus_manager_name_has_owner (nm_dbus_manager_get (),
|
if (nm_dbus_manager_name_has_owner (nm_dbus_manager_get (),
|
||||||
NM_DBUS_SERVICE_USER_SETTINGS))
|
NM_DBUS_SERVICE_USER_SETTINGS))
|
||||||
query_user_connections (manager);
|
query_connections (manager, NM_CONNECTION_TYPE_USER);
|
||||||
|
|
||||||
|
if (nm_dbus_manager_name_has_owner (nm_dbus_manager_get (),
|
||||||
|
NM_DBUS_SERVICE_SYSTEM_SETTINGS))
|
||||||
|
query_connections (manager, NM_CONNECTION_TYPE_SYSTEM);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NMManager *
|
static NMManager *
|
||||||
nm_manager_new (void)
|
nm_manager_new (void)
|
||||||
{
|
{
|
||||||
GObject *object;
|
GObject *object;
|
||||||
@@ -503,17 +543,44 @@ nm_manager_new (void)
|
|||||||
return NM_MANAGER (object);
|
return NM_MANAGER (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NMManager *
|
||||||
|
nm_manager_get (void)
|
||||||
|
{
|
||||||
|
static NMManager *singleton = NULL;
|
||||||
|
|
||||||
|
if (!singleton)
|
||||||
|
singleton = nm_manager_new ();
|
||||||
|
else
|
||||||
|
g_object_ref (singleton);
|
||||||
|
|
||||||
|
g_assert (singleton);
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_manager_user_connections_destroy (NMManager *manager)
|
nm_manager_connections_destroy (NMManager *manager,
|
||||||
|
NMConnectionType type)
|
||||||
{
|
{
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
|
|
||||||
if (priv->user_connections)
|
if (type == NM_CONNECTION_TYPE_USER) {
|
||||||
g_hash_table_remove_all (priv->user_connections);
|
if (priv->user_connections)
|
||||||
|
g_hash_table_remove_all (priv->user_connections);
|
||||||
|
|
||||||
if (priv->user_proxy) {
|
if (priv->user_proxy) {
|
||||||
g_object_unref (priv->user_proxy);
|
g_object_unref (priv->user_proxy);
|
||||||
priv->user_proxy = NULL;
|
priv->user_proxy = NULL;
|
||||||
|
}
|
||||||
|
} else if (type == NM_CONNECTION_TYPE_SYSTEM) {
|
||||||
|
if (priv->system_connections)
|
||||||
|
g_hash_table_remove_all (priv->system_connections);
|
||||||
|
|
||||||
|
if (priv->system_proxy) {
|
||||||
|
g_object_unref (priv->system_proxy);
|
||||||
|
priv->system_proxy = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nm_warning ("Unknown NMConnectionType %d", type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -837,7 +904,8 @@ connections_to_slist (gpointer key, gpointer value, gpointer user_data)
|
|||||||
* unref the connections in the list and destroy the list.
|
* unref the connections in the list and destroy the list.
|
||||||
*/
|
*/
|
||||||
GSList *
|
GSList *
|
||||||
nm_manager_get_user_connections (NMManager *manager)
|
nm_manager_get_connections (NMManager *manager,
|
||||||
|
NMConnectionType type)
|
||||||
{
|
{
|
||||||
NMManagerPrivate *priv;
|
NMManagerPrivate *priv;
|
||||||
GSList *list = NULL;
|
GSList *list = NULL;
|
||||||
@@ -845,18 +913,45 @@ nm_manager_get_user_connections (NMManager *manager)
|
|||||||
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
|
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
|
||||||
|
|
||||||
priv = NM_MANAGER_GET_PRIVATE (manager);
|
priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
g_hash_table_foreach (priv->user_connections, connections_to_slist, &list);
|
if (type == NM_CONNECTION_TYPE_USER)
|
||||||
|
g_hash_table_foreach (priv->user_connections, connections_to_slist, &list);
|
||||||
|
else if (type == NM_CONNECTION_TYPE_SYSTEM)
|
||||||
|
g_hash_table_foreach (priv->system_connections, connections_to_slist, &list);
|
||||||
|
else
|
||||||
|
nm_warning ("Unknown NMConnectionType %d", type);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NMConnection *
|
||||||
|
nm_manager_get_connection_by_object_path (NMManager *manager,
|
||||||
|
NMConnectionType type,
|
||||||
|
const char *path)
|
||||||
|
{
|
||||||
|
NMManagerPrivate *priv;
|
||||||
|
NMConnection *connection = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
|
||||||
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
|
priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
|
if (type == NM_CONNECTION_TYPE_USER)
|
||||||
|
connection = (NMConnection *) g_hash_table_lookup (priv->user_connections, path);
|
||||||
|
else if (type == NM_CONNECTION_TYPE_SYSTEM)
|
||||||
|
connection = (NMConnection *) g_hash_table_lookup (priv->system_connections, path);
|
||||||
|
else
|
||||||
|
nm_warning ("Unknown NMConnectionType %d", type);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nm_manager_update_user_connections (NMManager *manager,
|
nm_manager_update_connections (NMManager *manager,
|
||||||
GSList *connections,
|
NMConnectionType type,
|
||||||
gboolean reset)
|
GSList *connections,
|
||||||
|
gboolean reset)
|
||||||
{
|
{
|
||||||
g_return_if_fail (NM_IS_MANAGER (manager));
|
g_return_if_fail (NM_IS_MANAGER (manager));
|
||||||
|
|
||||||
if (reset)
|
if (reset)
|
||||||
nm_manager_user_connections_destroy (manager);
|
nm_manager_connections_destroy (manager, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ typedef struct {
|
|||||||
|
|
||||||
GType nm_manager_get_type (void);
|
GType nm_manager_get_type (void);
|
||||||
|
|
||||||
NMManager *nm_manager_new (void);
|
NMManager *nm_manager_get (void);
|
||||||
|
|
||||||
/* Device handling */
|
/* Device handling */
|
||||||
|
|
||||||
@@ -54,15 +54,19 @@ gboolean nm_manager_wireless_enabled (NMManager *manager);
|
|||||||
void nm_manager_sleep (NMManager *manager, gboolean sleep);
|
void nm_manager_sleep (NMManager *manager, gboolean sleep);
|
||||||
|
|
||||||
/* Connections */
|
/* Connections */
|
||||||
|
typedef enum {
|
||||||
|
NM_CONNECTION_TYPE_SYSTEM = 0,
|
||||||
|
NM_CONNECTION_TYPE_USER,
|
||||||
|
} NMConnectionType;
|
||||||
|
|
||||||
GSList *nm_manager_get_user_connections (NMManager *manager);
|
GSList *nm_manager_get_connections (NMManager *manager, NMConnectionType type);
|
||||||
void nm_manager_update_user_connections (NMManager *manager,
|
void nm_manager_update_connections (NMManager *manager,
|
||||||
GSList *connections,
|
NMConnectionType type,
|
||||||
gboolean reset);
|
GSList *connections,
|
||||||
|
gboolean reset);
|
||||||
|
|
||||||
GSList *nm_manager_get_system_connections (NMManager *manager);
|
NMConnection * nm_manager_get_connection_by_object_path (NMManager *manager,
|
||||||
void nm_manager_update_system_connections (NMManager *manager,
|
NMConnectionType type,
|
||||||
GSList *connections,
|
const char *path);
|
||||||
gboolean reset);
|
|
||||||
|
|
||||||
#endif /* NM_MANAGER_H */
|
#endif /* NM_MANAGER_H */
|
||||||
|
Reference in New Issue
Block a user