<commit_before>/*
 *
 *  Network Monitor for Connection Manager
 *
 *  Copyright (C) 2012  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 2.1,
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <gio/gio.h>

#include "connman-api.h"

static int priority = 90;
static guint network_changed_signal = 0;

enum {
	PROP_0,
	PROP_NETWORK_AVAILABLE,
};

enum connman_state {
	STATE_UNKNOWN = 0,
	STATE_IDLE,
	STATE_READY,
	STATE_ONLINE,
	STATE_FAILURE,
};

typedef struct _GNetworkMonitorConnmanPrivate GNetworkMonitorConnmanPrivate;
struct _GNetworkMonitorConnmanPrivate
{
	enum connman_state state;
	struct connman_manager *manager;
};

typedef struct _GNetworkMonitorConnman GNetworkMonitorConnman;
struct _GNetworkMonitorConnman {
	GObject parent;
	GNetworkMonitorConnmanPrivate *priv;
};

typedef struct _GNetworkMonitorConnmanClass GNetworkMonitorConnmanClass;
struct _GNetworkMonitorConnmanClass {
	GObjectClass parent_class;
};

#define CONNMAN_TYPE_NETWORK_MONITOR (g_network_monitor_connman_get_type())
#define CONNMAN_NETWORK_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),	\
					CONNMAN_TYPE_NETWORK_MONITOR,   \
					GNetworkMonitorConnman))
#define CONNMAN_NETWORK_MONITOR_CLASS(klass) \
					(G_TYPE_CHECK_CLASS_CAST((klass), \
						CONNMAN_TYPE_NETWORK_MONITOR, \
						GNetworkMonitorConnmanClass))
#define CONNMAN_IS_NETWORK_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
						CONNMAN_TYPE_NETWORK_MONITOR))
#define CONNMAN_IS_NETWORK_MONITOR_CLASS(klass) \
					(G_TYPE_CHECK_CLASS_TYPE((klass), \
						CONNMAN_TYPE_NETWORK_MONITOR))

static void network_monitor_iface_init(GNetworkMonitorInterface *iface);
static void network_monitor_initable_iface_init(GInitableIface *iface);
static void g_network_monitor_connman_init(GNetworkMonitorConnman *self);
static void g_network_monitor_connman_class_init(GNetworkMonitorConnmanClass *klass);
static void g_network_monitor_connman_class_finalize(GNetworkMonitorConnmanClass *klass);
GType g_network_monitor_connman_get_type(void);

G_DEFINE_DYNAMIC_TYPE_EXTENDED(GNetworkMonitorConnman,
			g_network_monitor_connman,
			G_TYPE_OBJECT, 0  /* flags */,
			G_IMPLEMENT_INTERFACE_DYNAMIC(G_TYPE_INITABLE,
				network_monitor_initable_iface_init)
			G_IMPLEMENT_INTERFACE_DYNAMIC(G_TYPE_NETWORK_MONITOR,
				network_monitor_iface_init))

static GObject *network_monitor_constructor(GType type, guint n_props,
						GObjectConstructParam *props)
{
	GObject *obj;

	obj = G_OBJECT_CLASS(g_network_monitor_connman_parent_class)->
					constructor(type, n_props, props);
	return obj;
}

static void network_monitor_finalize(GObject *object)
{
	GNetworkMonitorConnman *monitor;

	g_return_if_fail(object != NULL);
	g_return_if_fail(CONNMAN_IS_NETWORK_MONITOR(object));

	monitor = CONNMAN_NETWORK_MONITOR(object);

	connman_manager_cleanup(monitor->priv->manager);
	monitor->priv->manager = NULL;
	monitor->priv->state = STATE_UNKNOWN;

	G_OBJECT_CLASS(g_network_monitor_connman_parent_class)->
					finalize(object);
}

static gboolean is_available(enum connman_state state)
{
	switch (state) {
	case STATE_UNKNOWN:
	case STATE_IDLE:
	case STATE_FAILURE:
		return FALSE;

	case STATE_READY:
	case STATE_ONLINE:
		return TRUE;
	}

	return FALSE;
}

static gboolean get_state(GNetworkMonitorConnman *monitor)
{
	return is_available(monitor->priv->state);
}

static void get_property(GObject *object, guint prop_id,
			GValue *value, GParamSpec *pspec)
{
	GNetworkMonitorConnman *monitor = CONNMAN_NETWORK_MONITOR(object);

	switch (prop_id) {
	case PROP_NETWORK_AVAILABLE:
		g_value_set_boolean(value, get_state(monitor));
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
		break;
	}
}

static void
g_network_monitor_connman_class_init(GNetworkMonitorConnmanClass *klass)
{
	GObjectClass *gobject_class;

	gobject_class = G_OBJECT_CLASS(klass);
	gobject_class->constructor = network_monitor_constructor;
	gobject_class->finalize = network_monitor_finalize;
	gobject_class->get_property = get_property;

	g_object_class_override_property(gobject_class,
					PROP_NETWORK_AVAILABLE,
					"network-available");
<commit_msg>monitor: Add dummy support for the GNetworkMonitor:connectivity property<commit_after>/*
 *
 *  Network Monitor for Connection Manager
 *
 *  Copyright (C) 2012  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 2.1,
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <gio/gio.h>

#include "connman-api.h"

static int priority = 90;
static guint network_changed_signal = 0;

enum {
	PROP_0,
	PROP_NETWORK_AVAILABLE,
	PROP_CONNECTIVITY,
};

enum connman_state {
	STATE_UNKNOWN = 0,
	STATE_IDLE,
	STATE_READY,
	STATE_ONLINE,
	STATE_FAILURE,
};

typedef struct _GNetworkMonitorConnmanPrivate GNetworkMonitorConnmanPrivate;
struct _GNetworkMonitorConnmanPrivate
{
	enum connman_state state;
	struct connman_manager *manager;
};

typedef struct _GNetworkMonitorConnman GNetworkMonitorConnman;
struct _GNetworkMonitorConnman {
	GObject parent;
	GNetworkMonitorConnmanPrivate *priv;
};

typedef struct _GNetworkMonitorConnmanClass GNetworkMonitorConnmanClass;
struct _GNetworkMonitorConnmanClass {
	GObjectClass parent_class;
};

#define CONNMAN_TYPE_NETWORK_MONITOR (g_network_monitor_connman_get_type())
#define CONNMAN_NETWORK_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),	\
					CONNMAN_TYPE_NETWORK_MONITOR,   \
					GNetworkMonitorConnman))
#define CONNMAN_NETWORK_MONITOR_CLASS(klass) \
					(G_TYPE_CHECK_CLASS_CAST((klass), \
						CONNMAN_TYPE_NETWORK_MONITOR, \
						GNetworkMonitorConnmanClass))
#define CONNMAN_IS_NETWORK_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
						CONNMAN_TYPE_NETWORK_MONITOR))
#define CONNMAN_IS_NETWORK_MONITOR_CLASS(klass) \
					(G_TYPE_CHECK_CLASS_TYPE((klass), \
						CONNMAN_TYPE_NETWORK_MONITOR))

static void network_monitor_iface_init(GNetworkMonitorInterface *iface);
static void network_monitor_initable_iface_init(GInitableIface *iface);
static void g_network_monitor_connman_init(GNetworkMonitorConnman *self);
static void g_network_monitor_connman_class_init(GNetworkMonitorConnmanClass *klass);
static void g_network_monitor_connman_class_finalize(GNetworkMonitorConnmanClass *klass);
GType g_network_monitor_connman_get_type(void);

G_DEFINE_DYNAMIC_TYPE_EXTENDED(GNetworkMonitorConnman,
			g_network_monitor_connman,
			G_TYPE_OBJECT, 0  /* flags */,
			G_IMPLEMENT_INTERFACE_DYNAMIC(G_TYPE_INITABLE,
				network_monitor_initable_iface_init)
			G_IMPLEMENT_INTERFACE_DYNAMIC(G_TYPE_NETWORK_MONITOR,
				network_monitor_iface_init))

static GObject *network_monitor_constructor(GType type, guint n_props,
						GObjectConstructParam *props)
{
	GObject *obj;

	obj = G_OBJECT_CLASS(g_network_monitor_connman_parent_class)->
					constructor(type, n_props, props);
	return obj;
}

static void network_monitor_finalize(GObject *object)
{
	GNetworkMonitorConnman *monitor;

	g_return_if_fail(object != NULL);
	g_return_if_fail(CONNMAN_IS_NETWORK_MONITOR(object));

	monitor = CONNMAN_NETWORK_MONITOR(object);

	connman_manager_cleanup(monitor->priv->manager);
	monitor->priv->manager = NULL;
	monitor->priv->state = STATE_UNKNOWN;

	G_OBJECT_CLASS(g_network_monitor_connman_parent_class)->
					finalize(object);
}

static gboolean is_available(enum connman_state state)
{
	switch (state) {
	case STATE_UNKNOWN:
	case STATE_IDLE:
	case STATE_FAILURE:
		return FALSE;

	case STATE_READY:
	case STATE_ONLINE:
		return TRUE;
	}

	return FALSE;
}

static gboolean get_state(GNetworkMonitorConnman *monitor)
{
	return is_available(monitor->priv->state);
}

static void get_property(GObject *object, guint prop_id,
			GValue *value, GParamSpec *pspec)
{
	GNetworkMonitorConnman *monitor = CONNMAN_NETWORK_MONITOR(object);

	switch (prop_id) {
	case PROP_NETWORK_AVAILABLE:
		g_value_set_boolean(value, get_state(monitor));
		break;

	case PROP_CONNECTIVITY:
		/* FIXME: Implement connectivity and captive portal checking. */
		g_value_set_enum(value, get_state(monitor) ? G_NETWORK_CONNECTIVITY_FULL : G_NETWORK_CONNECTIVITY_LOCAL);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
		break;
	}
}

static void
g_network_monitor_connman_class_init(GNetworkMonitorConnmanClass *klass)
{
	GObjectClass *gobject_class;

	gobject_class = G_OBJECT_CLASS(klass);
	gobject_class->constructor = network_monitor_constructor;
	gobject_class->finalize = network_monitor_finalize;
	gobject_class->get_property = get_property;

	g_object_class_override_property(gobject_class,
					PROP_NETWORK_AVAILABLE,
					"network-available");
	g_object_class_override_property(gobject_class,
					PROP_CONNECTIVITY,
					"connectivity");

{'fraction_non_alphanumeric': 0.07412587412587412, 'fraction_numerical': 0.004595404595404595, 'mean_word_length': 6.2913328477785875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1980835', 'n_tokens_mistral': 3577, 'n_tokens_neox': 3370, 'n_words': 699}