call: Move inbound property into base class

This avoids some repetition in the derived classes.
This commit is contained in:
Evangelos Ribeiro Tzaras
2021-12-10 08:00:11 +01:00
parent 88cd7ce222
commit ddf1dd7349
7 changed files with 66 additions and 89 deletions

View File

@@ -33,7 +33,6 @@ struct _CallsDummyCall
{
GObject parent_instance;
gchar *id;
gboolean inbound;
CallsCallState state;
};
@@ -46,7 +45,6 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, CALLS_TYPE_CALL,
enum {
PROP_0,
PROP_ID_CONSTRUCTOR,
PROP_INBOUND_CONSTRUCTOR,
PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];
@@ -86,14 +84,6 @@ calls_dummy_call_get_state (CallsCall *call)
return self->state;
}
static gboolean
calls_dummy_call_get_inbound (CallsCall *call)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
return self->inbound;
}
static const char*
calls_dummy_call_get_protocol (CallsCall *call)
{
@@ -163,7 +153,7 @@ calls_dummy_call_new (const gchar *id,
return g_object_new (CALLS_TYPE_DUMMY_CALL,
"id-constructor", id,
"inbound-constructor", inbound,
"inbound", inbound,
NULL);
}
@@ -181,10 +171,6 @@ set_property (GObject *object,
self->id = g_value_dup_string (value);
break;
case PROP_INBOUND_CONSTRUCTOR:
self->inbound = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -197,15 +183,12 @@ constructed (GObject *object)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
if (self->inbound)
{
self->state = CALLS_CALL_STATE_INCOMING;
}
else
{
self->state = CALLS_CALL_STATE_DIALING;
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
}
if (calls_call_get_inbound (CALLS_CALL (object))) {
self->state = CALLS_CALL_STATE_INCOMING;
} else {
self->state = CALLS_CALL_STATE_DIALING;
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
}
G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object);
}
@@ -233,7 +216,6 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
call_class->get_id = calls_dummy_call_get_id;
call_class->get_state = calls_dummy_call_get_state;
call_class->get_inbound = calls_dummy_call_get_inbound;
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;
@@ -246,14 +228,6 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
"+441234567890",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_ID_CONSTRUCTOR, props[PROP_ID_CONSTRUCTOR]);
props[PROP_INBOUND_CONSTRUCTOR] =
g_param_spec_boolean ("inbound-constructor",
"Inbound (constructor)",
"Whether the calls is inbound (dummy class constructor)",
FALSE,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_INBOUND_CONSTRUCTOR, props[PROP_INBOUND_CONSTRUCTOR]);
}
static void

View File

@@ -207,16 +207,6 @@ calls_mm_call_get_state (CallsCall *call)
return self->state;
}
static gboolean
calls_mm_call_get_inbound (CallsCall *call)
{
CallsMMCall *self = CALLS_MM_CALL (call);
if (self->mm_call)
return mm_call_get_direction (self->mm_call) == MM_CALL_DIRECTION_INCOMING;
return FALSE;
}
static const char *
calls_mm_call_get_protocol (CallsCall *self)
@@ -380,7 +370,6 @@ calls_mm_call_class_init (CallsMMCallClass *klass)
call_class->get_id = calls_mm_call_get_id;
call_class->get_state = calls_mm_call_get_state;
call_class->get_inbound = calls_mm_call_get_inbound;
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;
@@ -410,10 +399,14 @@ calls_mm_call_init (CallsMMCall *self)
CallsMMCall *
calls_mm_call_new (MMCall *mm_call)
{
gboolean inbound;
g_return_val_if_fail (MM_IS_CALL (mm_call), NULL);
inbound = mm_call_get_direction (mm_call) == MM_CALL_DIRECTION_INCOMING;
return g_object_new (CALLS_TYPE_MM_CALL,
"mm-call", mm_call,
"inbound", inbound,
NULL);
}

View File

@@ -39,10 +39,6 @@ struct _CallsOfonoCall
gchar *name;
CallsCallState state;
gchar *disconnect_reason;
/* `inbound` is derived from `state` at construction time.
* If the call was already somehow accepted and thus state=active,
* then it's not possible to know the correct value for `inbound`. */
gboolean inbound;
};
static void calls_ofono_call_message_source_interface_init (CallsMessageSourceInterface *iface);
@@ -108,14 +104,6 @@ calls_ofono_call_get_state (CallsCall *call)
return self->state;
}
static gboolean
calls_ofono_call_get_inbound (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->inbound;
}
static const char *
calls_ofono_call_get_protocol (CallsCall *call)
{
@@ -214,11 +202,6 @@ 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 (self->state == CALLS_CALL_STATE_INCOMING)
{
self->inbound = TRUE;
}
}
@@ -347,7 +330,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_inbound = calls_ofono_call_get_inbound;
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;
@@ -393,14 +375,39 @@ calls_ofono_call_init (CallsOfonoCall *self)
CallsOfonoCall *
calls_ofono_call_new (GDBOVoiceCall *voice_call,
GVariant *properties)
GVariant *call_props)
{
const char *state_str = NULL;
const char *name = NULL;
const char *id = NULL;
CallsCallState state = CALLS_CALL_STATE_UNKNOWN;
gboolean inbound = FALSE;
g_return_val_if_fail (GDBO_IS_VOICE_CALL (voice_call), NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (call_props != NULL, NULL);
/* The following is a copy of set_properties() that we will get rid off
once all properties have been moved */
g_variant_lookup (call_props, "LineIdentification", "s", &id);
g_variant_lookup (call_props, "Name", "s", &name);
g_variant_lookup (call_props, "State", "&s", &state_str);
if (state_str)
calls_call_state_parse_nick (&state, state_str);
/* `inbound` is derived from `state` at construction time.
* If the call was already somehow accepted and thus state=active,
* then it's not possible to know the correct value for `inbound`. */
if (state == CALLS_CALL_STATE_INCOMING)
inbound = TRUE;
return g_object_new (CALLS_TYPE_OFONO_CALL,
"voice-call", voice_call,
"properties", properties,
"properties", call_props,
//"id", id,
//"name", name,
"inbound", inbound,
//"state", state,
NULL);
}

View File

@@ -58,7 +58,6 @@ struct _CallsSipCall
{
GObject parent_instance;
gchar *id;
gboolean inbound;
CallsCallState state;
CallsSipMediaManager *manager;
@@ -135,15 +134,6 @@ calls_sip_call_get_state (CallsCall *call)
}
static gboolean
calls_sip_call_get_inbound (CallsCall *call)
{
CallsSipCall *self = CALLS_SIP_CALL (call);
return self->inbound;
}
static const char *
calls_sip_call_get_protocol (CallsCall *call)
{
@@ -299,7 +289,6 @@ calls_sip_call_class_init (CallsSipCallClass *klass)
call_class->get_id = calls_sip_call_get_id;
call_class->get_state = calls_sip_call_get_state;
call_class->get_inbound = calls_sip_call_get_inbound;
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;
@@ -404,10 +393,10 @@ calls_sip_call_new (const gchar *id,
call = g_object_new (CALLS_TYPE_SIP_CALL,
"nua-handle", handle,
"inbound", inbound,
NULL);
call->id = g_strdup (id);
call->inbound = inbound;
if (inbound)
call->state = CALLS_CALL_STATE_INCOMING;