-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapter abstraction layer for HCI device
Add adapter abstraction layer to the internal transport management stack. Now, it will be possible to handle multiple number of HCI with single BlueALSA instance. The layer hierarchy looks like this: adapter (HCI) -> device (BT device) -> transport (audio)
- Loading branch information
Showing
18 changed files
with
509 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* BlueALSA - ba-adapter.c | ||
* Copyright (c) 2016-2019 Arkadiusz Bokowy | ||
* | ||
* This file is a part of bluez-alsa. | ||
* | ||
* This project is licensed under the terms of the MIT license. | ||
* | ||
*/ | ||
|
||
#include "ba-adapter.h" | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
|
||
#include "bluealsa.h" | ||
|
||
static guint g_bdaddr_hash(gconstpointer v) { | ||
const bdaddr_t *ba = (const bdaddr_t *)v; | ||
return ((uint32_t *)ba->b)[0] * ((uint16_t *)ba->b)[2]; | ||
} | ||
|
||
static gboolean g_bdaddr_equal(gconstpointer v1, gconstpointer v2) { | ||
return bacmp(v1, v2) == 0; | ||
} | ||
|
||
struct ba_adapter *ba_adapter_new(int dev_id, const char *name) { | ||
|
||
struct ba_adapter *a; | ||
|
||
/* make sure we are within array boundaries */ | ||
if (dev_id < 0 || dev_id >= HCI_MAX_DEV) { | ||
errno = EINVAL; | ||
return NULL; | ||
} | ||
|
||
if ((a = calloc(1, sizeof(*a))) == NULL) | ||
return NULL; | ||
|
||
a->hci_dev_id = dev_id; | ||
|
||
if (name != NULL) | ||
strncpy(a->hci_name, name, sizeof(a->hci_name) - 1); | ||
else | ||
sprintf(a->hci_name, "hci%d", dev_id); | ||
|
||
pthread_mutex_init(&a->devices_mutex, NULL); | ||
a->devices = g_hash_table_new_full(g_bdaddr_hash, g_bdaddr_equal, NULL, NULL); | ||
|
||
config.adapters[a->hci_dev_id] = a; | ||
return a; | ||
} | ||
|
||
struct ba_adapter *ba_adapter_lookup(int dev_id) { | ||
if (dev_id >= 0 && dev_id < HCI_MAX_DEV) | ||
return config.adapters[dev_id]; | ||
return NULL; | ||
} | ||
|
||
void ba_adapter_free(struct ba_adapter *a) { | ||
|
||
/* detach adapter from global configuration */ | ||
config.adapters[a->hci_dev_id] = NULL; | ||
|
||
if (a->devices != NULL) { | ||
|
||
GHashTableIter iter; | ||
struct ba_device *d; | ||
|
||
g_hash_table_iter_init(&iter, a->devices); | ||
while (g_hash_table_iter_next(&iter, NULL, (gpointer)&d)) | ||
ba_device_free(d); | ||
|
||
g_hash_table_unref(a->devices); | ||
} | ||
|
||
pthread_mutex_destroy(&a->devices_mutex); | ||
|
||
free(a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* BlueALSA - ba-adapter.h | ||
* Copyright (c) 2016-2019 Arkadiusz Bokowy | ||
* | ||
* This file is a part of bluez-alsa. | ||
* | ||
* This project is licensed under the terms of the MIT license. | ||
* | ||
*/ | ||
|
||
#ifndef BLUEALSA_BAADAPTER_H | ||
#define BLUEALSA_BAADAPTER_H | ||
|
||
#if HAVE_CONFIG_H | ||
# include <config.h> | ||
#endif | ||
|
||
#include <pthread.h> | ||
|
||
#include <glib.h> | ||
|
||
#include "ba-device.h" | ||
|
||
/* Data associated with BT adapter. */ | ||
struct ba_adapter { | ||
|
||
int hci_dev_id; | ||
char hci_name[8]; | ||
|
||
/* collection of connected devices */ | ||
pthread_mutex_t devices_mutex; | ||
GHashTable *devices; | ||
|
||
}; | ||
|
||
struct ba_adapter *ba_adapter_new(int dev_id, const char *name); | ||
struct ba_adapter *ba_adapter_lookup(int dev_id); | ||
void ba_adapter_free(struct ba_adapter *a); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.