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:
@@ -33,7 +33,6 @@ struct _CallsDummyCall
|
||||
{
|
||||
GObject parent_instance;
|
||||
gchar *id;
|
||||
CallsCallState state;
|
||||
};
|
||||
|
||||
static void calls_dummy_call_message_source_interface_init (CallsMessageSourceInterface *iface);
|
||||
@@ -49,25 +48,6 @@ enum {
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
||||
static void
|
||||
change_state (CallsDummyCall *self,
|
||||
CallsCallState state)
|
||||
{
|
||||
CallsCallState 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);
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_dummy_call_get_id (CallsCall *call)
|
||||
{
|
||||
@@ -76,14 +56,6 @@ calls_dummy_call_get_id (CallsCall *call)
|
||||
return self->id;
|
||||
}
|
||||
|
||||
static CallsCallState
|
||||
calls_dummy_call_get_state (CallsCall *call)
|
||||
{
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
|
||||
|
||||
return self->state;
|
||||
}
|
||||
|
||||
static const char*
|
||||
calls_dummy_call_get_protocol (CallsCall *call)
|
||||
{
|
||||
@@ -93,25 +65,18 @@ calls_dummy_call_get_protocol (CallsCall *call)
|
||||
static void
|
||||
calls_dummy_call_answer (CallsCall *call)
|
||||
{
|
||||
CallsDummyCall *self;
|
||||
|
||||
g_return_if_fail (CALLS_IS_DUMMY_CALL (call));
|
||||
self = CALLS_DUMMY_CALL (call);
|
||||
g_return_if_fail (calls_call_get_state (call) == CALLS_CALL_STATE_INCOMING);
|
||||
|
||||
g_return_if_fail (self->state == CALLS_CALL_STATE_INCOMING);
|
||||
|
||||
change_state (self, CALLS_CALL_STATE_ACTIVE);
|
||||
calls_call_set_state (call, CALLS_CALL_STATE_ACTIVE);
|
||||
}
|
||||
|
||||
static void
|
||||
calls_dummy_call_hang_up (CallsCall *call)
|
||||
{
|
||||
CallsDummyCall *self;
|
||||
|
||||
g_return_if_fail (CALLS_IS_DUMMY_CALL (call));
|
||||
self = CALLS_DUMMY_CALL (call);
|
||||
|
||||
change_state (self, CALLS_CALL_STATE_DISCONNECTED);
|
||||
calls_call_set_state (call, CALLS_CALL_STATE_DISCONNECTED);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -124,17 +89,21 @@ calls_dummy_call_send_dtmf_tone (CallsCall *call,
|
||||
static gboolean
|
||||
outbound_timeout_cb (CallsDummyCall *self)
|
||||
{
|
||||
switch (self->state) {
|
||||
CallsCall *call;
|
||||
|
||||
g_assert (CALLS_IS_DUMMY_CALL (self));
|
||||
|
||||
call = CALLS_CALL (self);
|
||||
|
||||
switch (calls_call_get_state (call)) {
|
||||
case CALLS_CALL_STATE_DIALING:
|
||||
change_state (self,
|
||||
CALLS_CALL_STATE_ALERTING);
|
||||
calls_call_set_state (call, CALLS_CALL_STATE_ALERTING);
|
||||
g_timeout_add_seconds
|
||||
(3, (GSourceFunc)outbound_timeout_cb, self);
|
||||
break;
|
||||
|
||||
case CALLS_CALL_STATE_ALERTING:
|
||||
change_state (self,
|
||||
CALLS_CALL_STATE_ACTIVE);
|
||||
calls_call_set_state (call, CALLS_CALL_STATE_ACTIVE);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -183,12 +152,8 @@ constructed (GObject *object)
|
||||
{
|
||||
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
||||
|
||||
if (calls_call_get_inbound (CALLS_CALL (object))) {
|
||||
self->state = CALLS_CALL_STATE_INCOMING;
|
||||
} else {
|
||||
self->state = CALLS_CALL_STATE_DIALING;
|
||||
if (!calls_call_get_inbound (CALLS_CALL (object)))
|
||||
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object);
|
||||
}
|
||||
@@ -215,7 +180,6 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
||||
object_class->finalize = finalize;
|
||||
|
||||
call_class->get_id = calls_dummy_call_get_id;
|
||||
call_class->get_state = calls_dummy_call_get_state;
|
||||
call_class->get_protocol = calls_dummy_call_get_protocol;
|
||||
call_class->answer = calls_dummy_call_answer;
|
||||
call_class->hang_up = calls_dummy_call_hang_up;
|
||||
|
||||
@@ -38,7 +38,6 @@ struct _CallsMMCall
|
||||
GObject parent_instance;
|
||||
MMCall *mm_call;
|
||||
GString *id;
|
||||
CallsCallState state;
|
||||
gchar *disconnect_reason;
|
||||
};
|
||||
|
||||
@@ -55,26 +54,6 @@ enum {
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
||||
static void
|
||||
change_state (CallsMMCall *self,
|
||||
CallsCallState state)
|
||||
{
|
||||
CallsCallState 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);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
notify_id_cb (CallsMMCall *self,
|
||||
const gchar *id)
|
||||
@@ -185,7 +164,7 @@ state_changed_cb (CallsMMCall *self,
|
||||
{
|
||||
g_debug ("MM call state changed to `%s'",
|
||||
map_row->name);
|
||||
change_state (self, map_row->calls);
|
||||
calls_call_set_state (CALLS_CALL (self), map_row->calls);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -199,14 +178,6 @@ calls_mm_call_get_id (CallsCall *call)
|
||||
return self->id->str;
|
||||
}
|
||||
|
||||
static CallsCallState
|
||||
calls_mm_call_get_state (CallsCall *call)
|
||||
{
|
||||
CallsMMCall *self = CALLS_MM_CALL (call);
|
||||
|
||||
return self->state;
|
||||
}
|
||||
|
||||
|
||||
static const char *
|
||||
calls_mm_call_get_protocol (CallsCall *self)
|
||||
@@ -369,7 +340,6 @@ calls_mm_call_class_init (CallsMMCallClass *klass)
|
||||
object_class->finalize = finalize;
|
||||
|
||||
call_class->get_id = calls_mm_call_get_id;
|
||||
call_class->get_state = calls_mm_call_get_state;
|
||||
call_class->get_protocol = calls_mm_call_get_protocol;
|
||||
call_class->answer = calls_mm_call_answer;
|
||||
call_class->hang_up = calls_mm_call_hang_up;
|
||||
|
||||
@@ -37,7 +37,6 @@ struct _CallsOfonoCall
|
||||
GDBOVoiceCall *voice_call;
|
||||
gchar *id;
|
||||
gchar *name;
|
||||
CallsCallState state;
|
||||
gchar *disconnect_reason;
|
||||
};
|
||||
|
||||
@@ -61,25 +60,6 @@ enum {
|
||||
};
|
||||
static guint signals [SIGNAL_LAST_SIGNAL];
|
||||
|
||||
static void
|
||||
change_state (CallsOfonoCall *self,
|
||||
CallsCallState state)
|
||||
{
|
||||
CallsCallState 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);
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_ofono_call_get_id (CallsCall *call)
|
||||
{
|
||||
@@ -96,14 +76,6 @@ calls_ofono_call_get_name (CallsCall *call)
|
||||
return self->name;
|
||||
}
|
||||
|
||||
static CallsCallState
|
||||
calls_ofono_call_get_state (CallsCall *call)
|
||||
{
|
||||
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
||||
|
||||
return self->state;
|
||||
}
|
||||
|
||||
static const char *
|
||||
calls_ofono_call_get_protocol (CallsCall *call)
|
||||
{
|
||||
@@ -178,7 +150,7 @@ static void
|
||||
calls_ofono_call_send_dtmf_tone (CallsCall *call, gchar key)
|
||||
{
|
||||
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
||||
if (self->state != CALLS_CALL_STATE_ACTIVE) {
|
||||
if (calls_call_get_state (call) != CALLS_CALL_STATE_ACTIVE) {
|
||||
g_warning ("Tone start requested for non-active call to `%s'",
|
||||
self->id);
|
||||
return;
|
||||
@@ -192,6 +164,7 @@ static void
|
||||
set_properties (CallsOfonoCall *self,
|
||||
GVariant *call_props)
|
||||
{
|
||||
CallsCallState state;
|
||||
const gchar *str = NULL;
|
||||
|
||||
g_return_if_fail (call_props != NULL);
|
||||
@@ -201,7 +174,8 @@ set_properties (CallsOfonoCall *self,
|
||||
|
||||
g_variant_lookup (call_props, "State", "&s", &str);
|
||||
g_return_if_fail (str != NULL);
|
||||
calls_call_state_parse_nick (&self->state, str);
|
||||
if (calls_call_state_parse_nick (&state, str))
|
||||
calls_call_set_state (CALLS_CALL (self), state);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +226,7 @@ property_changed_cb (CallsOfonoCall *self,
|
||||
|
||||
ok = calls_call_state_parse_nick (&state, str);
|
||||
if (ok)
|
||||
change_state (self, state);
|
||||
calls_call_set_state (CALLS_CALL (self), state);
|
||||
else
|
||||
g_warning ("Could not parse new state `%s'"
|
||||
" of oFono call to `%s'",
|
||||
@@ -329,7 +303,6 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
|
||||
|
||||
call_class->get_id = calls_ofono_call_get_id;
|
||||
call_class->get_name = calls_ofono_call_get_name;
|
||||
call_class->get_state = calls_ofono_call_get_state;
|
||||
call_class->get_protocol = calls_ofono_call_get_protocol;
|
||||
call_class->answer = calls_ofono_call_answer;
|
||||
call_class->hang_up = calls_ofono_call_hang_up;
|
||||
@@ -407,7 +380,7 @@ calls_ofono_call_new (GDBOVoiceCall *voice_call,
|
||||
//"id", id,
|
||||
//"name", name,
|
||||
"inbound", inbound,
|
||||
//"state", state,
|
||||
"state", state,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -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