dns: drop get_name() and is_caching() virtual functions for klass variables

The plugin name and whether a plugin is caching only depends on the type,
it does not require a virtual function where types would decided depending
on other reasons.

Convert the virtual functions into fields of the class.
This commit is contained in:
Thomas Haller 2019-08-31 09:09:37 +02:00
parent 5bf2112056
commit 807fd682fb
5 changed files with 29 additions and 76 deletions

View file

@ -425,20 +425,6 @@ child_quit (NMDnsPlugin *plugin, int status)
/*****************************************************************************/ /*****************************************************************************/
static gboolean
is_caching (NMDnsPlugin *plugin)
{
return TRUE;
}
static const char *
get_name (NMDnsPlugin *plugin)
{
return "dnsmasq";
}
/*****************************************************************************/
static void static void
nm_dns_dnsmasq_init (NMDnsDnsmasq *self) nm_dns_dnsmasq_init (NMDnsDnsmasq *self)
{ {
@ -473,8 +459,8 @@ nm_dns_dnsmasq_class_init (NMDnsDnsmasqClass *dns_class)
object_class->dispose = dispose; object_class->dispose = dispose;
plugin_class->child_quit = child_quit; plugin_class->plugin_name = "dnsmasq";
plugin_class->is_caching = is_caching; plugin_class->is_caching = TRUE;
plugin_class->update = update; plugin_class->child_quit = child_quit;
plugin_class->get_name = get_name; plugin_class->update = update;
} }

View file

@ -74,23 +74,22 @@ nm_dns_plugin_update (NMDnsPlugin *self,
hostname); hostname);
} }
static gboolean
is_caching (NMDnsPlugin *self)
{
return FALSE;
}
gboolean gboolean
nm_dns_plugin_is_caching (NMDnsPlugin *self) nm_dns_plugin_is_caching (NMDnsPlugin *self)
{ {
return NM_DNS_PLUGIN_GET_CLASS (self)->is_caching (self); return NM_DNS_PLUGIN_GET_CLASS (self)->is_caching;
} }
const char * const char *
nm_dns_plugin_get_name (NMDnsPlugin *self) nm_dns_plugin_get_name (NMDnsPlugin *self)
{ {
g_assert (NM_DNS_PLUGIN_GET_CLASS (self)->get_name); NMDnsPluginClass *klass;
return NM_DNS_PLUGIN_GET_CLASS (self)->get_name (self);
g_return_val_if_fail (NM_IS_DNS_PLUGIN (self), NULL);
klass = NM_DNS_PLUGIN_GET_CLASS (self);
nm_assert (klass->plugin_name);
return klass->plugin_name;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -275,8 +274,6 @@ nm_dns_plugin_class_init (NMDnsPluginClass *plugin_class)
object_class->dispose = dispose; object_class->dispose = dispose;
plugin_class->is_caching = is_caching;
/* Emitted by the plugin and consumed by NMDnsManager when /* Emitted by the plugin and consumed by NMDnsManager when
* some error happens with the nameserver subprocess. Causes NM to fall * some error happens with the nameserver subprocess. Causes NM to fall
* back to writing out a non-local-caching resolv.conf until the next * back to writing out a non-local-caching resolv.conf until the next

View file

@ -2,8 +2,8 @@
/* Copyright (C) 2010 Red Hat, Inc. /* Copyright (C) 2010 Red Hat, Inc.
*/ */
#ifndef __NETWORKMANAGER_DNS_PLUGIN_H__ #ifndef __NM_DNS_PLUGIN_H__
#define __NETWORKMANAGER_DNS_PLUGIN_H__ #define __NM_DNS_PLUGIN_H__
#include "nm-dns-manager.h" #include "nm-dns-manager.h"
#include "nm-config-data.h" #include "nm-config-data.h"
@ -28,8 +28,6 @@ typedef struct {
typedef struct { typedef struct {
GObjectClass parent; GObjectClass parent;
/* Methods */
/* Called when DNS information is changed. 'configs' is an array /* Called when DNS information is changed. 'configs' is an array
* of pointers to NMDnsIPConfigData sorted by priority. * of pointers to NMDnsIPConfigData sorted by priority.
* 'global_config' is the optional global DNS * 'global_config' is the optional global DNS
@ -40,16 +38,7 @@ typedef struct {
const CList *ip_config_lst_head, const CList *ip_config_lst_head,
const char *hostname); const char *hostname);
/* Subclasses should override and return TRUE if they start a local const char *plugin_name;
* caching nameserver that listens on localhost and would block any
* other local caching nameserver from operating.
*/
gboolean (*is_caching) (NMDnsPlugin *self);
/* Subclasses should override this and return their plugin name */
const char *(*get_name) (NMDnsPlugin *self);
/* Signals */
/* Emitted by the plugin base class when the nameserver subprocess /* Emitted by the plugin base class when the nameserver subprocess
* quits. This signal is consumed by the plugin subclasses and not * quits. This signal is consumed by the plugin subclasses and not
@ -57,6 +46,13 @@ typedef struct {
* by waitpid(2)) is fatal it should then emit the 'failed' signal. * by waitpid(2)) is fatal it should then emit the 'failed' signal.
*/ */
void (*child_quit) (NMDnsPlugin *self, int status); void (*child_quit) (NMDnsPlugin *self, int status);
/* Types should set to TRUE if they start a local caching nameserver
* that listens on localhost and would block any other local caching
* nameserver from operating.
*/
bool is_caching:1;
} NMDnsPluginClass; } NMDnsPluginClass;
GType nm_dns_plugin_get_type (void); GType nm_dns_plugin_get_type (void);
@ -89,4 +85,4 @@ GPid nm_dns_plugin_child_pid (NMDnsPlugin *self);
gboolean nm_dns_plugin_child_kill (NMDnsPlugin *self); gboolean nm_dns_plugin_child_kill (NMDnsPlugin *self);
#endif /* __NETWORKMANAGER_DNS_PLUGIN_H__ */ #endif /* __NM_DNS_PLUGIN_H__ */

View file

@ -388,20 +388,6 @@ update (NMDnsPlugin *plugin,
/*****************************************************************************/ /*****************************************************************************/
static gboolean
is_caching (NMDnsPlugin *plugin)
{
return TRUE;
}
static const char *
get_name (NMDnsPlugin *plugin)
{
return "systemd-resolved";
}
/*****************************************************************************/
static void static void
name_owner_changed (NMDnsSystemdResolved *self, name_owner_changed (NMDnsSystemdResolved *self,
const char *owner) const char *owner)
@ -553,7 +539,7 @@ nm_dns_systemd_resolved_class_init (NMDnsSystemdResolvedClass *dns_class)
object_class->dispose = dispose; object_class->dispose = dispose;
plugin_class->is_caching = is_caching; plugin_class->plugin_name = "systemd-resolved";
plugin_class->update = update; plugin_class->is_caching = TRUE;
plugin_class->get_name = get_name; plugin_class->update = update;
} }

View file

@ -46,18 +46,6 @@ update (NMDnsPlugin *plugin,
return (status == 0); return (status == 0);
} }
static gboolean
is_caching (NMDnsPlugin *plugin)
{
return TRUE;
}
static const char *
get_name (NMDnsPlugin *plugin)
{
return "unbound";
}
/*****************************************************************************/ /*****************************************************************************/
static void static void
@ -76,7 +64,7 @@ nm_dns_unbound_class_init (NMDnsUnboundClass *klass)
{ {
NMDnsPluginClass *plugin_class = NM_DNS_PLUGIN_CLASS (klass); NMDnsPluginClass *plugin_class = NM_DNS_PLUGIN_CLASS (klass);
plugin_class->update = update; plugin_class->plugin_name = "unbound";
plugin_class->is_caching = is_caching; plugin_class->is_caching = TRUE;
plugin_class->get_name = get_name; plugin_class->update = update;
} }