commit 4d14f67cd579bf4831293b75b4f24a135cff05b3
parent eb48b0fb4f5e61a5a4b65378a647b7717b011020
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 7 Dec 2013 21:01:44 +0000
-perform mic/speaker operations before event callbacks
Diffstat:
2 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
@@ -560,6 +560,34 @@ phone_error_handler (void *cls,
/**
+ * Clean up all callers of the given phone.
+ *
+ * @param phone phone to clean up callers for
+ */
+static void
+clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone)
+{
+ struct GNUNET_CONVERSATION_Caller *caller;
+
+ while (NULL != (caller = phone->caller_head))
+ {
+ /* make sure mic/speaker are disabled *before* callback */
+ if (CS_ACTIVE == caller->state)
+ {
+ caller->speaker->disable_speaker (caller->speaker->cls);
+ caller->mic->disable_microphone (caller->mic->cls);
+ caller->state = CS_CALLER_SUSPENDED;
+ }
+ phone->event_handler (phone->event_handler_cls,
+ GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
+ caller,
+ caller->caller_id_str);
+ GNUNET_CONVERSATION_caller_hang_up (caller);
+ }
+}
+
+
+/**
* The phone got disconnected, reconnect to the service.
*
* @param phone phone to reconnect
@@ -588,16 +616,8 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
};
struct GNUNET_MQ_Envelope *e;
struct ClientPhoneRegisterMessage *reg;
- struct GNUNET_CONVERSATION_Caller *caller;
- while (NULL != (caller = phone->caller_head))
- {
- phone->event_handler (phone->event_handler_cls,
- GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
- caller,
- caller->caller_id_str);
- GNUNET_CONVERSATION_caller_hang_up (caller);
- }
+ clean_up_callers (phone);
if (NULL != phone->mq)
{
GNUNET_MQ_destroy (phone->mq);
@@ -766,7 +786,8 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
caller);
GNUNET_free_non_null (caller->caller_id_str);
GNUNET_free (caller);
- e = GNUNET_MQ_msg (hang, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
+ e = GNUNET_MQ_msg (hang,
+ GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
GNUNET_MQ_send (phone->mq, e);
}
@@ -779,16 +800,7 @@ GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
void
GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone)
{
- struct GNUNET_CONVERSATION_Caller *caller;
-
- while (NULL != (caller = phone->caller_head))
- {
- phone->event_handler (phone->event_handler_cls,
- GNUNET_CONVERSATION_EC_PHONE_HUNG_UP,
- caller,
- caller->caller_id_str);
- GNUNET_CONVERSATION_caller_hang_up (caller);
- }
+ clean_up_callers (phone);
if (NULL != phone->ns)
{
GNUNET_NAMESTORE_disconnect (phone->ns);
diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c
@@ -215,10 +215,10 @@ handle_call_suspend (void *cls,
break;
case CS_ACTIVE:
call->state = CS_SUSPENDED_CALLEE;
- call->event_handler (call->event_handler_cls,
- GNUNET_CONVERSATION_EC_CALL_SUSPENDED);
call->speaker->disable_speaker (call->speaker->cls);
call->mic->disable_microphone (call->mic->cls);
+ call->event_handler (call->event_handler_cls,
+ GNUNET_CONVERSATION_EC_CALL_SUSPENDED);
break;
case CS_SHUTDOWN:
GNUNET_CONVERSATION_call_stop (call);
@@ -328,6 +328,8 @@ handle_call_hangup (void *cls,
const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CONVERSATION_Call *call = cls;
+ GNUNET_CONVERSATION_CallEventHandler eh;
+ void *eh_cls;
switch (call->state)
{
@@ -340,9 +342,10 @@ handle_call_hangup (void *cls,
case CS_SUSPENDED_CALLEE:
case CS_SUSPENDED_BOTH:
case CS_ACTIVE:
- call->event_handler (call->event_handler_cls,
- GNUNET_CONVERSATION_EC_CALL_HUNG_UP);
+ eh = call->event_handler;
+ eh_cls = call->event_handler_cls;
GNUNET_CONVERSATION_call_stop (call);
+ eh (eh_cls, GNUNET_CONVERSATION_EC_CALL_HUNG_UP);
return;
case CS_SHUTDOWN:
GNUNET_CONVERSATION_call_stop (call);