<commit_before>/*
 *
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2011  Nokia Corporation
 *  Copyright (C) 2011  <NAME> <<EMAIL>>
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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 General Public License for more details.
 *
 *  You should have received a copy of the GNU 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 <gdbus.h>

#include "adapter.h"
#include "device.h"
#include "monitor.h"
#include "reporter.h"
#include "manager.h"

#define IMMEDIATE_ALERT_UUID	"00001802-0000-1000-8000-00805f9b34fb"
#define LINK_LOSS_UUID		"00001803-0000-1000-8000-00805f9b34fb"
#define TX_POWER_UUID		"00001804-0000-1000-8000-00805f9b34fb"

static DBusConnection *connection = NULL;

static struct enabled enabled  = {
	.linkloss = TRUE,
	.pathloss = TRUE,
	.findme = TRUE,
};

static int attio_device_probe(struct btd_device *device, GSList *uuids)
{
	gboolean linkloss = FALSE, pathloss = FALSE, findme = FALSE;

	if (g_slist_find_custom(uuids, IMMEDIATE_ALERT_UUID,
					(GCompareFunc) strcasecmp)) {
		findme = enabled.findme;
		if (g_slist_find_custom(uuids, TX_POWER_UUID,
					(GCompareFunc) strcasecmp))
			pathloss = enabled.pathloss;
	}

	if (g_slist_find_custom(uuids, LINK_LOSS_UUID,
				(GCompareFunc) strcasecmp))
		linkloss = enabled.linkloss;

	return monitor_register(connection, device, linkloss, pathloss, findme);
}

static void attio_device_remove(struct btd_device *device)
{
	monitor_unregister(connection, device);
}

static struct btd_device_driver monitor_driver = {
	.name = "Proximity GATT Driver",
	.uuids = BTD_UUIDS(IMMEDIATE_ALERT_UUID, LINK_LOSS_UUID, TX_POWER_UUID),
	.probe = attio_device_probe,
	.remove = attio_device_remove,
};

static void load_config_file(GKeyFile *config)
{
	char **list;
	int i;

	list = g_key_file_get_string_list(config, "General", "Disable",
								NULL, NULL);
	for (i = 0; list && list[i] != NULL; i++) {
		if (g_str_equal(list[i], "FindMe"))
			enabled.findme = FALSE;
		else if (g_str_equal(list[i], "LinkLoss"))
			enabled.linkloss = FALSE;
		else if (g_str_equal(list[i], "PathLoss"))
			enabled.pathloss = FALSE;
	}

	g_strfreev(list);
}

int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
{
	int ret;
<commit_msg>Fix error when proximity config file is missing<commit_after>/*
 *
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2011  Nokia Corporation
 *  Copyright (C) 2011  <NAME> <<EMAIL>>
 *
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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 General Public License for more details.
 *
 *  You should have received a copy of the GNU 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 <gdbus.h>

#include "adapter.h"
#include "device.h"
#include "monitor.h"
#include "reporter.h"
#include "manager.h"

#define IMMEDIATE_ALERT_UUID	"00001802-0000-1000-8000-00805f9b34fb"
#define LINK_LOSS_UUID		"00001803-0000-1000-8000-00805f9b34fb"
#define TX_POWER_UUID		"00001804-0000-1000-8000-00805f9b34fb"

static DBusConnection *connection = NULL;

static struct enabled enabled  = {
	.linkloss = TRUE,
	.pathloss = TRUE,
	.findme = TRUE,
};

static int attio_device_probe(struct btd_device *device, GSList *uuids)
{
	gboolean linkloss = FALSE, pathloss = FALSE, findme = FALSE;

	if (g_slist_find_custom(uuids, IMMEDIATE_ALERT_UUID,
					(GCompareFunc) strcasecmp)) {
		findme = enabled.findme;
		if (g_slist_find_custom(uuids, TX_POWER_UUID,
					(GCompareFunc) strcasecmp))
			pathloss = enabled.pathloss;
	}

	if (g_slist_find_custom(uuids, LINK_LOSS_UUID,
				(GCompareFunc) strcasecmp))
		linkloss = enabled.linkloss;

	return monitor_register(connection, device, linkloss, pathloss, findme);
}

static void attio_device_remove(struct btd_device *device)
{
	monitor_unregister(connection, device);
}

static struct btd_device_driver monitor_driver = {
	.name = "Proximity GATT Driver",
	.uuids = BTD_UUIDS(IMMEDIATE_ALERT_UUID, LINK_LOSS_UUID, TX_POWER_UUID),
	.probe = attio_device_probe,
	.remove = attio_device_remove,
};

static void load_config_file(GKeyFile *config)
{
	char **list;
	int i;

	if (config == NULL)
		return;

	list = g_key_file_get_string_list(config, "General", "Disable",
								NULL, NULL);
	for (i = 0; list && list[i] != NULL; i++) {
		if (g_str_equal(list[i], "FindMe"))
			enabled.findme = FALSE;
		else if (g_str_equal(list[i], "LinkLoss"))
			enabled.linkloss = FALSE;
		else if (g_str_equal(list[i], "PathLoss"))
			enabled.pathloss = FALSE;
	}

	g_strfreev(list);
}

int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
{
	int ret;

{'fraction_non_alphanumeric': 0.10463091922005571, 'fraction_numerical': 0.03655988857938719, 'mean_word_length': 4.529355149181906, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7015794', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2035, 'n_words': 575}