diff options
author | Thomas Haller <thaller@redhat.com> | 2019-10-18 07:44:31 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-10-21 18:34:54 +0200 |
commit | 35b024acaa3a74fc7b8c2fbccd1a5708bfe5cfa8 (patch) | |
tree | 84f54b126e1baded460cf091dc16feec8c16de05 | |
parent | ba64c162dc471740a405f9d59e7a132f0e290078 (diff) | |
download | NetworkManager-35b024acaa3a74fc7b8c2fbccd1a5708bfe5cfa8.tar.gz |
libnm: hide NMClient struct from public headers and use direct private field
Having the NMClient/NMClientClass structs in the public header allows
the user to subclass these types. Subclassing this type was never
intended, nor is it supported, nor does it seem useful. Subclassing only
makes sense if the type has suitable hooks to extend the type in a
meaningful way. NMClient hasn't, and everybody trying to derive from
this class would better delegate the actions.
Also, having these structs in the public header prevents us from
embedding the private data in the object structure itself.
It has thus an runtime overhead and is less convenient for debugging (it's
hard to find the private data pointer in gdb).
Most importantly, there is no easy way to find the offset of the private
data fields, short of calling NM_CLIENT_GET_PRIVATE() -- which currently
is a macro. Later we want to generically lookup the offset of the
private data, we would need NM_CLIENT_GET_PRIVATE() as a function.
Instead, by having an internally, statically known offset, we can use
that offset instead.
Also drop all signal hooks. They are also not useful.
This is an ABI and API change, but of something that we never wanted to
be part of the ABI/API, and which hopefull nobody is using.
-rw-r--r-- | libnm/nm-client.c | 31 | ||||
-rw-r--r-- | libnm/nm-client.h | 22 |
2 files changed, 17 insertions, 36 deletions
diff --git a/libnm/nm-client.c b/libnm/nm-client.c index 9ad3a874d8..e2233ed770 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -149,12 +149,21 @@ typedef struct { bool udev_inited:1; } NMClientPrivate; +struct _NMClient { + GObject parent; + NMClientPrivate _priv; +}; + +struct _NMClientClass { + GObjectClass parent; +}; + G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_client_initable_iface_init); G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_client_async_initable_iface_init); ) -#define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate)) +#define NM_CLIENT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMClient, NM_IS_CLIENT) /*****************************************************************************/ @@ -3863,8 +3872,6 @@ nm_client_class_init (NMClientClass *client_class) { GObjectClass *object_class = G_OBJECT_CLASS (client_class); - g_type_class_add_private (client_class, sizeof (NMClientPrivate)); - object_class->get_property = get_property; object_class->set_property = set_property; object_class->constructed = constructed; @@ -4246,8 +4253,7 @@ nm_client_class_init (NMClientClass *client_class) g_signal_new (NM_CLIENT_DEVICE_ADDED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, device_added), - NULL, NULL, NULL, + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT); @@ -4263,8 +4269,7 @@ nm_client_class_init (NMClientClass *client_class) g_signal_new (NM_CLIENT_DEVICE_REMOVED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, device_removed), - NULL, NULL, NULL, + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT); @@ -4280,8 +4285,7 @@ nm_client_class_init (NMClientClass *client_class) g_signal_new (NM_CLIENT_ANY_DEVICE_ADDED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, any_device_added), - NULL, NULL, NULL, + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT); @@ -4297,8 +4301,7 @@ nm_client_class_init (NMClientClass *client_class) g_signal_new (NM_CLIENT_ANY_DEVICE_REMOVED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, any_device_removed), - NULL, NULL, NULL, + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_OBJECT); @@ -4327,8 +4330,7 @@ nm_client_class_init (NMClientClass *client_class) g_signal_new (NM_CLIENT_CONNECTION_ADDED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, connection_added), - NULL, NULL, NULL, + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, NM_TYPE_REMOTE_CONNECTION); @@ -4343,8 +4345,7 @@ nm_client_class_init (NMClientClass *client_class) g_signal_new (NM_CLIENT_CONNECTION_REMOVED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMClientClass, connection_removed), - NULL, NULL, NULL, + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, NM_TYPE_REMOTE_CONNECTION); diff --git a/libnm/nm-client.h b/libnm/nm-client.h index 744b564d7f..2a45342ed5 100644 --- a/libnm/nm-client.h +++ b/libnm/nm-client.h @@ -199,27 +199,7 @@ gboolean nm_dns_entry_get_vpn (NMDnsEntry *entry); /** * NMClient: */ -struct _NMClient { - GObject parent; -}; - -typedef struct { - GObjectClass parent; - - /* Signals */ - void (*device_added) (NMClient *client, NMDevice *device); - void (*device_removed) (NMClient *client, NMDevice *device); - void (*any_device_added) (NMClient *client, NMDevice *device); - void (*any_device_removed) (NMClient *client, NMDevice *device); - void (*permission_changed) (NMClient *client, - NMClientPermission permission, - NMClientPermissionResult result); - void (*connection_added) (NMClient *client, NMRemoteConnection *connection); - void (*connection_removed) (NMClient *client, NMRemoteConnection *connection); - - /*< private >*/ - gpointer padding[6]; -} NMClientClass; +typedef struct _NMClientClass NMClientClass; GType nm_client_get_type (void); |