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:
Evangelos Ribeiro Tzaras
2021-12-10 09:02:39 +01:00
parent ddf1dd7349
commit a048b4c83d
10 changed files with 100 additions and 243 deletions

View File

@@ -15,7 +15,6 @@ enum {
PROP_0,
PROP_NAME,
PROP_ID,
PROP_STATE,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
@@ -26,7 +25,6 @@ struct _CallsMockCall
char *id;
char *display_name;
CallsCallState state;
};
G_DEFINE_TYPE (CallsMockCall, calls_mock_call, CALLS_TYPE_CALL)
@@ -38,7 +36,7 @@ calls_mock_call_answer (CallsCall *call)
g_assert (CALLS_IS_MOCK_CALL (call));
g_assert_cmpint (calls_call_get_state (call), ==, CALLS_CALL_STATE_INCOMING);
calls_mock_call_set_state (CALLS_MOCK_CALL (call), CALLS_CALL_STATE_ACTIVE);
calls_call_set_state (call, CALLS_CALL_STATE_ACTIVE);
}
@@ -48,18 +46,10 @@ calls_mock_call_hang_up (CallsCall *call)
g_assert (CALLS_IS_MOCK_CALL (call));
g_assert_cmpint (calls_call_get_state (call), !=, CALLS_CALL_STATE_DISCONNECTED);
calls_mock_call_set_state (CALLS_MOCK_CALL (call), CALLS_CALL_STATE_DISCONNECTED);
calls_call_set_state (call, CALLS_CALL_STATE_DISCONNECTED);
}
static CallsCallState
calls_mock_call_get_state (CallsCall *call)
{
g_assert (CALLS_IS_MOCK_CALL (call));
return CALLS_MOCK_CALL (call)->state;
}
static void
calls_mock_call_get_property (GObject *object,
guint prop_id,
@@ -75,9 +65,6 @@ calls_mock_call_get_property (GObject *object,
case PROP_NAME:
g_value_set_string (value, self->display_name);
break;
case PROP_STATE:
g_value_set_enum (value, self->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -104,7 +91,6 @@ calls_mock_call_class_init (CallsMockCallClass *klass)
call_class->answer = calls_mock_call_answer;
call_class->hang_up = calls_mock_call_hang_up;
call_class->get_state = calls_mock_call_get_state;
object_class->get_property = calls_mock_call_get_property;
object_class->finalize = calls_mock_call_finalize;
@@ -118,12 +104,6 @@ calls_mock_call_class_init (CallsMockCallClass *klass)
PROP_NAME,
"name");
props[PROP_NAME] = g_object_class_find_property (object_class, "name");
g_object_class_override_property (object_class,
PROP_STATE,
"state");
props[PROP_STATE] = g_object_class_find_property (object_class, "state");
}
@@ -132,14 +112,15 @@ calls_mock_call_init (CallsMockCall *self)
{
self->display_name = g_strdup ("John Doe");
self->id = g_strdup ("0800 1234");
self->state = CALLS_CALL_STATE_INCOMING;
}
CallsMockCall *
calls_mock_call_new (void)
{
return g_object_new (CALLS_TYPE_MOCK_CALL, NULL);
return g_object_new (CALLS_TYPE_MOCK_CALL,
"inbound", TRUE,
NULL);
}
@@ -167,26 +148,3 @@ calls_mock_call_set_name (CallsMockCall *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]);
}
void
calls_mock_call_set_state (CallsMockCall *self,
CallsCallState state)
{
CallsCallState old_state;
g_return_if_fail (CALLS_IS_MOCK_CALL (self));
old_state = self->state;
if (old_state == state)
return;
self->state = state;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATE]);
g_signal_emit_by_name (CALLS_CALL (self),
"state-changed",
state,
old_state);
}

View File

@@ -22,7 +22,5 @@ void calls_mock_call_set_id (CallsMockCall *self,
const char *id);
void calls_mock_call_set_name (CallsMockCall *self,
const char *name);
void calls_mock_call_set_state (CallsMockCall *self,
CallsCallState state);
G_END_DECLS

View File

@@ -251,7 +251,7 @@ test_ringing_accept_call (void **state)
/* delay before completion of __wrap_lfb_event_end_feedback_async() */
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_mock_call_set_state (data->call_one, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_one);
/* main loop will quit in callback of notify::ring */
@@ -302,7 +302,7 @@ test_ringing_hang_up_call (void **state)
/* delay before completion of __wrap_lfb_event_end_feedback_async() */
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_mock_call_set_state (data->call_one, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_one);
/* main loop will quit in callback of notify::ring */
@@ -346,7 +346,7 @@ test_ringing_hang_up_call_ringer_cancelled (void **state)
/* delay before completion of __wrap_lfb_event_trigger_feedback_async() */
will_return (__wrap_lfb_event_trigger_feedback_async, 50);
calls_mock_call_set_state (data->call_one, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_one);
g_timeout_add (10, G_SOURCE_FUNC (t3_on_ringer_timeout), data);
@@ -400,7 +400,7 @@ test_ringing_silence_call (void **state)
/* delay before completion of __wrap_lfb_event_end_feedback_async() */
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_mock_call_set_state (data->call_one, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_one);
/* main loop will quit in callback of notify::ring */
@@ -472,7 +472,7 @@ test_ringing_multiple_calls (void **state)
/* delay before completion of __wrap_lfb_event_end_feedback_async() */
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_mock_call_set_state (data->call_one, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_one);
/* main loop will quit in callback of notify::ring */
@@ -537,9 +537,9 @@ test_ringing_multiple_calls_with_restart (void **state)
/* delay before completion of __wrap_lfb_event_end_feedback_async() */
will_return_always (__wrap_lfb_event_end_feedback_async, 10);
calls_mock_call_set_state (data->call_one, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_one);
calls_mock_call_set_state (data->call_two, CALLS_CALL_STATE_INCOMING);
calls_call_set_state (CALLS_CALL (data->call_two), CALLS_CALL_STATE_INCOMING);
add_call (data->manager, data->call_two);
/* main loop will quit in callback of notify::ring */