3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2011-2012 Intel Corporation
6
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34
#include <sys/socket.h>
37
#include "src/shared/mainloop.h"
38
#include "src/shared/hfp.h"
40
static void hfp_debug(const char *str, void *user_data)
42
const char *prefix = user_data;
44
printf("%s%s\n", prefix, str);
47
static void command_handler(const char *command, void *user_data)
49
struct hfp_gw *hfp = user_data;
51
printf("Command: %s\n", command);
53
hfp_gw_send_result(hfp, HFP_RESULT_ERROR);
56
static bool open_connection(void)
58
static const char SOCKET_PATH[] = "\0hfp-headset";
60
struct sockaddr_un addr;
63
fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
65
perror("Failed to create Unix socket");
69
memset(&addr, 0, sizeof(addr));
70
addr.sun_family = AF_UNIX;
71
memcpy(addr.sun_path, SOCKET_PATH, sizeof(SOCKET_PATH));
73
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
74
perror("Failed to connect Unix socket");
85
hfp_gw_set_close_on_unref(hfp, true);
87
hfp_gw_set_debug(hfp, hfp_debug, "HFP: ", NULL);
89
hfp_gw_set_command_handler(hfp, command_handler, hfp, NULL);
94
static void signal_callback(int signum, void *user_data)
104
int main(int argc, char *argv[])
111
sigaddset(&mask, SIGINT);
112
sigaddset(&mask, SIGTERM);
114
mainloop_set_signal(&mask, signal_callback, NULL, NULL);
116
if (!open_connection())
119
return mainloop_run();