~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to audio/device.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-10-07 12:10:29 UTC
  • Revision ID: james.westby@ubuntu.com-20081007121029-4gup4fmmh2vfo5nh
Tags: upstream-4.12
ImportĀ upstreamĀ versionĀ 4.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  BlueZ - Bluetooth protocol stack for Linux
 
4
 *
 
5
 *  Copyright (C) 2006-2007  Nokia Corporation
 
6
 *  Copyright (C) 2004-2008  Marcel Holtmann <marcel@holtmann.org>
 
7
 *
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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
 
22
 *
 
23
 */
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <config.h>
 
27
#endif
 
28
 
 
29
#include <stdio.h>
 
30
#include <errno.h>
 
31
#include <unistd.h>
 
32
#include <sys/stat.h>
 
33
#include <sys/param.h>
 
34
#include <netinet/in.h>
 
35
 
 
36
#include <bluetooth/bluetooth.h>
 
37
#include <bluetooth/hci.h>
 
38
#include <bluetooth/hci_lib.h>
 
39
#include <bluetooth/sdp.h>
 
40
#include <bluetooth/sdp_lib.h>
 
41
 
 
42
#include <glib.h>
 
43
#include <dbus/dbus.h>
 
44
#include <gdbus.h>
 
45
 
 
46
#include "logging.h"
 
47
#include "textfile.h"
 
48
 
 
49
#include "error.h"
 
50
#include "ipc.h"
 
51
#include "device.h"
 
52
#include "avdtp.h"
 
53
#include "control.h"
 
54
#include "headset.h"
 
55
#include "sink.h"
 
56
 
 
57
static void device_free(struct audio_device *dev)
 
58
{
 
59
        if (dev->conn)
 
60
                dbus_connection_unref(dev->conn);
 
61
 
 
62
        g_free(dev->path);
 
63
        g_free(dev);
 
64
}
 
65
 
 
66
struct audio_device *device_register(DBusConnection *conn,
 
67
                                        const char *path, const bdaddr_t *src,
 
68
                                        const bdaddr_t *dst)
 
69
{
 
70
        struct audio_device *dev;
 
71
 
 
72
        if (!conn || !path)
 
73
                return NULL;
 
74
 
 
75
        dev = g_new0(struct audio_device, 1);
 
76
 
 
77
        dev->path = g_strdup(path);
 
78
        bacpy(&dev->dst, dst);
 
79
        bacpy(&dev->src, src);
 
80
        dev->conn = dbus_connection_ref(conn);
 
81
 
 
82
        return dev;
 
83
}
 
84
 
 
85
gboolean device_is_connected(struct audio_device *dev, const char *interface)
 
86
{
 
87
        if (!interface) {
 
88
                if ((dev->sink || dev->source) &&
 
89
                        avdtp_is_connected(&dev->src, &dev->dst))
 
90
                        return TRUE;
 
91
 
 
92
                if (dev->headset && headset_is_active(dev))
 
93
                        return TRUE;
 
94
        }
 
95
        else if (!strcmp(interface, AUDIO_SINK_INTERFACE) && dev->sink &&
 
96
                        avdtp_is_connected(&dev->src, &dev->dst))
 
97
                return TRUE;
 
98
        else if (!strcmp(interface, AUDIO_SOURCE_INTERFACE) && dev->source &&
 
99
                        avdtp_is_connected(&dev->src, &dev->dst))
 
100
                return TRUE;
 
101
        else if (!strcmp(interface, AUDIO_HEADSET_INTERFACE) && dev->headset &&
 
102
                        headset_is_active(dev))
 
103
                return TRUE;
 
104
        else if (!strcmp(interface, AUDIO_CONTROL_INTERFACE) && dev->headset &&
 
105
                        control_is_active(dev))
 
106
                return TRUE;
 
107
 
 
108
        return FALSE;
 
109
}
 
110
 
 
111
void device_unregister(struct audio_device *device)
 
112
{
 
113
        if (device->headset)
 
114
                headset_unregister(device);
 
115
 
 
116
        if (device->sink)
 
117
                sink_unregister(device);
 
118
 
 
119
        if (device->control)
 
120
                control_unregister(device);
 
121
 
 
122
        device_free(device);
 
123
}