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;
|
||||
|
||||
Reference in New Issue
Block a user