summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-20 18:10:55 +0100
committerThomas Haller <thaller@redhat.com>2019-12-21 11:34:16 +0100
commitf411094d2e73ff81587c9348865e08b870f9c599 (patch)
tree18f9bc3cb6312844c926bf46876b62a2031d156e
parent785da51d83bf5b76835c457683bb2a4543386338 (diff)
downloadNetworkManager-th/capability-ovs-rh1785147.tar.gz
libnm: add nm_client_get_capabilities() to expose server Capabilitiesth/capability-ovs-rh1785147
I hesitated to add this to libnm, because it's hardly used. However, we already fetch the property during GetManagedObjects(), we we should make it accessible, instead of requiring the user to make another D-Bus call.
-rw-r--r--libnm/libnm.ver1
-rw-r--r--libnm/nm-client.c95
-rw-r--r--libnm/nm-client.h5
3 files changed, 100 insertions, 1 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index d2af078d8d..eaa7f30ed1 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1655,6 +1655,7 @@ global:
libnm_1_24_0 {
global:
+ nm_client_get_capabilities;
nm_client_get_instance_flags;
nm_client_get_permissions_state;
nm_client_instance_flags_get_type;
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index 1af3e319ca..02a5b002f5 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -223,6 +223,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMClient,
PROP_DNS_RC_MANAGER,
PROP_DNS_CONFIGURATION,
PROP_CHECKPOINTS,
+ PROP_CAPABILITIES,
PROP_PERMISSIONS_STATE,
);
@@ -308,6 +309,8 @@ typedef struct {
NMLDBusPropertyAO property_ao[_PROPERTY_AO_IDX_NM_NUM];
char *connectivity_check_uri;
char *version;
+ guint32 *capabilities_arr;
+ gsize capabilities_len;
guint32 connectivity;
guint32 state;
guint32 metered;
@@ -6092,6 +6095,64 @@ _notify_update_prop_dns_manager_configuration (NMClient *self,
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
+/**
+ * nm_client_get_capabilities:
+ * @client: the #NMClient instance
+ * @length: (out) (allow-none): the number of returned capabilities.
+ *
+ * Returns: (transfer none) (array length=length): the
+ * list of capabilities reported by the server or %NULL
+ * if the capabilities are unknown.
+ * The numeric values correspond to #NMCapability enum.
+ * The array is terminated by a numeric zero sentinel
+ * at position @length.
+ *
+ * Since: 1.24
+ */
+const guint32 *
+nm_client_get_capabilities (NMClient *client,
+ gsize *length)
+{
+ NMClientPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (length, NULL);
+
+ priv = NM_CLIENT_GET_PRIVATE (client);
+
+ NM_SET_OUT (length, priv->nm.capabilities_len);
+ return priv->nm.capabilities_arr;
+}
+
+static NMLDBusNotifyUpdatePropFlags
+_notify_update_prop_nm_capabilities (NMClient *self,
+ NMLDBusObject *dbobj,
+ const NMLDBusMetaIface *meta_iface,
+ guint dbus_property_idx,
+ GVariant *value)
+{
+ NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self);
+
+ nm_assert (G_OBJECT (self) == dbobj->nmobj);
+
+ nm_clear_g_free (&priv->nm.capabilities_arr);
+ priv->nm.capabilities_len = 0;
+
+ if (value) {
+ const guint32 *arr;
+ gsize len;
+
+ arr = g_variant_get_fixed_array (value, &len, sizeof (guint32));
+ priv->nm.capabilities_len = len;
+ priv->nm.capabilities_arr = g_new (guint32, len + 1);
+ if (len > 0)
+ memcpy (priv->nm.capabilities_arr, arr, len * sizeof (guint32));
+ priv->nm.capabilities_arr[len] = 0;
+ }
+
+ return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
+}
+
/*****************************************************************************/
/**
@@ -7084,6 +7145,20 @@ get_property (GObject *object, guint prop_id,
case PROP_CHECKPOINTS:
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_checkpoints (self)));
break;
+ case PROP_CAPABILITIES: {
+ const guint32 *arr;
+ GArray *out;
+ gsize len;
+
+ arr = nm_client_get_capabilities (self, &len);
+ if (arr) {
+ out = g_array_new (TRUE, FALSE, sizeof (guint32));
+ g_array_append_vals (out, arr, len);
+ } else
+ out = NULL;
+ g_value_take_boxed (value, out);
+ }
+ break;
case PROP_PERMISSIONS_STATE:
g_value_set_enum (value, priv->permissions_state);
break;
@@ -7497,6 +7572,9 @@ dispose (GObject *object)
g_clear_object (&priv->context_busy_watcher);
nm_clear_g_free (&priv->name_owner);
+
+ priv->nm.capabilities_len = 0;
+ nm_clear_g_free (&priv->nm.capabilities_arr);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_agentmanager = NML_DBUS_META_IFACE_INIT (
@@ -7513,7 +7591,7 @@ const NMLDBusMetaIface _nml_dbus_meta_iface_nm = NML_DBUS_META_IFACE_INIT_PROP (
NML_DBUS_META_PROPERTY_INIT_O_PROP ("ActivatingConnection", PROP_ACTIVATING_CONNECTION, NMClient, _priv.nm.property_o[PROPERTY_O_IDX_NM_ACTIVATING_CONNECTION], nm_active_connection_get_type ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("ActiveConnections", PROP_ACTIVE_CONNECTIONS, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_ACTIVE_CONNECTIONS], nm_active_connection_get_type, .notify_changed_ao = _property_ao_notify_changed_active_connections_cb ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("AllDevices", PROP_ALL_DEVICES, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_ALL_DEVICES], nm_device_get_type, .notify_changed_ao = _property_ao_notify_changed_all_devices_cb ),
- NML_DBUS_META_PROPERTY_INIT_IGNORE ("Capabilities", "au" ),
+ NML_DBUS_META_PROPERTY_INIT_FCN ("Capabilities", PROP_CAPABILITIES, "au", _notify_update_prop_nm_capabilities, ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Checkpoints", PROP_CHECKPOINTS, NMClient, _priv.nm.property_ao[PROPERTY_AO_IDX_CHECKPOINTS], nm_checkpoint_get_type ),
NML_DBUS_META_PROPERTY_INIT_U ("Connectivity", PROP_CONNECTIVITY, NMClient, _priv.nm.connectivity ),
NML_DBUS_META_PROPERTY_INIT_B ("ConnectivityCheckAvailable", PROP_CONNECTIVITY_CHECK_AVAILABLE, NMClient, _priv.nm.connectivity_check_available ),
@@ -7975,6 +8053,21 @@ nm_client_class_init (NMClientClass *client_class)
G_PARAM_STATIC_STRINGS);
/**
+ * NMClient:capabilities: (type GArray(guint32))
+ *
+ * The list of capabilities numbers as guint32 or %NULL if
+ * there are no capabitilies. The numeric value correspond
+ * to %NMCapability enum.
+ *
+ * Since: 1.24
+ */
+ obj_properties[PROP_CAPABILITIES] =
+ g_param_spec_boxed (NM_CLIENT_CAPABILITIES, "", "",
+ G_TYPE_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+
+ /**
* NMClient:permissions-state:
*
* The state of the cached permissions. The value %NM_TERNARY_DEFAULT
diff --git a/libnm/nm-client.h b/libnm/nm-client.h
index 37bac38b8b..e409fbc05b 100644
--- a/libnm/nm-client.h
+++ b/libnm/nm-client.h
@@ -81,6 +81,7 @@ _NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
#define NM_CLIENT_DNS_RC_MANAGER "dns-rc-manager"
#define NM_CLIENT_DNS_CONFIGURATION "dns-configuration"
#define NM_CLIENT_CHECKPOINTS "checkpoints"
+#define NM_CLIENT_CAPABILITIES "capabilities"
#define NM_CLIENT_PERMISSIONS_STATE "permissions-state"
#define NM_CLIENT_DEVICE_ADDED "device-added"
@@ -178,6 +179,10 @@ NMMetered nm_client_get_metered (NMClient *client);
gboolean nm_client_networking_get_enabled (NMClient *client);
+NM_AVAILABLE_IN_1_24
+const guint32 *nm_client_get_capabilities (NMClient *client,
+ gsize *length);
+
_NM_DEPRECATED_SYNC_METHOD
gboolean nm_client_networking_set_enabled (NMClient *client,
gboolean enabled,