call: Move state property into base class
This let's us get rid of a lot of duplication in the derived classes. Additionally we set the initial state to CALLS_CALL_STATE_INCOMING if inbound is TRUE and CALLS_CALL_STATE_DIALING otherwise.
This commit is contained in:
@@ -58,7 +58,6 @@ struct _CallsSipCall
|
||||
{
|
||||
GObject parent_instance;
|
||||
gchar *id;
|
||||
CallsCallState state;
|
||||
|
||||
CallsSipMediaManager *manager;
|
||||
CallsSipMediaPipeline *pipeline;
|
||||
@@ -125,15 +124,6 @@ calls_sip_call_get_id (CallsCall *call)
|
||||
}
|
||||
|
||||
|
||||
static CallsCallState
|
||||
calls_sip_call_get_state (CallsCall *call)
|
||||
{
|
||||
CallsSipCall *self = CALLS_SIP_CALL (call);
|
||||
|
||||
return self->state;
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
calls_sip_call_get_protocol (CallsCall *call)
|
||||
{
|
||||
@@ -157,7 +147,7 @@ calls_sip_call_answer (CallsCall *call)
|
||||
|
||||
g_assert (self->nh);
|
||||
|
||||
if (self->state != CALLS_CALL_STATE_INCOMING) {
|
||||
if (calls_call_get_state (CALLS_CALL (self)) != CALLS_CALL_STATE_INCOMING) {
|
||||
g_warning ("Call must be in 'incoming' state in order to answer");
|
||||
return;
|
||||
}
|
||||
@@ -178,7 +168,7 @@ calls_sip_call_answer (CallsCall *call)
|
||||
SOATAG_AF (SOA_AF_IP4_IP6),
|
||||
TAG_END ());
|
||||
|
||||
calls_sip_call_set_state (self, CALLS_CALL_STATE_ACTIVE);
|
||||
calls_call_set_state (CALLS_CALL (self), CALLS_CALL_STATE_ACTIVE);
|
||||
}
|
||||
|
||||
|
||||
@@ -192,7 +182,7 @@ calls_sip_call_hang_up (CallsCall *call)
|
||||
|
||||
self = CALLS_SIP_CALL (call);
|
||||
|
||||
switch (self->state) {
|
||||
switch (calls_call_get_state (call)) {
|
||||
case CALLS_CALL_STATE_DIALING:
|
||||
nua_cancel (self->nh, TAG_END ());
|
||||
g_debug ("Hanging up on outgoing ringing call");
|
||||
@@ -214,7 +204,8 @@ calls_sip_call_hang_up (CallsCall *call)
|
||||
break;
|
||||
|
||||
default:
|
||||
g_warning ("Hanging up not possible in state %d", self->state);
|
||||
g_warning ("Hanging up not possible in state %d",
|
||||
calls_call_get_state (call));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +279,6 @@ calls_sip_call_class_init (CallsSipCallClass *klass)
|
||||
object_class->finalize = calls_sip_call_finalize;
|
||||
|
||||
call_class->get_id = calls_sip_call_get_id;
|
||||
call_class->get_state = calls_sip_call_get_state;
|
||||
call_class->get_protocol = calls_sip_call_get_protocol;
|
||||
call_class->answer = calls_sip_call_answer;
|
||||
call_class->hang_up = calls_sip_call_hang_up;
|
||||
@@ -394,48 +384,14 @@ calls_sip_call_new (const gchar *id,
|
||||
call = g_object_new (CALLS_TYPE_SIP_CALL,
|
||||
"nua-handle", handle,
|
||||
"inbound", inbound,
|
||||
"state", inbound ? CALLS_CALL_STATE_INCOMING : CALLS_CALL_STATE_DIALING,
|
||||
NULL);
|
||||
|
||||
call->id = g_strdup (id);
|
||||
|
||||
if (inbound)
|
||||
call->state = CALLS_CALL_STATE_INCOMING;
|
||||
else
|
||||
call->state = CALLS_CALL_STATE_DIALING;
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_sip_call_set_state:
|
||||
* @self: A #CallsSipCall
|
||||
* @state: The new #CallsCallState to set
|
||||
*
|
||||
* Sets the new call state and emits the state-changed signal
|
||||
*/
|
||||
void
|
||||
calls_sip_call_set_state (CallsSipCall *self,
|
||||
CallsCallState state)
|
||||
{
|
||||
CallsCallState old_state;
|
||||
|
||||
g_return_if_fail (CALLS_IS_CALL (self));
|
||||
g_return_if_fail (CALLS_IS_SIP_CALL (self));
|
||||
|
||||
old_state = self->state;
|
||||
|
||||
if (old_state == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
self->state = state;
|
||||
g_object_notify (G_OBJECT (self), "state");
|
||||
g_signal_emit_by_name (CALLS_CALL (self),
|
||||
"state-changed",
|
||||
state,
|
||||
old_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_sip_call_set_codecs:
|
||||
* @self: A #CallsSipCall
|
||||
|
||||
@@ -575,7 +575,7 @@ sip_i_state (int status,
|
||||
return;
|
||||
}
|
||||
|
||||
calls_sip_call_set_state (call, state);
|
||||
calls_call_set_state (CALLS_CALL (call), state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user