summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-10-08 14:09:25 +0200
committerJohan Hedberg <johan.hedberg@nokia.com>2008-10-08 14:09:25 +0200
commit586fd91a6c1a18e7e324fe39c20786be357c3576 (patch)
tree07060acebc43eeaaa448e0170f05133ed951f370
parent2db2d39af8cba3883756d21a0634722f37bdfef0 (diff)
Add separate function for creating new audio device objects
This is needed in preparation of supporting remotely initated audio device pairing and connections (when we haven't done SDP to the remote device yet).
-rw-r--r--audio/manager.c58
-rw-r--r--audio/manager.h6
2 files changed, 55 insertions, 9 deletions
diff --git a/audio/manager.c b/audio/manager.c
index a6a040fe..5a043f5e 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -50,6 +50,7 @@
#include <gdbus.h>
#include "glib-helper.h"
+#include "../src/manager.h"
#include "../src/adapter.h"
#include "../src/device.h"
@@ -684,12 +685,10 @@ static int audio_probe(struct btd_device *device, GSList *records)
adapter_get_address(adapter, &src);
device_get_address(device, &dst);
- dev = manager_find_device(&dst, NULL, FALSE);
+ dev = manager_get_device(&src, &dst, path, NULL);
if (!dev) {
- dev = device_register(connection, path, &src, &dst);
- if (!dev)
- return -EINVAL;
- devices = g_slist_append(devices, dev);
+ debug("audio_probe: unable to get a device object");
+ return -1;
}
g_slist_foreach(records, (GFunc) handle_record, dev);
@@ -1057,3 +1056,52 @@ struct audio_device *manager_find_device(const bdaddr_t *bda, const char *interf
return NULL;
}
+
+struct audio_device *manager_get_device(bdaddr_t *src, bdaddr_t *dst,
+ const char *path, gboolean *created)
+{
+ struct audio_device *dev;
+
+ if (created)
+ *created = FALSE;
+
+ dev = manager_find_device(dst, NULL, FALSE);
+ if (dev)
+ return dev;
+
+ if (!path) {
+ struct btd_adapter *adapter;
+ struct btd_device *device;
+ char addr[18];
+
+ ba2str(src, addr);
+
+ adapter = manager_find_adapter(src);
+ if (!adapter) {
+ error("Unable to get a btd_adapter object for %s",
+ addr);
+ return NULL;
+ }
+
+ ba2str(dst, addr);
+
+ device = adapter_get_device(connection, adapter, addr);
+ if (!device) {
+ error("Unable to get btd_device object for %s", addr);
+ return NULL;
+ }
+
+ path = device_get_path(device);
+ }
+
+ dev = device_register(connection, path, src, dst);
+ if (!dev)
+ return NULL;
+
+ devices = g_slist_append(devices, dev);
+
+ if (created)
+ *created = TRUE;
+
+ return dev;
+}
diff --git a/audio/manager.h b/audio/manager.h
index 708b52be..7feaf83c 100644
--- a/audio/manager.h
+++ b/audio/manager.h
@@ -30,8 +30,6 @@ struct enabled_interfaces {
gboolean control;
};
-typedef void (*create_dev_cb_t) (struct audio_device *dev, void *user_data);
-
int audio_manager_init(DBusConnection *conn, GKeyFile *config);
void audio_manager_exit(void);
@@ -40,5 +38,5 @@ gboolean server_is_enabled(bdaddr_t *src, uint16_t svc);
struct audio_device *manager_find_device(const bdaddr_t *bda, const char *interface,
gboolean connected);
-gboolean manager_create_device(bdaddr_t *bda, create_dev_cb_t cb,
- void *user_data);
+struct audio_device *manager_get_device(bdaddr_t *sba, bdaddr_t *dba,
+ const char *path, gboolean *created);