core: don't pass config data to NMDHCPManager and NMDnsManager

Rather than passing specific bits of data to NMDHCPManager and
NMDnsManager, just let them call nm_config_get() and then get the data
themselves.

Also, remove the GError argument from nm_dhcp_manager_new(), since the
function never returned NULL. This in turn means there is no longer
any need for a distinction between nm_dhcp_manager_new() and
nm_dhcp_manager_get(), so remove the former.
This commit is contained in:
Dan Winship 2013-03-12 14:01:43 -04:00
parent 0b815ca166
commit 213a3a4d2e
8 changed files with 27 additions and 22 deletions

View file

@ -7,6 +7,7 @@ INCLUDES = \
-I${top_builddir}/src/generated \
-I${top_srcdir}/src/generated \
-I${top_srcdir}/src/logging \
-I${top_srcdir}/src/config \
-I${top_srcdir}/src/posix-signals \
-I${top_builddir}/libnm-util \
-I${top_srcdir}/libnm-util \
@ -61,6 +62,7 @@ libdhcp_manager_la_CPPFLAGS = \
libdhcp_manager_la_LIBADD = \
$(top_builddir)/src/logging/libnm-logging.la \
$(top_builddir)/src/config/libnm-config.la \
$(top_builddir)/src/posix-signals/libnm-posix-signals.la \
$(builddir)/libdhcp-dhclient.la \
$(DBUS_LIBS) \

View file

@ -41,6 +41,7 @@
#include "nm-logging.h"
#include "nm-dbus-manager.h"
#include "nm-hostname-provider.h"
#include "nm-config.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
@ -293,24 +294,30 @@ get_client_type (const char *client, GError **error)
}
NMDHCPManager *
nm_dhcp_manager_new (const char *client, GError **error)
nm_dhcp_manager_get (void)
{
NMDHCPManagerPrivate *priv;
DBusGConnection *g_connection;
const char *client;
GError *error = NULL;
g_warn_if_fail (singleton == NULL);
if (singleton)
return g_object_ref (singleton);
singleton = g_object_new (NM_TYPE_DHCP_MANAGER, NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE (singleton);
/* Client-specific setup */
priv->client_type = get_client_type (client, error);
client = nm_config_get_dhcp_client (nm_config_get ());
priv->client_type = get_client_type (client, &error);
if (priv->client_type == NM_TYPE_DHCP_DHCLIENT)
priv->get_lease_config_func = nm_dhcp_dhclient_get_lease_config;
else if (priv->client_type == NM_TYPE_DHCP_DHCPCD)
priv->get_lease_config_func = nm_dhcp_dhcpcd_get_lease_config;
else {
nm_log_warn (LOGD_DHCP, "No usable DHCP client found! DHCP configurations will fail.");
nm_log_warn (LOGD_DHCP, "No usable DHCP client found (%s)! DHCP configurations will fail.",
error->message);
g_error_free (error);
}
priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal,
@ -590,13 +597,6 @@ nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client,
/***************************************************/
NMDHCPManager *
nm_dhcp_manager_get (void)
{
g_warn_if_fail (singleton != NULL);
return g_object_ref (singleton);
}
static void
nm_dhcp_manager_init (NMDHCPManager *manager)
{

View file

@ -93,7 +93,4 @@ NMIP4Config *nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client
GHashTable *options,
const char *reason);
/* Only for main.c */
NMDHCPManager *nm_dhcp_manager_new (const char *client, GError **error);
#endif /* NM_DHCP_MANAGER_H */

View file

@ -1,5 +1,6 @@
INCLUDES = \
-I${top_srcdir}/src/logging \
-I${top_srcdir}/src/config \
-I${top_srcdir}/src/posix-signals \
-I${top_srcdir}/libnm-util \
-I${top_builddir}/libnm-util \
@ -30,6 +31,7 @@ libdns_manager_la_CPPFLAGS = \
libdns_manager_la_LIBADD = \
$(top_builddir)/src/logging/libnm-logging.la \
$(top_builddir)/src/config/libnm-config.la \
$(top_builddir)/src/posix-signals/libnm-posix-signals.la \
$(LIBNL_LIBS) \
$(DBUS_LIBS) \

View file

@ -42,6 +42,7 @@
#include "nm-logging.h"
#include "NetworkManagerUtils.h"
#include "nm-posix-signals.h"
#include "nm-config.h"
#include "nm-dns-plugin.h"
#include "nm-dns-dnsmasq.h"
@ -1076,13 +1077,16 @@ load_plugins (NMDnsManager *self, const char **plugins)
/******************************************************************/
NMDnsManager *
nm_dns_manager_get (const char **plugins)
nm_dns_manager_get (void)
{
static NMDnsManager * singleton = NULL;
const char **plugins;
if (!singleton) {
singleton = NM_DNS_MANAGER (g_object_new (NM_TYPE_DNS_MANAGER, NULL));
g_assert (singleton);
plugins = nm_config_get_dns_plugins (nm_config_get ());
load_plugins (singleton, plugins);
} else
g_object_ref (singleton);

View file

@ -67,7 +67,7 @@ typedef struct {
GType nm_dns_manager_get_type (void);
NMDnsManager * nm_dns_manager_get (const char **plugins);
NMDnsManager * nm_dns_manager_get (void);
/* Allow changes to be batched together */
void nm_dns_manager_begin_updates (NMDnsManager *mgr, const char *func);

View file

@ -493,7 +493,7 @@ main (int argc, char *argv[])
goto done;
}
dns_mgr = nm_dns_manager_get (nm_config_get_dns_plugins (config));
dns_mgr = nm_dns_manager_get ();
if (!dns_mgr) {
nm_log_err (LOGD_CORE, "failed to start the DNS manager.");
goto done;
@ -535,7 +535,7 @@ main (int argc, char *argv[])
}
/* Initialize DHCP manager */
dhcp_mgr = nm_dhcp_manager_new (nm_config_get_dhcp_client (config), &error);
dhcp_mgr = nm_dhcp_manager_get ();
if (!dhcp_mgr) {
nm_log_err (LOGD_CORE, "failed to start the DHCP manager: %s.", error->message);
goto done;

View file

@ -852,7 +852,7 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update)
{
NMDnsManager *mgr;
mgr = nm_dns_manager_get (NULL);
mgr = nm_dns_manager_get ();
nm_dns_manager_begin_updates (mgr, __func__);
update_ip4_dns (policy, mgr);
@ -1609,7 +1609,7 @@ vpn_connection_activated (NMPolicy *policy, NMVPNConnection *vpn)
NMIP6Config *ip6_config;
const char *ip_iface;
mgr = nm_dns_manager_get (NULL);
mgr = nm_dns_manager_get ();
nm_dns_manager_begin_updates (mgr, __func__);
ip_iface = nm_vpn_connection_get_ip_iface (vpn);
@ -1640,7 +1640,7 @@ vpn_connection_deactivated (NMPolicy *policy, NMVPNConnection *vpn)
const char *ip_iface;
NMDevice *parent;
mgr = nm_dns_manager_get (NULL);
mgr = nm_dns_manager_get ();
nm_dns_manager_begin_updates (mgr, __func__);
ip_iface = nm_vpn_connection_get_ip_iface (vpn);
@ -1987,7 +1987,7 @@ nm_policy_new (NMManager *manager, NMSettings *settings)
G_CALLBACK (firewall_started), policy);
policy->fw_started_id = id;
policy->dns_manager = nm_dns_manager_get (NULL);
policy->dns_manager = nm_dns_manager_get ();
policy->config_changed_id = g_signal_connect (policy->dns_manager, "config-changed",
G_CALLBACK (dns_config_changed), policy);