From 7c10db26c20cd39862059e08ddd237e6eeb406d0 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Thu, 14 Jun 2018 14:43:10 +0200 Subject: base-call: setup/cleanup custom events when transitioning to/from in-call --- src/mm-base-call.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/mm-base-call.c') diff --git a/src/mm-base-call.c b/src/mm-base-call.c index c28ce476..9e0673de 100644 --- a/src/mm-base-call.c +++ b/src/mm-base-call.c @@ -539,18 +539,42 @@ mm_base_call_get_path (MMBaseCall *self) return self->priv->path; } +/* Define the states in which we want to handle in-call events */ +#define MM_CALL_STATE_IS_IN_CALL(state) \ + (state == MM_CALL_STATE_DIALING || \ + state == MM_CALL_STATE_RINGING_OUT || \ + state == MM_CALL_STATE_ACTIVE) + void -mm_base_call_change_state (MMBaseCall *self, - MMCallState new_state, - MMCallStateReason reason) +mm_base_call_change_state (MMBaseCall *self, + MMCallState new_state, + MMCallStateReason reason) { - MMCallState old_state; + MMCallState old_state; + GError *error = NULL; old_state = mm_gdbus_call_get_state (MM_GDBUS_CALL (self)); if (old_state == new_state) return; + /* Setup/cleanup unsolicited events based on state transitions to/from ACTIVE */ + if (!MM_CALL_STATE_IS_IN_CALL (old_state) && MM_CALL_STATE_IS_IN_CALL (new_state)) { + mm_dbg ("Setting up in-call unsolicited events..."); + if (MM_BASE_CALL_GET_CLASS (self)->setup_unsolicited_events && + !MM_BASE_CALL_GET_CLASS (self)->setup_unsolicited_events (self, &error)) { + mm_warn ("Couldn't setup in-call unsolicited events: %s", error->message); + g_error_free (error); + } + } else if (MM_CALL_STATE_IS_IN_CALL (old_state) && !MM_CALL_STATE_IS_IN_CALL (new_state)) { + mm_dbg ("Cleaning up in-call unsolicited events..."); + if (MM_BASE_CALL_GET_CLASS (self)->cleanup_unsolicited_events && + !MM_BASE_CALL_GET_CLASS (self)->cleanup_unsolicited_events (self, &error)) { + mm_warn ("Couldn't cleanup in-call unsolicited events: %s", error->message); + g_error_free (error); + } + } + mm_gdbus_call_set_state (MM_GDBUS_CALL (self), new_state); mm_gdbus_call_set_state_reason (MM_GDBUS_CALL (self), reason); mm_gdbus_call_emit_state_changed (MM_GDBUS_CALL (self), old_state, new_state, reason); -- cgit v1.2.3-70-g09d2