<commit_before>/*
 * Copyright (C) 2014 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>

#include <cutils/properties.h>

#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
#include "ipc-common.h"
#include "hal-ipc.h"

#define MODE_PROPERTY_NAME "persist.sys.bluetooth.handsfree"

static const bthf_callbacks_t *cbs = NULL;

static bool interface_ready(void)
{
	return cbs != NULL;
}

static void handle_conn_state(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_conn_state *ev = buf;

	if (cbs->connection_state_cb)
		cbs->connection_state_cb(ev->state,
						(bt_bdaddr_t *) (ev->bdaddr));
}

static void handle_audio_state(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_audio_state *ev = buf;

	if (cbs->audio_state_cb)
		cbs->audio_state_cb(ev->state, (bt_bdaddr_t *) (ev->bdaddr));
}

static void handle_vr_state(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_vr_state *ev = buf;

	if (cbs->vr_cmd_cb)
		cbs->vr_cmd_cb(ev->state);
}

static void handle_answer(void *buf, uint16_t len, int fd)
{
	if (cbs->answer_call_cmd_cb)
		cbs->answer_call_cmd_cb();
}

static void handle_hangup(void *buf, uint16_t len, int fd)
{
	if (cbs->hangup_call_cmd_cb)
		cbs->hangup_call_cmd_cb();
}

static void handle_volume(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_volume *ev = buf;

	if (cbs->volume_cmd_cb)
		cbs->volume_cmd_cb(ev->type, ev->volume);
}

static void handle_dial(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_dial *ev = buf;
	uint16_t num_len = ev->number_len;

	if (len != sizeof(*ev) + num_len ||
			(num_len != 0 && ev->number[num_len - 1] != '\0')) {
		error("invalid dial event, aborting");
		exit(EXIT_FAILURE);
	}

	if (!cbs->dial_call_cmd_cb)
		return;

	if (ev->number_len)
		cbs->dial_call_cmd_cb((char *) ev->number);
	else
		cbs->dial_call_cmd_cb(NULL);
}

static void handle_dtmf(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_dtmf *ev = buf;

	if (cbs->dtmf_cmd_cb)
		cbs->dtmf_cmd_cb(ev->tone);
}

static void handle_nrec(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_nrec *ev = buf;

	if (cbs->nrec_cmd_cb)
		cbs->nrec_cmd_cb(ev->nrec);
}

static void handle_chld(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_chld *ev = buf;

	if (cbs->chld_cmd_cb)
		cbs->chld_cmd_cb(ev->chld);<commit_msg>android/handsfree: Refactor handle_dial()<commit_after>/*
 * Copyright (C) 2014 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>

#include <cutils/properties.h>

#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
#include "ipc-common.h"
#include "hal-ipc.h"

#define MODE_PROPERTY_NAME "persist.sys.bluetooth.handsfree"

static const bthf_callbacks_t *cbs = NULL;

static bool interface_ready(void)
{
	return cbs != NULL;
}

static void handle_conn_state(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_conn_state *ev = buf;

	if (cbs->connection_state_cb)
		cbs->connection_state_cb(ev->state,
						(bt_bdaddr_t *) (ev->bdaddr));
}

static void handle_audio_state(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_audio_state *ev = buf;

	if (cbs->audio_state_cb)
		cbs->audio_state_cb(ev->state, (bt_bdaddr_t *) (ev->bdaddr));
}

static void handle_vr_state(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_vr_state *ev = buf;

	if (cbs->vr_cmd_cb)
		cbs->vr_cmd_cb(ev->state);
}

static void handle_answer(void *buf, uint16_t len, int fd)
{
	if (cbs->answer_call_cmd_cb)
		cbs->answer_call_cmd_cb();
}

static void handle_hangup(void *buf, uint16_t len, int fd)
{
	if (cbs->hangup_call_cmd_cb)
		cbs->hangup_call_cmd_cb();
}

static void handle_volume(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_volume *ev = buf;

	if (cbs->volume_cmd_cb)
		cbs->volume_cmd_cb(ev->type, ev->volume);
}

static void handle_dial(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_dial *ev = buf;
	uint16_t num_len = ev->number_len;
	char *number = NULL;

	if (len != sizeof(*ev) + num_len ||
			(num_len != 0 && ev->number[num_len - 1] != '\0')) {
		error("invalid dial event, aborting");
		exit(EXIT_FAILURE);
	}

	if (!cbs->dial_call_cmd_cb)
		return;

	if (ev->number_len)
		number = (char *) ev->number;

	cbs->dial_call_cmd_cb(number);
}

static void handle_dtmf(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_dtmf *ev = buf;

	if (cbs->dtmf_cmd_cb)
		cbs->dtmf_cmd_cb(ev->tone);
}

static void handle_nrec(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_nrec *ev = buf;

	if (cbs->nrec_cmd_cb)
		cbs->nrec_cmd_cb(ev->nrec);
}

static void handle_chld(void *buf, uint16_t len, int fd)
{
	struct hal_ev_handsfree_chld *ev = buf;

	if (cbs->chld_cmd_cb)
		cbs->chld_cmd_cb(ev->chld);
{'fraction_non_alphanumeric': 0.12921727395411606, 'fraction_numerical': 0.011133603238866396, 'mean_word_length': 4.635931558935361, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1743192', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2309, 'n_words': 580}