diff options
author | Thomas Haller <thaller@redhat.com> | 2016-07-06 11:45:02 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-07-08 12:08:02 +0200 |
commit | 7ab03097fc904f31d4c1f2f6854d99815b6e7c48 (patch) | |
tree | 4fe91641357651a75f933c2f02f11899b6ea5f60 | |
parent | 5fa835baee76e5dc661b66f30c5ca954a80e86d5 (diff) | |
download | NetworkManager-7ab03097fc904f31d4c1f2f6854d99815b6e7c48.tar.gz |
rdisc: embed pointer to private data in NMRDisc
NMRDisc is one of the more heavily used classes. Let's clean it up
a bit.
-rw-r--r-- | src/rdisc/nm-rdisc.c | 46 | ||||
-rw-r--r-- | src/rdisc/nm-rdisc.h | 4 |
2 files changed, 37 insertions, 13 deletions
diff --git a/src/rdisc/nm-rdisc.c b/src/rdisc/nm-rdisc.c index c11557d943..3263edc6b8 100644 --- a/src/rdisc/nm-rdisc.c +++ b/src/rdisc/nm-rdisc.c @@ -20,33 +20,33 @@ #include "nm-default.h" +#include "nm-rdisc.h" + #include <stdlib.h> #include <arpa/inet.h> #include <string.h> -#include "nm-rdisc.h" -#include "nm-rdisc-private.h" +#include "nm-setting-ip6-config.h" +#include "nm-rdisc-private.h" #include "nm-utils.h" #include "nm-platform.h" #include "nmp-netns.h" -#include <nm-setting-ip6-config.h> - #define _NMLOG_PREFIX_NAME "rdisc" -typedef struct { +/*****************************************************************************/ + +struct _NMRDiscPrivate { int solicitations_left; guint send_rs_id; gint64 last_rs; guint ra_timeout_id; /* first RA timeout */ guint timeout_id; /* prefix/dns/etc lifetime timeout */ char *last_send_rs_error; -} NMRDiscPrivate; - -#define NM_RDISC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_RDISC, NMRDiscPrivate)) +}; -G_DEFINE_TYPE (NMRDisc, nm_rdisc, G_TYPE_OBJECT) +typedef struct _NMRDiscPrivate NMRDiscPrivate; NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_PLATFORM, @@ -60,7 +60,22 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; -/******************************************************************/ +G_DEFINE_TYPE (NMRDisc, nm_rdisc, G_TYPE_OBJECT) + +#define NM_RDISC_GET_PRIVATE(self) \ + ({ \ + /* preserve the const-ness of self. Unfortunately, that + * way, @self cannot be a void pointer */ \ + typeof (self) _self = (self); \ + \ + /* Get compiler error if variable is of wrong type */ \ + _nm_unused const NMRDisc *_self2 = (_self); \ + \ + nm_assert (NM_IS_RDISC (_self)); \ + _self->_priv; \ + }) + +/*****************************************************************************/ NMPNetns * nm_rdisc_netns_get (NMRDisc *self) @@ -687,8 +702,10 @@ check_timestamps (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed) static gboolean timeout_cb (gpointer user_data) { - NM_RDISC_GET_PRIVATE (user_data)->timeout_id = 0; - check_timestamps (NM_RDISC (user_data), nm_utils_get_monotonic_timestamp_s (), 0); + NMRDisc *self = user_data; + + NM_RDISC_GET_PRIVATE (self)->timeout_id = 0; + check_timestamps (self, nm_utils_get_monotonic_timestamp_s (), 0); return G_SOURCE_REMOVE; } @@ -741,7 +758,10 @@ set_property (GObject *object, guint prop_id, static void nm_rdisc_init (NMRDisc *rdisc) { - NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc); + NMRDiscPrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (rdisc, NM_TYPE_RDISC, NMRDiscPrivate); + rdisc->_priv = priv; rdisc->gateways = g_array_new (FALSE, FALSE, sizeof (NMRDiscGateway)); rdisc->addresses = g_array_new (FALSE, FALSE, sizeof (NMRDiscAddress)); diff --git a/src/rdisc/nm-rdisc.h b/src/rdisc/nm-rdisc.h index 8c14576bcb..3eb73b7357 100644 --- a/src/rdisc/nm-rdisc.h +++ b/src/rdisc/nm-rdisc.h @@ -103,6 +103,8 @@ typedef enum { #define NM_RDISC_RTR_SOLICITATIONS_DEFAULT 3 #define NM_RDISC_RTR_SOLICITATION_INTERVAL_DEFAULT 4 +struct _NMRDiscPrivate; + /** * NMRDisc: * @ifindex: Interface index @@ -113,6 +115,8 @@ typedef enum { typedef struct { GObject parent; + struct _NMRDiscPrivate *_priv; + NMPlatform *_platform; NMPNetns *_netns; |