Commit 5da37a12 authored by Dan Williams's avatar Dan Williams Committed by Thomas Haller

api/manager: add GetAllDevices() method and AllDevices property

Returns both realized and un-realized devices.
parent 20906ca7
......@@ -6,11 +6,27 @@
<method name="GetDevices">
<tp:docstring>
Get the list of network devices.
Get the list of realized network devices.
</tp:docstring>
<arg name="devices" type="ao" direction="out">
<tp:docstring>
List of object paths of network devices known to the system.
List of object paths of network devices known to the system. This
list does not include device placeholders (see GetAllDevices()).
</tp:docstring>
</arg>
</method>
<method name="GetAllDevices">
<tp:docstring>
Get the list of all network devices.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_all_devices"/>
<arg name="devices" type="ao" direction="out">
<tp:docstring>
List of object paths of network devices and device placeholders
(eg, devices that do not yet exist but which can be automatically
created by NetworkManager if one of their AvailableConnections
was activated).
</tp:docstring>
</arg>
</method>
......@@ -249,7 +265,18 @@
<property name="Devices" type="ao" access="read">
<tp:docstring>
The list of network devices/interfaces NetworkManager knows about.
The list of realized network devices. Realized devices are those which
have backing resources (eg from the kernel or a management daemon like
ModemManager, teamd, etc).
</tp:docstring>
</property>
<property name="AllDevices" type="ao" access="read">
<tp:docstring>
The list of both realized and un-realized network devices. Un-realized
devices are software devices which do not yet have backing resources,
but for which backing resources can be created if the device is
activated.
</tp:docstring>
</property>
......
......@@ -149,7 +149,9 @@ G_DEFINE_TYPE (NMManager, nm_manager, NM_TYPE_EXPORTED_OBJECT)
enum {
DEVICE_ADDED,
INTERNAL_DEVICE_ADDED,
DEVICE_REMOVED,
INTERNAL_DEVICE_REMOVED,
STATE_CHANGED,
CHECK_PERMISSIONS,
USER_PERMISSIONS_CHANGED,
......@@ -182,6 +184,7 @@ enum {
PROP_DEVICES,
PROP_METERED,
PROP_GLOBAL_DNS_CONFIGURATION,
PROP_ALL_DEVICES,
/* Not exported */
PROP_HOSTNAME,
......@@ -800,9 +803,13 @@ remove_device (NMManager *manager,
nm_settings_device_removed (priv->settings, device, quitting);
priv->devices = g_slist_remove (priv->devices, device);
g_signal_emit (manager, signals[DEVICE_REMOVED], 0, device);
g_object_notify (G_OBJECT (manager), NM_MANAGER_DEVICES);
nm_device_removed (device);
if (nm_device_is_real (device)) {
g_signal_emit (manager, signals[DEVICE_REMOVED], 0, device);
g_object_notify (G_OBJECT (manager), NM_MANAGER_DEVICES);
nm_device_removed (device);
}
g_signal_emit (manager, signals[INTERNAL_DEVICE_REMOVED], 0, device);
g_object_notify (G_OBJECT (manager), NM_MANAGER_ALL_DEVICES);
nm_exported_object_clear_and_unexport (&device);
......@@ -1673,6 +1680,10 @@ device_realized (NMDevice *device,
int ifindex;
gboolean assumed = FALSE;
/* Emit D-Bus signals */
g_signal_emit (self, signals[DEVICE_ADDED], 0, device);
g_object_notify (G_OBJECT (self), NM_MANAGER_DEVICES);
/* Loopback device never gets managed */
ifindex = nm_device_get_ifindex (device);
if (ifindex > 0 && nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) == NM_LINK_TYPE_LOOPBACK)
......@@ -1798,8 +1809,8 @@ add_device (NMManager *self, NMDevice *device)
nm_device_finish_init (device);
nm_settings_device_added (priv->settings, device);
g_signal_emit (self, signals[DEVICE_ADDED], 0, device);
g_object_notify (G_OBJECT (self), NM_MANAGER_DEVICES);
g_signal_emit (self, signals[INTERNAL_DEVICE_ADDED], 0, device);
g_object_notify (G_OBJECT (self), NM_MANAGER_ALL_DEVICES);
for (iter = priv->devices; iter; iter = iter->next) {
NMDevice *d = iter->data;
......@@ -2092,8 +2103,9 @@ nm_manager_get_best_device_for_connection (NMManager *self,
}
static void
impl_manager_get_devices (NMManager *self,
GDBusMethodInvocation *context)
_get_devices (NMManager *self,
GDBusMethodInvocation *context,
gboolean all_devices)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
gs_free const char **paths = NULL;
......@@ -2107,7 +2119,7 @@ impl_manager_get_devices (NMManager *self,
path = nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data));
if ( path
&& nm_device_is_real (iter->data))
&& (all_devices || nm_device_is_real (iter->data)))
paths[i++] = path;
}
paths[i++] = NULL;
......@@ -2116,6 +2128,20 @@ impl_manager_get_devices (NMManager *self,
g_variant_new ("(^ao)", (char **) paths));
}
static void
impl_manager_get_devices (NMManager *self,
GDBusMethodInvocation *context)
{
_get_devices (self, context, FALSE);
}
static void
impl_manager_get_all_devices (NMManager *self,
GDBusMethodInvocation *context)
{
_get_devices (self, context, TRUE);
}
static void
impl_manager_get_device_by_ip_iface (NMManager *self,
GDBusMethodInvocation *context,
......@@ -5183,6 +5209,9 @@ get_property (GObject *object, guint prop_id,
dns_config = nm_config_data_get_global_dns_config (config_data);
nm_global_dns_config_to_dbus (dns_config, value);
break;
case PROP_ALL_DEVICES:
nm_utils_g_value_set_object_path_array (value, priv->devices, NULL, NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -5510,7 +5539,23 @@ nm_manager_class_init (NMManagerClass *manager_class)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMManager:all-devices:
*
* All devices, including those that are not realized.
*
* Since: 1.2
**/
g_object_class_install_property
(object_class, PROP_ALL_DEVICES,
g_param_spec_boxed (NM_MANAGER_ALL_DEVICES, "", "",
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/* signals */
/* D-Bus exported; emitted only for realized devices */
signals[DEVICE_ADDED] =
g_signal_new ("device-added",
G_OBJECT_CLASS_TYPE (object_class),
......@@ -5519,6 +5564,15 @@ nm_manager_class_init (NMManagerClass *manager_class)
NULL, NULL, NULL,
G_TYPE_NONE, 1, NM_TYPE_DEVICE);
/* Emitted for both realized devices and placeholder devices */
signals[INTERNAL_DEVICE_ADDED] =
g_signal_new ("internal-device-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST, 0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
/* D-Bus exported; emitted only for realized devices */
signals[DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_OBJECT_CLASS_TYPE (object_class),
......@@ -5527,6 +5581,14 @@ nm_manager_class_init (NMManagerClass *manager_class)
NULL, NULL, NULL,
G_TYPE_NONE, 1, NM_TYPE_DEVICE);
/* Emitted for both realized devices and placeholder devices */
signals[INTERNAL_DEVICE_REMOVED] =
g_signal_new ("internal-device-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST, 0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
signals[STATE_CHANGED] =
g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (object_class),
......@@ -5573,6 +5635,7 @@ nm_manager_class_init (NMManagerClass *manager_class)
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class),
NMDBUS_TYPE_MANAGER_SKELETON,
"GetDevices", impl_manager_get_devices,
"GetAllDevices", impl_manager_get_all_devices,
"GetDeviceByIpIface", impl_manager_get_device_by_ip_iface,
"ActivateConnection", impl_manager_activate_connection,
"AddAndActivateConnection", impl_manager_add_and_activate_connection,
......
......@@ -50,6 +50,7 @@
#define NM_MANAGER_DEVICES "devices"
#define NM_MANAGER_METERED "metered"
#define NM_MANAGER_GLOBAL_DNS_CONFIGURATION "global-dns-configuration"
#define NM_MANAGER_ALL_DEVICES "all-devices"
/* Not exported */
#define NM_MANAGER_HOSTNAME "hostname"
......
......@@ -1779,8 +1779,8 @@ nm_policy_new (NMManager *manager, NMSettings *settings)
_connect_manager_signal (policy, "notify::" NM_MANAGER_HOSTNAME, hostname_changed);
_connect_manager_signal (policy, "notify::" NM_MANAGER_SLEEPING, sleeping_changed);
_connect_manager_signal (policy, "notify::" NM_MANAGER_NETWORKING_ENABLED, sleeping_changed);
_connect_manager_signal (policy, "device-added", device_added);
_connect_manager_signal (policy, "device-removed", device_removed);
_connect_manager_signal (policy, "internal-device-added", device_added);
_connect_manager_signal (policy, "internal-device-removed", device_removed);
_connect_manager_signal (policy, NM_MANAGER_ACTIVE_CONNECTION_ADDED, active_connection_added);
_connect_manager_signal (policy, NM_MANAGER_ACTIVE_CONNECTION_REMOVED, active_connection_removed);
......
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