Add new dbus telephony driver
Subsystems (2)
cover Add new dbus telephony driver
This patch add a new telephony driver allowing HSP/HFP to be managed through an external DBus agent.
BlueZ takes care of SDP and RFComm parts while the upper layer is processed by the agent.
Current AT parser and dbus code which are only needed by current drivers (built-in drivers) are move to telephony-builtin.[ch].
Frédéric Danis (4):
Audio: move at parsing code to telephony-builtin.[ch] files
Audio: move dbus callbacks to telephony-builtin.c
Audio: add adapter to telephony_init/_exit
Audio: add dbus telephony driver
Makefile.am | 9 +- acinclude.m4 | 1 + audio/headset.c | 1485 +++---------------------------------------- audio/headset.h | 4 + audio/manager.c | 4 +- audio/telephony-builtin.c | 1570 +++++++++++++++++++++++++++++++++++++++++++++ audio/telephony-builtin.h | 218 +++++++ audio/telephony-dbus.c | 554 ++++++++++++++++ audio/telephony-dummy.c | 5 +- audio/telephony-maemo5.c | 5 +- audio/telephony-maemo6.c | 5 +- audio/telephony-ofono.c | 5 +- audio/telephony.h | 225 +------ doc/audio-api.txt | 99 +++ 14 files changed, 2590 insertions(+), 1599 deletions(-) create mode 100644 audio/telephony-builtin.c create mode 100644 audio/telephony-builtin.h create mode 100644 audio/telephony-dbus.c
PATCH 1/4 Audio: move at parsing code to telephony-builtin.[ch] files
--- Makefile.am | 7 +- acinclude.m4 | 1 + audio/headset.c | 1306 +++------------------------------------------ audio/headset.h | 4 + audio/telephony-builtin.c | 1287 ++++++++++++++++++++++++++++++++++++++++++++ audio/telephony-builtin.h | 218 ++++++++ audio/telephony-dummy.c | 1 + audio/telephony-maemo5.c | 1 + audio/telephony-maemo6.c | 1 + audio/telephony-ofono.c | 1 + audio/telephony.h | 207 +------- 11 files changed, 1615 insertions(+), 1419 deletions(-) create mode 100644 audio/telephony-builtin.c create mode 100644 audio/telephony-builtin.h
Makefile.am +6 -1
@@ -157,6 +157,10 @@ builtin_sources += audio/main.c \ audio/telephony.h audio/a2dp-codecs.h builtin_nodist += audio/telephony.c +if TELEPHONYBUILTIN +builtin_sources += audio/telephony-builtin.h audio/telephony-builtin.c +endif + noinst_LIBRARIES += audio/libtelephony.a audio_libtelephony_a_SOURCES = audio/telephony.h audio/telephony-dummy.c \
@@ -340,7 +344,8 @@ EXTRA_DIST += src/genbuiltin src/bluetooth.conf \ audio/audio.conf audio/telephony-dummy.c \ audio/telephony-maemo5.c audio/telephony-ofono.c \ audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c \ - proximity/proximity.conf + proximity/proximity.conf audio/telephony-builtin.h \ + audio/telephony-builtin.c if ALSA alsadir = $(libdir)/alsa-lib
acinclude.m4 +1 -0
@@ -433,4 +433,5 @@ AC_DEFUN([AC_ARG_BLUEZ], [ AM_CONDITIONAL(DBUSOOBPLUGIN, test "${dbusoob_enable}" = "yes") AM_CONDITIONAL(WIIMOTEPLUGIN, test "${wiimote_enable}" = "yes") AM_CONDITIONAL(THERMOMETERPLUGIN, test "${thermometer_enable}" = "yes") + AM_CONDITIONAL(TELEPHONYBUILTIN, test "${telephony_driver}" = "dummy" || test "${telephony_driver}" = "maemo5" || test "${telephony_driver}" = "maemo6" || test "${telephony_driver}" = "ofono") ])
audio/headset.c +77 -1229
1,583 lines not on this page · raw message
audio/headset.h +4 -0
@@ -100,6 +100,7 @@ gboolean headset_get_nrec(struct audio_device *dev);unsigned int headset_add_nrec_cb (struct audio_device *dev,headset_nrec_cb cb,void *user_data);gboolean headset_remove_nrec_cb (struct audio_device *dev,unsigned int id); +void headset_set_nrec (struct audio_device *dev,gboolean state);gboolean headset_get_inband (struct audio_device *dev);gboolean headset_get_sco_hci (struct audio_device *dev);
@@ -111,3 +112,6 @@ gboolean headset_unlock(struct audio_device *dev, headset_lock_t lock);gboolean headset_suspend (struct audio_device *dev,void *data);gboolean headset_play (struct audio_device *dev,void *data);void headset_shutdown (struct audio_device *dev); + +struct at_slc *headset_get_slc (struct audio_device *dev); +void headset_slc_complete (struct audio_device *dev);
audio/telephony-builtin.c new file +1287 -0
1,287 lines not on this page · raw message
audio/telephony-builtin.h new file +218 -0
93 lines not on this page · raw message
audio/telephony.h +18 -189
207 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
PATCH 2/4 Audio: move dbus callbacks to telephony-builtin.c
In reply to Frédéric Danis--- audio/headset.c | 231 ++++++------------------------------ audio/telephony-builtin.c | 291 ++++++++++++++++++++++++++++++++++++++++++++- audio/telephony.h | 24 +++- 3 files changed, 344 insertions(+), 202 deletions(-)
audio/headset.c +36 -193
@@ -59,7 +59,6 @@#include "dbus-common.h" #include "../src/adapter.h" #include "../src/device.h" -#include "telephony-builtin.h" #define DC_TIMEOUT 3
@@ -126,6 +125,7 @@ struct headset {headset_lock_t lock;void *slc;GSList *nrec_cbs; +struct TelephonyDBusTable *dbus_cb; };static GSList *headset_callbacks =NULL ;
@@ -774,34 +774,11 @@ static DBusMessage *hs_ring(DBusConnection *conn, DBusMessage *msg, {struct audio_device *device = data;struct headset *hs = device->headset; -DBusMessage *reply =NULL ; -#if 0 -int err; -#endif - -if (hs->state <HEADSET_STATE_CONNECTED ) -return btd_error_not_connected (msg); - - reply =dbus_message_new_method_return (msg); -if (!reply) -return NULL ; - -if (telephony_is_ringing ()) { -DBG ("IndicateCall received when already indicating" ); -return reply; - } - -#if 0 - err =headset_send (hs,"\r\nRING\r\n" ); -if (err <0 ) { -dbus_message_unref (reply); -return btd_error_failed (msg,strerror (-err)); - } -#endif -telephony_start_ring (hs->slc); +if (hs->dbus_cb ==NULL || hs->dbus_cb->indicate_call ==NULL ) +return btd_error_not_supported (msg); -return reply; +return hs->dbus_cb->indicate_call (conn, msg, hs->slc, hs->state); } static DBusMessage *hs_cancel_call(DBusConnection *conn,
@@ -810,21 +787,11 @@ static DBusMessage *hs_cancel_call(DBusConnection *conn, {struct audio_device *device = data;struct headset *hs = device->headset; -DBusMessage *reply =NULL ; -if (hs->state <HEADSET_STATE_CONNECTED ) -return btd_error_not_connected (msg); +if (hs->dbus_cb ==NULL || hs->dbus_cb->cancel_call ==NULL ) +return btd_error_not_supported (msg); - reply =dbus_message_new_method_return (msg); -if (!reply) -return NULL ; - -if (telephony_is_ringing ()) -telephony_stop_ring (hs->slc); -else -DBG ("Got CancelCall method call but no call is active" ); - -return reply; +return hs->dbus_cb->cancel_call (conn, msg, hs->slc, hs->state); } static DBusMessage *hs_play(DBusConnection *conn, DBusMessage *msg,
@@ -872,22 +839,11 @@ static DBusMessage *hs_get_speaker_gain(DBusConnection *conn, {struct audio_device *device = data;struct headset *hs = device->headset; -DBusMessage *reply; -dbus_uint16_t gain; - -if (hs->state <HEADSET_STATE_CONNECTED ) -return btd_error_not_available (msg); - - reply =dbus_message_new_method_return (msg); -if (!reply) -return NULL ; - gain = (dbus_uint16_t )telephony_get_speaker_gain (hs->slc); +if (hs->dbus_cb ==NULL || hs->dbus_cb->get_speaker_gain ==NULL ) +return btd_error_not_supported (msg); -dbus_message_append_args (reply,DBUS_TYPE_UINT16 , &gain, -DBUS_TYPE_INVALID ); - -return reply; +return hs->dbus_cb->get_speaker_gain (conn, msg, hs->slc, hs->state); } static DBusMessage *hs_get_mic_gain(DBusConnection *conn,
@@ -896,174 +852,61 @@ static DBusMessage *hs_get_mic_gain(DBusConnection *conn, {struct audio_device *device = data;struct headset *hs = device->headset; -DBusMessage *reply; -dbus_uint16_t gain; - -if (hs->state <HEADSET_STATE_CONNECTED || hs->slc ==NULL ) -return btd_error_not_available (msg); - reply =dbus_message_new_method_return (msg); -if (!reply) -return NULL ; - - gain = (dbus_uint16_t )telephony_get_mic_gain (hs->slc); +if (hs->dbus_cb ==NULL || hs->dbus_cb->get_mic_gain ==NULL ) +return btd_error_not_supported (msg); -dbus_message_append_args (reply,DBUS_TYPE_UINT16 , &gain, -DBUS_TYPE_INVALID ); - -return reply; -} - -static DBusMessage *hs_set_gain (DBusConnection *conn, -DBusMessage *msg, -void *data,uint16_t gain, -char type) -{ -struct audio_device *device = data; -struct headset *hs = device->headset; -struct at_slc *slc = hs->slc; -DBusMessage *reply; -int err; - -if (hs->state <HEADSET_STATE_CONNECTED ) -return btd_error_not_connected (msg); - - err =telephony_set_gain (slc, gain, type); -if (err <0 ) -return btd_error_invalid_args (msg); - - reply =dbus_message_new_method_return (msg); -if (!reply) -return NULL ; - -if (hs->state ==HEADSET_STATE_PLAYING ) { - err =telephony_send_gain (slc, type, gain); -if (err <0 ) { -dbus_message_unref (reply); -return btd_error_failed (msg,strerror (-err)); - } - } - -return reply; +return hs->dbus_cb->get_mic_gain (conn, msg, hs->slc, hs->state); }static DBusMessage *hs_set_speaker_gain (DBusConnection *conn,DBusMessage *msg,void *data) { -uint16_t gain; +struct audio_device *device = data; +struct headset *hs = device->headset; -if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_UINT16 , &gain, -DBUS_TYPE_INVALID )) -return NULL ; +if (hs->dbus_cb ==NULL || hs->dbus_cb->set_speaker_gain ==NULL ) +return btd_error_not_supported (msg); -return hs_set_gain (conn, msg, data, gain,HEADSET_GAIN_SPEAKER ); +return hs->dbus_cb->set_speaker_gain (conn, msg, hs->slc, hs->state); }static DBusMessage *hs_set_mic_gain (DBusConnection *conn,DBusMessage *msg,void *data) { -uint16_t gain; +struct audio_device *device = data; +struct headset *hs = device->headset; -if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_UINT16 , &gain, -DBUS_TYPE_INVALID )) -return NULL ; +if (hs->dbus_cb ==NULL || hs->dbus_cb->set_mic_gain ==NULL ) +return btd_error_not_supported (msg); -return hs_set_gain (conn, msg, data, gain,HEADSET_GAIN_MICROPHONE ); +return hs->dbus_cb->set_mic_gain (conn, msg, hs->slc, hs->state); }static DBusMessage *hs_get_properties (DBusConnection *conn,DBusMessage *msg,void *data) {struct audio_device *device = data; -DBusMessage *reply; -DBusMessageIter iter; -DBusMessageIter dict; -gboolean value; -const char *state; -int gain; - - reply =dbus_message_new_method_return (msg); -if (!reply) -return NULL ; - -dbus_message_iter_init_append (reply, &iter); - -dbus_message_iter_open_container (&iter,DBUS_TYPE_ARRAY , -DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING - DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); - - -/* Playing */ - value = (device->headset->state ==HEADSET_STATE_PLAYING ); -dict_append_entry (&dict,"Playing" ,DBUS_TYPE_BOOLEAN , &value); - -/* State */ - state =state2str (device->headset->state); -if (state) -dict_append_entry (&dict,"State" ,DBUS_TYPE_STRING , &state); - -/* Connected */ - value = (device->headset->state >=HEADSET_STATE_CONNECTED ); -dict_append_entry (&dict,"Connected" ,DBUS_TYPE_BOOLEAN , &value); - -if (!value) - goto done; - -/* SpeakerGain */ - gain =telephony_get_speaker_gain (device->headset->slc); -dict_append_entry (&dict,"SpeakerGain" ,DBUS_TYPE_UINT16 , &gain); +struct headset *hs = device->headset; -/* MicrophoneGain */ - gain =telephony_get_mic_gain (device->headset->slc); -dict_append_entry (&dict,"MicrophoneGain" ,DBUS_TYPE_UINT16 , &gain); +if (hs->dbus_cb ==NULL || hs->dbus_cb->get_properties ==NULL ) +return btd_error_not_supported (msg); -done: -dbus_message_iter_close_container (&iter, &dict); - -return reply; +return hs->dbus_cb->get_properties (conn, msg, hs->slc, hs->state); }static DBusMessage *hs_set_property (DBusConnection *conn,DBusMessage *msg,void *data) { -const char *property; -DBusMessageIter iter; -DBusMessageIter sub; -uint16_t gain; - -if (!dbus_message_iter_init (msg, &iter)) -return btd_error_invalid_args (msg); - -if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) -return btd_error_invalid_args (msg); - -dbus_message_iter_get_basic (&iter, &property); -dbus_message_iter_next (&iter); - -if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_VARIANT ) -return btd_error_invalid_args (msg); -dbus_message_iter_recurse (&iter, &sub); - -if (g_str_equal ("SpeakerGain" , property)) { -if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_UINT16 ) -return btd_error_invalid_args (msg); - -dbus_message_iter_get_basic (&sub, &gain); -return hs_set_gain (conn, msg, data, gain, -HEADSET_GAIN_SPEAKER ); - }else if (g_str_equal ("MicrophoneGain" , property)) { -if (dbus_message_iter_get_arg_type (&sub) !=DBUS_TYPE_UINT16 ) -return btd_error_invalid_args (msg); +struct audio_device *device = data; +struct headset *hs = device->headset; -dbus_message_iter_get_basic (&sub, &gain); -return hs_set_gain (conn, msg, data, gain, -HEADSET_GAIN_MICROPHONE ); - } +if (hs->dbus_cb ==NULL || hs->dbus_cb->set_property ==NULL ) +return btd_error_not_supported (msg); -return btd_error_invalid_args (msg); +return hs->dbus_cb->set_property (conn, msg, hs->slc, hs->state); }static GDBusMethodTable headset_methods[] = {
@@ -1236,6 +1079,8 @@ struct headset *headset_init(struct audio_device *dev, uint16_t svc, } register_iface: + hs->dbus_cb =telephony_dbus_table (); + if (!g_dbus_register_interface(dev->conn, dev->path, AUDIO_HEADSET_INTERFACE, headset_methods, headset_signals, NULL,
@@ -1608,13 +1453,11 @@ void headset_set_state(struct audio_device *dev, headset_state_t state) gain =telephony_get_speaker_gain (hs->slc);if (gain >=0 ) -telephony_send_gain (hs->slc,HEADSET_GAIN_SPEAKER , - gain); +telephony_send_speaker_gain (hs->slc, gain); gain =telephony_get_mic_gain (hs->slc);if (gain >=0 ) -telephony_send_gain (hs->slc,HEADSET_GAIN_MICROPHONE , - gain); +telephony_send_mic_gain (hs->slc, gain);break ; }
audio/telephony-builtin.c +287 -4
328 lines not on this page · raw message
audio/telephony.h +20 -4
@@ -57,8 +57,6 @@ void telephony_device_set_active(void *telephony_device, gboolean active);gboolean telephony_get_ready_state (void );gboolean telephony_pending_ring (void *slc);void telephony_start_ring (void *slc); -void telephony_stop_ring (void *slc); -gboolean telephony_is_ringing (void );uint32_t telephony_get_ag_features (void );void telephony_set_fast_connectable (gboolean state);gboolean telephony_get_nrec (void *slc);
@@ -66,8 +64,26 @@ gboolean telephony_get_inband_ringtone(void *slc);void telephony_set_inband_ringtone (void *slc,gboolean state);int telephony_get_speaker_gain (void *slc);int telephony_get_mic_gain (void *slc); -int telephony_send_gain (void *slc,char type,uint16_t gain); -int telephony_set_gain (void *slc,uint16_t gain,char type); +int telephony_send_speaker_gain (void *slc,uint16_t gain); +int telephony_send_mic_gain (void *slc,uint16_t gain); + +/* DBus interface functions. Implemented by telephony-*.c */ +typedef DBusMessage * (*telephony_dbus_cb )(DBusConnection *conn, +DBusMessage *msg, +void *slc,int state); + +struct TelephonyDBusTable { +telephony_dbus_cb indicate_call; +telephony_dbus_cb cancel_call; +telephony_dbus_cb get_speaker_gain; +telephony_dbus_cb set_speaker_gain; +telephony_dbus_cb get_mic_gain; +telephony_dbus_cb set_mic_gain; +telephony_dbus_cb get_properties; +telephony_dbus_cb set_property; +}; + +struct TelephonyDBusTable *telephony_dbus_table (void );int telephony_init (void );void telephony_exit (void );
Signature · 1 line
1.7.1
PATCH 3/4 Audio: add adapter to telephony_init/_exit
In reply to Frédéric Danis--- audio/manager.c | 4 ++-- audio/telephony-dummy.c | 4 ++-- audio/telephony-maemo5.c | 4 ++-- audio/telephony-maemo6.c | 4 ++-- audio/telephony-ofono.c | 4 ++-- audio/telephony.h | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-)
audio/manager.c +2 -2
@@ -881,7 +881,7 @@ static void state_changed(struct btd_adapter *adapter, gboolean powered)/* telephony driver already initialized*/ if (telephony == TRUE)return ; -telephony_init (); +telephony_init (adapter); telephony = TRUE;return ; }
@@ -897,7 +897,7 @@ static void state_changed(struct btd_adapter *adapter, gboolean powered)return ; } -telephony_exit (); +telephony_exit (adapter); telephony = FALSE; }
audio/telephony-dummy.c +2 -2
@@ -396,7 +396,7 @@ static GDBusSignalTable dummy_signals[] = { { } }; -int telephony_init (void ) +int telephony_init (void *adapter) {uint32_t features =AG_FEATURE_REJECT_A_CALL | AG_FEATURE_ENHANCED_CALL_STATUS |
@@ -421,7 +421,7 @@ int telephony_init(void)return 0 ; } -void telephony_exit (void ) +void telephony_exit (void *adapter) {DBG ("" );
audio/telephony-maemo5.c +2 -2
@@ -2029,7 +2029,7 @@ static DBusHandlerResult signal_filter(DBusConnection *conn,return DBUS_HANDLER_RESULT_NOT_YET_HANDLED ; } -int telephony_init (void ) +int telephony_init (void *adapter) {const char *battery_cap ="battery" ; uint32_t features = AG_FEATURE_EC_ANDOR_NR |
@@ -2090,7 +2090,7 @@ int telephony_init(void)return 0 ; } -void telephony_exit (void ) +void telephony_exit (void *adapter) {g_slist_foreach (calls, (GFunc ) csd_call_free,NULL );g_slist_free (calls);
audio/telephony-maemo6.c +2 -2
@@ -2110,7 +2110,7 @@ done:remove_pending (call); } -int telephony_init (void ) +int telephony_init (void *adapter) {const char *battery_cap ="battery" ; uint32_t features = AG_FEATURE_EC_ANDOR_NR |
@@ -2166,7 +2166,7 @@ static void remove_watch(gpointer data)g_dbus_remove_watch (connection,GPOINTER_TO_UINT (data)); } -void telephony_exit (void ) +void telephony_exit (void *adapter) {DBG ("" );
audio/telephony-ofono.c +2 -2
@@ -1546,7 +1546,7 @@ static void handle_service_disconnect(DBusConnection *conn, void *user_data)modem_removed (modem_obj_path); } -int telephony_init (void ) +int telephony_init (void *adapter) {uint32_t features =AG_FEATURE_EC_ANDOR_NR | AG_FEATURE_INBAND_RINGTONE |
@@ -1616,7 +1616,7 @@ static void pending_free(void *data)dbus_pending_call_unref (call); } -void telephony_exit (void ) +void telephony_exit (void *adapter) {DBG ("" );
audio/telephony.h +2 -2
@@ -85,5 +85,5 @@ struct TelephonyDBusTable {struct TelephonyDBusTable *telephony_dbus_table (void ); -int telephony_init (void ); -void telephony_exit (void ); +int telephony_init (void *adapter); +void telephony_exit (void *adapter);
Signature · 1 line
1.7.1
PATCH 4/4 Audio: add dbus telephony driver
In reply to Frédéric Danis--- Makefile.am | 4 +- audio/telephony-dbus.c | 554 ++++++++++++++++++++++++++++++++++++++++++++++++ doc/audio-api.txt | 99 +++++++++ 3 files changed, 655 insertions(+), 2 deletions(-) create mode 100644 audio/telephony-dbus.c
Makefile.am +2 -2
@@ -165,7 +165,7 @@ noinst_LIBRARIES += audio/libtelephony.a audio_libtelephony_a_SOURCES = audio/telephony.h audio/telephony-dummy.c \ audio/telephony-maemo5.c audio/telephony-ofono.c \ - audio/telephony-maemo6.c + audio/telephony-maemo6.c audio/telephony-dbus.c endif if SAPPLUGIN
@@ -345,7 +345,7 @@ EXTRA_DIST += src/genbuiltin src/bluetooth.conf \ audio/telephony-maemo5.c audio/telephony-ofono.c \ audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c \ proximity/proximity.conf audio/telephony-builtin.h \ - audio/telephony-builtin.c + audio/telephony-builtin.c audio/telephony-dbus.c if ALSA alsadir = $(libdir)/alsa-lib
audio/telephony-dbus.c new file +554 -0
554 lines not on this page · raw message
doc/audio-api.txt +99 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.1