]> code.delx.au - pulseaudio/blobdiff - src/modules/bluetooth/module-bluetooth-discover.c
bluetooth: Update modules description and copyright
[pulseaudio] / src / modules / bluetooth / module-bluetooth-discover.c
index 7571e48a09b5edef6c2397763e0be6ce10bd9429..d89890b3871880b1624ce264cf677067ec5b471e 100644 (file)
@@ -1,7 +1,7 @@
 /***
   This file is part of PulseAudio.
 
-  Copyright 2008-2009 Joao Paulo Rechi Vita
+  Copyright 2008-2013 João Paulo Rechi Vita
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #include <pulse/xmalloc.h>
 #include <pulsecore/module.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/modargs.h>
 #include <pulsecore/macro.h>
-#include <pulsecore/llist.h>
 #include <pulsecore/core-util.h>
 #include <pulsecore/dbus-shared.h>
 
 #include "module-bluetooth-discover-symdef.h"
 #include "bluetooth-util.h"
 
-PA_MODULE_AUTHOR("Joao Paulo Rechi Vita");
-PA_MODULE_DESCRIPTION("Detect available bluetooth audio devices and load bluetooth audio drivers");
+PA_MODULE_AUTHOR("João Paulo Rechi Vita");
+PA_MODULE_DESCRIPTION("Detect available BlueZ 4 Bluetooth audio devices and load BlueZ 4 Bluetooth audio drivers");
 PA_MODULE_VERSION(PACKAGE_VERSION);
-PA_MODULE_USAGE("async=<Asynchronous initialization?>");
-PA_MODULE_LOAD_ONCE(TRUE);
-
-/*
-#ifdef NOKIA
-   "sco_sink=<name of sink> "
-   "sco_source=<name of source>"
-#endif
-*/
+PA_MODULE_USAGE("sco_sink=<name of sink> "
+                "sco_source=<name of source> ");
+PA_MODULE_LOAD_ONCE(true);
 
 static const char* const valid_modargs[] = {
-#ifdef NOKIA
     "sco_sink",
     "sco_source",
-#endif
-    "async",
+    "async", /* deprecated */
     NULL
 };
 
@@ -83,9 +73,7 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
 
     mi = pa_hashmap_get(u->hashmap, d->path);
 
-    pa_log("dead: %d, device_connected: %d, audio_state: %d, audio_source_state: %d", d->dead, d->device_connected, d->audio_state, d->audio_source_state);
-    if (!d->dead &&
-        d->device_connected > 0 && (d->audio_state >= PA_BT_AUDIO_STATE_CONNECTED || d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED)) {
+    if (pa_bluetooth_device_any_audio_connected(d)) {
 
         if (!mi) {
             pa_module *m = NULL;
@@ -94,17 +82,7 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
             /* Oh, awesome, a new device has shown up and been connected! */
 
             args = pa_sprintf_malloc("address=\"%s\" path=\"%s\"", d->address, d->path);
-#if 0
-            /* This is in case we have to use hsp immediately, without waiting for .Audio.State = Connected */
-            if (d->headset_state >= PA_BT_AUDIO_STATE_CONNECTED && somecondition) {
-                char *tmp;
-                tmp = pa_sprintf_malloc("%s profile=\"hsp\"", args);
-                pa_xfree(args);
-                args = tmp;
-            }
-#endif
 
-#ifdef NOKIA
             if (pa_modargs_get_value(u->modargs, "sco_sink", NULL) &&
                 pa_modargs_get_value(u->modargs, "sco_source", NULL)) {
                 char *tmp;
@@ -115,10 +93,6 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
                 pa_xfree(args);
                 args = tmp;
             }
-#endif
-
-            if (d->audio_source_state >= PA_BT_AUDIO_STATE_CONNECTED)
-                args = pa_sprintf_malloc("%s profile=\"a2dp_source\"", args);
 
             pa_log_debug("Loading module-bluetooth-device %s", args);
             m = pa_module_load(u->module->core, "module-bluetooth-device", args);
@@ -138,11 +112,9 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
 
         if (mi) {
 
-            /* Hmm, disconnection? Then let's unload our module */
-
-            pa_log_debug("Unloading module for %s", d->path);
-            pa_module_unload_request_by_index(u->core, mi->module, TRUE);
+            /* Hmm, disconnection? Then the module unloads itself */
 
+            pa_log_debug("Unregistering module for %s", d->path);
             pa_hashmap_remove(u->hashmap, mi->path);
             pa_xfree(mi->path);
             pa_xfree(mi);
@@ -155,7 +127,6 @@ static pa_hook_result_t load_module_for_device(pa_bluetooth_discovery *y, const
 int pa__init(pa_module* m) {
     struct userdata *u;
     pa_modargs *ma = NULL;
-    pa_bool_t async = FALSE;
 
     pa_assert(m);
 
@@ -164,10 +135,8 @@ int pa__init(pa_module* m) {
         goto fail;
     }
 
-    if (pa_modargs_get_value_boolean(ma, "async", &async) < 0) {
-        pa_log("Failed to parse async argument.");
-        goto fail;
-    }
+    if (pa_modargs_get_value(ma, "async", NULL))
+        pa_log_warn("The 'async' argument is deprecated and does nothing.");
 
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->module = m;
@@ -179,10 +148,8 @@ int pa__init(pa_module* m) {
     if (!(u->discovery = pa_bluetooth_discovery_get(u->core)))
         goto fail;
 
-    u->slot = pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery), PA_HOOK_NORMAL, (pa_hook_cb_t) load_module_for_device, u);
-
-    if (!async)
-        pa_bluetooth_discovery_sync(u->discovery);
+    u->slot = pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
+                              PA_HOOK_NORMAL, (pa_hook_cb_t) load_module_for_device, u);
 
     return 0;
 
@@ -217,7 +184,7 @@ void pa__done(pa_module* m) {
             pa_xfree(mi);
         }
 
-        pa_hashmap_free(u->hashmap, NULL, NULL);
+        pa_hashmap_free(u->hashmap);
     }
 
     if (u->modargs)