bluez5: telephony: implement asynchronous D-Bus calls

This removes the need to call poll() on the rfcomm socket in order
to wait for replies from the AG.

Use a queue to buffer all the commands that are to be sent to the AG
and match them to replies when they are received. Optionally associate
each command with a DBusMessage that is assumed to be a method call
from the telephony interface, which is then replied to when the rfcomm
command reply is received. Also associate each command with a state,
so that it is always deterministic what gets executed after the reply
is received.

On the telephony module, pass on the DBusMessage on the callbacks and
add a method to allow the receiver to send a reply. Only send FAILED
directly when the callback is not handled. Also, remove the return value
from the Dial() command (it was not advertised on the introspection
anyway) to make things easier.
This commit is contained in:
George Kiagiadakis 2025-07-25 22:15:17 +03:00 committed by Wim Taymans
parent 0b647a9009
commit e4b0f68e0b
4 changed files with 369 additions and 628 deletions

View file

@ -67,33 +67,38 @@ struct spa_bt_telephony_ag_callbacks {
#define SPA_VERSION_BT_TELEPHONY_AG_CALLBACKS 0
uint32_t version;
void (*dial)(void *data, const char *number, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*swap_calls)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*release_and_answer)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*release_and_swap)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*hold_and_answer)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*hangup_all)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*create_multiparty)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*send_tones)(void *data, const char *tones, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*dial)(void *data, const char *number, DBusMessage *m);
void (*swap_calls)(void *data, DBusMessage *m);
void (*release_and_answer)(void *data, DBusMessage *m);
void (*release_and_swap)(void *data, DBusMessage *m);
void (*hold_and_answer)(void *data, DBusMessage *m);
void (*hangup_all)(void *data, DBusMessage *m);
void (*create_multiparty)(void *data, DBusMessage *m);
void (*send_tones)(void *data, const char *tones, DBusMessage *m);
void (*transport_activate)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*transport_activate)(void *data, DBusMessage *m);
void (*set_speaker_volume)(void *data, uint8_t volume, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*set_microphone_volume)(void *data, uint8_t volume, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*set_speaker_volume)(void *data, uint8_t volume, DBusMessage *m);
void (*set_microphone_volume)(void *data, uint8_t volume, DBusMessage *m);
};
struct spa_bt_telephony_call_callbacks {
#define SPA_VERSION_BT_TELEPHONY_CALL_CALLBACKS 0
uint32_t version;
void (*answer)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*hangup)(void *data, enum spa_bt_telephony_error *err, uint8_t *cme_error);
void (*answer)(void *data, DBusMessage *m);
void (*hangup)(void *data, DBusMessage *m);
};
struct spa_bt_telephony *telephony_new(struct spa_log *log, struct spa_dbus *dbus,
const struct spa_dict *info);
void telephony_free(struct spa_bt_telephony *telephony);
/* send a reply to any of the methods (they all return void);
this is must be called from the callbacks either in sync or async */
void telephony_send_dbus_method_reply(struct spa_bt_telephony *telephony,
DBusMessage *m, enum spa_bt_telephony_error err, uint8_t cme_error);
/* create/destroy the ag object */
struct spa_bt_telephony_ag * telephony_ag_new(struct spa_bt_telephony *telephony,