diff options
author | Thomas Haller <thaller@redhat.com> | 2019-12-05 18:17:43 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-12-10 07:53:25 +0100 |
commit | f7aeda03901dbda40697f588b4a6129160c5dc1e (patch) | |
tree | 9f976b874821d2e0fa8aae4fc7644b8aff1f0293 | |
parent | 51bc2c02242ead7659c417cfa2336a231ac4ea24 (diff) | |
download | NetworkManager-f7aeda03901dbda40697f588b4a6129160c5dc1e.tar.gz |
libnm: add NMClient:instance-flags property
Add a flags property to control behavior of NMClient.
Possible future use cases:
- currently it would always automatically fetch permissions. Often that
is not used and the user could opt out of it.
- currently, using sync init creates an internal GMainContext. This
has an overhead and may be undesirable. We could implement another
"sync" initialization that would merely iterate the callers mainloop
until the initialization completes. A flag would allow to opt in.
- currently, NMClient always fetches all connection settings
automatically. Via a flag the user could opt out of that.
Instead NMClient could provide an API so the user can request
settings as they are needed.
-rw-r--r-- | libnm/libnm.ver | 6 | ||||
-rw-r--r-- | libnm/nm-client.c | 62 | ||||
-rw-r--r-- | libnm/nm-client.h | 15 | ||||
-rw-r--r-- | libnm/nm-libnm-utils.h | 2 |
4 files changed, 85 insertions, 0 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver index fb5a4f64df..ffd6e3dbd5 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1652,3 +1652,9 @@ global: nm_setting_gsm_get_auto_config; nm_setting_ip_config_get_dhcp_hostname_flags; } libnm_1_20_0; + +libnm_1_24_0 { +global: + nm_client_get_instance_flags; + nm_client_instance_flags_get_type; +} libnm_1_22_0; diff --git a/libnm/nm-client.c b/libnm/nm-client.c index b10456e274..6b2844a0d7 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -195,6 +195,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMClient, PROP_DBUS_CONNECTION, PROP_DBUS_NAME_OWNER, PROP_VERSION, + PROP_INSTANCE_FLAGS, PROP_STATE, PROP_STARTUP, PROP_NM_RUNNING, @@ -290,6 +291,10 @@ typedef struct { guint dbsid_nm_vpn_connection_state_changed; guint dbsid_nm_check_permissions; + NMClientInstanceFlags instance_flags:3; + + bool instance_flags_constructed:1; + bool udev_inited:1; bool notify_event_lst_changed:1; bool check_dbobj_visible_all:1; @@ -3751,6 +3756,22 @@ _request_wait_finish (NMClient *client, /*****************************************************************************/ /** + * nm_client_get_instance_flags: + * @self: the #NMClient instance. + * + * Returns: the #NMClientInstanceFlags flags. + * + * Since: 1.24 + */ +NMClientInstanceFlags +nm_client_get_instance_flags (NMClient *self) +{ + g_return_val_if_fail (NM_IS_CLIENT (self), NM_CLIENT_INSTANCE_FLAGS_NONE); + + return NM_CLIENT_GET_PRIVATE (self)->instance_flags; +} + +/** * nm_client_get_dbus_connection: * @client: a #NMClient * @@ -6929,6 +6950,9 @@ get_property (GObject *object, guint prop_id, NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object); switch (prop_id) { + case PROP_INSTANCE_FLAGS: + g_value_set_uint (value, priv->instance_flags); + break; case PROP_DBUS_CONNECTION: g_value_set_object (value, priv->dbus_connection); break; @@ -7041,8 +7065,27 @@ set_property (GObject *object, guint prop_id, NMClient *self = NM_CLIENT (object); NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (self); gboolean b; + guint v_uint; switch (prop_id) { + + case PROP_INSTANCE_FLAGS: + /* construct */ + + v_uint = g_value_get_uint (value); + g_return_if_fail (!NM_FLAGS_ANY (v_uint, ~((guint) NM_CLIENT_INSTANCE_FLAGS_ALL))); + v_uint &= ((guint) NM_CLIENT_INSTANCE_FLAGS_ALL); + + if (!priv->instance_flags_constructed) { + priv->instance_flags_constructed = TRUE; + priv->instance_flags = v_uint; + nm_assert ((guint) priv->instance_flags == v_uint); + } else { + /* Later, we may want to implement setting some flags not only at construct time. + * For now, that is not implemented and resetting flags afterwards has no effect. */ + } + break; + case PROP_DBUS_CONNECTION: /* construct-only */ priv->dbus_connection = g_value_dup_object (value); @@ -7476,6 +7519,25 @@ nm_client_class_init (NMClientClass *client_class) G_PARAM_STATIC_STRINGS); /** + * NMClient:instance-flags: + * + * #NMClientInstanceFlags for the instance. These affect behavior of #NMClient. + * This is a construct property and you may only set the flags during + * construction. + * + * Since: 1.24 + */ + obj_properties[PROP_INSTANCE_FLAGS] = + g_param_spec_uint (NM_CLIENT_INSTANCE_FLAGS, "", "", + 0, + G_MAXUINT32, + 0, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS); + + /** * NMClient:dbus-name-owner: * * The name owner of the NetworkManager D-Bus service. diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 6bff58684e..4dc1a16791 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -15,6 +15,16 @@ G_BEGIN_DECLS +/** + * NMClientInstanceFlags: + * @NM_CLIENT_INSTANCE_FLAGS_NONE: special value to indicate no flags. + * + * Since: 1.24 + */ +typedef enum { /*< flags >*/ + NM_CLIENT_INSTANCE_FLAGS_NONE = 0, +} NMClientInstanceFlags; + #define NM_TYPE_CLIENT (nm_client_get_type ()) #define NM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CLIENT, NMClient)) #define NM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CLIENT, NMClientClass)) @@ -28,6 +38,7 @@ G_BEGIN_DECLS #define NM_CLIENT_NM_RUNNING "nm-running" #define NM_CLIENT_DBUS_CONNECTION "dbus-connection" #define NM_CLIENT_DBUS_NAME_OWNER "dbus-name-owner" +#define NM_CLIENT_INSTANCE_FLAGS "instance-flags" _NM_DEPRECATED_SYNC_WRITABLE_PROPERTY #define NM_CLIENT_NETWORKING_ENABLED "networking-enabled" @@ -133,6 +144,10 @@ void nm_client_new_async (GCancellable *cancellable, NMClient *nm_client_new_finish (GAsyncResult *result, GError **error); + +NM_AVAILABLE_IN_1_24 +NMClientInstanceFlags nm_client_get_instance_flags (NMClient *self); + NM_AVAILABLE_IN_1_22 GDBusConnection *nm_client_get_dbus_connection (NMClient *client); diff --git a/libnm/nm-libnm-utils.h b/libnm/nm-libnm-utils.h index 304c35f4be..5dea53c682 100644 --- a/libnm/nm-libnm-utils.h +++ b/libnm/nm-libnm-utils.h @@ -166,6 +166,8 @@ typedef enum { /*****************************************************************************/ +#define NM_CLIENT_INSTANCE_FLAGS_ALL ((NMClientInstanceFlags) 0x0) + typedef struct { GType (*get_o_type_fcn) (void); |