This patch adds a new handsfree audio driver abstration to allow
implementing the connect callbacks and other potential functions
specific of each HFP profile version. This approach also avoids
including dependency of hfpmodem in handsfree-audio, keeping the service
level handling inside the hfp_hf_bluez5 only.
---
 include/handsfree-audio.h | 11 +++++++++++
 src/handsfree-audio.c     | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/handsfree-audio.h b/include/handsfree-audio.h
index c5403c7..69f5a8e 100644
--- a/include/handsfree-audio.h
+++ b/include/handsfree-audio.h
@@ -30,6 +30,17 @@ extern "C" {
 
 struct ofono_handsfree_card;
 
+struct ofono_handsfree_card_driver {
+       int (*probe) (struct ofono_handsfree_card *card, void *data);
+       void (*remove) (struct ofono_handsfree_card *card);
+       int (*audio_connect) (const char *remote, const char *local);
+};
+
+int ofono_handsfree_card_driver_register(
+                       const struct ofono_handsfree_card_driver *d);
+void ofono_handsfree_card_driver_unregister(
+                       const struct ofono_handsfree_card_driver *d);
+
 struct ofono_handsfree_card *ofono_handsfree_card_create(const char *remote,
                                                        const char *local);
 int ofono_handsfree_card_register(struct ofono_handsfree_card *card);
diff --git a/src/handsfree-audio.c b/src/handsfree-audio.c
index 73c6183..ffae47b 100644
--- a/src/handsfree-audio.c
+++ b/src/handsfree-audio.c
@@ -52,6 +52,7 @@ struct ofono_handsfree_card {
        char *remote;
        char *local;
        char *path;
+       const struct ofono_handsfree_card_driver *driver;
 };
 
 struct agent {
@@ -66,6 +67,7 @@ static struct agent *agent = NULL;
 static int ref_count = 0;
 static GSList *card_list = 0;
 static guint sco_watch = 0;
+static GSList *g_drivers = NULL;
 
 static void send_new_connection(const char *card, int fd)
 {
@@ -255,6 +257,7 @@ struct ofono_handsfree_card 
*ofono_handsfree_card_create(const char *remote,
                                                        const char *local)
 {
        struct ofono_handsfree_card *card;
+       GSList *l;
 
        card = g_new0(struct ofono_handsfree_card, 1);
 
@@ -263,6 +266,16 @@ struct ofono_handsfree_card 
*ofono_handsfree_card_create(const char *remote,
 
        card_list = g_slist_prepend(card_list, card);
 
+       for (l = g_drivers; l; l = g_slist_next(l)) {
+               const struct ofono_handsfree_card_driver *drv = l->data;
+
+               if (drv->probe(card, NULL) < 0)
+                       continue;
+
+               card->driver = drv;
+               break;
+       }
+
        return card;
 }
 
@@ -534,6 +547,27 @@ static const GDBusSignalTable am_signals[] = {
        { }
 };
 
+int ofono_handsfree_card_driver_register(
+                               const struct ofono_handsfree_card_driver *d)
+{
+       DBG("driver: %p", d);
+
+       if (d->probe == NULL)
+               return -EINVAL;
+
+       g_drivers = g_slist_prepend(g_drivers, (void *) d);
+
+       return 0;
+}
+
+void ofono_handsfree_card_driver_unregister(
+                               const struct ofono_handsfree_card_driver *d)
+{
+       DBG("driver: %p", d);
+
+       g_drivers = g_slist_remove(g_drivers, (void *) d);
+}
+
 void ofono_handsfree_audio_ref(void)
 {
        ref_count += 1;
-- 
1.7.11.7

_______________________________________________
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono

Reply via email to