core: build NMConnectivity unconditionally, possibly as a no-op

Build and use NMConnectivity regardless of build options; if you build
without libsoup, NMConnectivity will just always report that you have
full connectivity (like it does when you build with libsoup but don't
enable connectivity checking).
This commit is contained in:
Dan Winship 2013-07-29 16:36:00 -04:00
parent 6885da2648
commit 91f810abfe
3 changed files with 26 additions and 29 deletions

View file

@ -222,6 +222,8 @@ nm_sources = \
nm-atm-manager.h \
nm-connection-provider.c \
nm-connection-provider.h \
nm-connectivity.c \
nm-connectivity.h \
nm-dbus-manager.c \
nm-dbus-manager.h \
nm-dhcp4-config.c \
@ -264,10 +266,6 @@ nm_sources = \
NetworkManagerUtils.c \
NetworkManagerUtils.h
if WITH_CONCHECK
nm_sources += nm-connectivity.c nm-connectivity.h
endif
if WITH_MODEM_MANAGER_1
nm_sources += \
modem-manager/nm-modem-broadband.c \

View file

@ -22,7 +22,9 @@
#include <config.h>
#include <string.h>
#if WITH_CONCHECK
#include <libsoup/soup.h>
#endif
#include "nm-connectivity.h"
#include "nm-logging.h"
@ -40,9 +42,11 @@ typedef struct {
char *response;
guint interval;
#if WITH_CONCHECK
SoupSession *soup_session;
gboolean running;
guint check_id;
#endif
gboolean connected;
} NMConnectivityPrivate;
@ -71,16 +75,21 @@ update_connected (NMConnectivity *self, gboolean connected)
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
gboolean old_connected = priv->connected;
#if WITH_CONCHECK
if (priv->uri == NULL || priv->interval == 0) {
/* Default to connected if no checks are to be run */
priv->connected = TRUE;
} else
priv->connected = connected;
#else
priv->connected = TRUE;
#endif
if (priv->connected != old_connected)
g_object_notify (G_OBJECT (self), NM_CONNECTIVITY_CONNECTED);
}
#if WITH_CONCHECK
static void
nm_connectivity_check_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
{
@ -135,10 +144,12 @@ run_check (gpointer user_data)
nm_log_dbg (LOGD_CORE, "Connectivity check with uri '%s' started.", priv->uri);
return TRUE;
}
#endif
void
nm_connectivity_start_check (NMConnectivity *self)
{
#if WITH_CONCHECK
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
if (!priv->uri || !priv->interval) {
@ -151,11 +162,13 @@ nm_connectivity_start_check (NMConnectivity *self)
if (priv->running == FALSE)
run_check (self);
#endif
}
void
nm_connectivity_stop_check (NMConnectivity *self)
{
#if WITH_CONCHECK
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
if (priv->check_id) {
@ -164,6 +177,7 @@ nm_connectivity_stop_check (NMConnectivity *self)
}
update_connected (self, FALSE);
#endif
}
NMConnectivity *
@ -211,6 +225,7 @@ set_property (GObject *object, guint property_id,
g_free (priv->uri);
priv->uri = get_non_empty_string_value (value);
#if WITH_CONCHECK
if (priv->uri) {
SoupURI *uri = soup_uri_new (priv->uri);
@ -220,6 +235,7 @@ set_property (GObject *object, guint property_id,
priv->uri = NULL;
}
}
#endif
break;
case PROP_INTERVAL:
priv->interval = g_value_get_uint (value);
@ -266,7 +282,9 @@ nm_connectivity_init (NMConnectivity *self)
{
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
#if WITH_CONCHECK
priv->soup_session = soup_session_async_new_with_options (SOUP_SESSION_TIMEOUT, 15, NULL);
#endif
}
@ -276,18 +294,20 @@ dispose (GObject *object)
NMConnectivity *self = NM_CONNECTIVITY (object);
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
g_free (priv->uri);
g_free (priv->response);
#if WITH_CONCHECK
if (priv->soup_session) {
soup_session_abort (priv->soup_session);
g_clear_object (&priv->soup_session);
}
g_free (priv->uri);
g_free (priv->response);
if (priv->check_id > 0) {
g_source_remove (priv->check_id);
priv->check_id = 0;
}
#endif
}

View file

@ -77,10 +77,7 @@
#include "nm-device-factory.h"
#include "nm-enum-types.h"
#include "nm-sleep-monitor.h"
#if WITH_CONCHECK
#include "nm-connectivity.h"
#endif
#define NM_AUTOIP_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd"
@ -219,9 +216,7 @@ typedef struct {
GSList *devices;
NMState state;
#if WITH_CONCHECK
NMConnectivity *connectivity;
#endif
NMDBusManager *dbus_mgr;
guint dbus_connection_changed_id;
@ -552,11 +547,9 @@ nm_manager_update_state (NMManager *manager)
if (state == NM_DEVICE_STATE_ACTIVATED) {
new_state = NM_STATE_CONNECTED_GLOBAL;
#if WITH_CONCHECK
/* Connectivity check might have a better idea */
if (nm_connectivity_get_connected (priv->connectivity) == FALSE)
new_state = NM_STATE_CONNECTED_SITE;
#endif
break;
}
@ -585,9 +578,7 @@ manager_device_state_changed (NMDevice *device,
gpointer user_data)
{
NMManager *self = NM_MANAGER (user_data);
#if WITH_CONCHECK
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
#endif
switch (new_state) {
case NM_DEVICE_STATE_UNMANAGED:
@ -603,7 +594,6 @@ manager_device_state_changed (NMDevice *device,
nm_manager_update_state (self);
#if WITH_CONCHECK
if (priv->state >= NM_STATE_CONNECTED_LOCAL) {
if (old_state == NM_DEVICE_STATE_ACTIVATED || new_state == NM_DEVICE_STATE_ACTIVATED) {
/* Still connected, but a device activated or deactivated; make sure
@ -618,7 +608,6 @@ manager_device_state_changed (NMDevice *device,
nm_log_dbg (LOGD_CORE, "stopping connectivity checks");
nm_connectivity_stop_check (priv->connectivity);
}
#endif
}
static void device_has_pending_action_changed (NMDevice *device,
@ -4003,7 +3992,6 @@ handle_firmware_changed (gpointer user_data)
return FALSE;
}
#if WITH_CONCHECK
static void
connectivity_changed (NMConnectivity *connectivity,
GParamSpec *pspec,
@ -4018,7 +4006,6 @@ connectivity_changed (NMConnectivity *connectivity,
nm_manager_update_state (self);
}
#endif /* WITH_CONCHECK */
static void
firmware_dir_changed (GFileMonitor *monitor,
@ -4227,12 +4214,9 @@ nm_manager_new (NMSettings *settings,
priv = NM_MANAGER_GET_PRIVATE (singleton);
#if WITH_CONCHECK
priv->connectivity = nm_connectivity_new ();
g_signal_connect (priv->connectivity, "notify::" NM_CONNECTIVITY_CONNECTED,
G_CALLBACK (connectivity_changed), singleton);
#endif
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
g_assert (bus);
@ -4361,12 +4345,7 @@ dispose (GObject *object)
}
g_slist_free (priv->active_connections);
#if WITH_CONCHECK
if (priv->connectivity) {
g_object_unref (priv->connectivity);
priv->connectivity = NULL;
}
#endif
g_clear_object (&priv->connectivity);
g_free (priv->hostname);