dhcp: minor cleanup of accept/decline functions in "nm-dhcp-client.c"
- assign the result of NM_DHCP_CLIENT_GET_CLASS() to a local variable. It feels nicer to only call the macro once. Of course, the macro expands to plain pointer dereferences, so there is little difference in terms of executed code. - handle the default case with no virtual function first.
This commit is contained in:
@@ -486,32 +486,34 @@ nm_dhcp_client_stop_watch_child(NMDhcpClient *self, pid_t pid)
|
||||
static gboolean
|
||||
_dhcp_client_accept(NMDhcpClient *self, const NML3ConfigData *l3cd, GError **error)
|
||||
{
|
||||
NMDhcpClientPrivate *priv;
|
||||
NMDhcpClientClass *klass;
|
||||
|
||||
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
|
||||
nm_assert(l3cd);
|
||||
|
||||
priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
|
||||
klass = NM_DHCP_CLIENT_GET_CLASS(self);
|
||||
|
||||
g_return_val_if_fail(priv->l3cd, FALSE);
|
||||
g_return_val_if_fail(NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd, FALSE);
|
||||
|
||||
if (NM_DHCP_CLIENT_GET_CLASS(self)->accept) {
|
||||
return NM_DHCP_CLIENT_GET_CLASS(self)->accept(self, l3cd, error);
|
||||
}
|
||||
if (!klass->accept)
|
||||
return TRUE;
|
||||
|
||||
return TRUE;
|
||||
return klass->accept(self, l3cd, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_dhcp_client_can_accept(NMDhcpClient *self)
|
||||
{
|
||||
gboolean can_accept;
|
||||
NMDhcpClientClass *klass;
|
||||
|
||||
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
|
||||
nm_assert(NM_IS_DHCP_CLIENT(self));
|
||||
|
||||
can_accept = !!(NM_DHCP_CLIENT_GET_CLASS(self)->accept);
|
||||
klass = NM_DHCP_CLIENT_GET_CLASS(self);
|
||||
|
||||
nm_assert(can_accept == (!!(NM_DHCP_CLIENT_GET_CLASS(self)->decline)));
|
||||
can_accept = !!klass->accept;
|
||||
|
||||
nm_assert(can_accept == (!!klass->decline));
|
||||
|
||||
return can_accept;
|
||||
}
|
||||
@@ -522,20 +524,19 @@ _dhcp_client_decline(NMDhcpClient *self,
|
||||
const char *error_message,
|
||||
GError **error)
|
||||
{
|
||||
NMDhcpClientPrivate *priv;
|
||||
NMDhcpClientClass *klass;
|
||||
|
||||
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
|
||||
nm_assert(l3cd);
|
||||
|
||||
priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
|
||||
klass = NM_DHCP_CLIENT_GET_CLASS(self);
|
||||
|
||||
g_return_val_if_fail(priv->l3cd, FALSE);
|
||||
g_return_val_if_fail(NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd, FALSE);
|
||||
|
||||
if (NM_DHCP_CLIENT_GET_CLASS(self)->decline) {
|
||||
return NM_DHCP_CLIENT_GET_CLASS(self)->decline(self, l3cd, error_message, error);
|
||||
}
|
||||
if (!klass->decline)
|
||||
return TRUE;
|
||||
|
||||
return TRUE;
|
||||
return klass->decline(self, l3cd, error_message, error);
|
||||
}
|
||||
|
||||
static GBytes *
|
||||
|
Reference in New Issue
Block a user