1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2025-01-07 12:25:31 +00:00

Let calls-call be an abstract class

And adapt to changes.

A calls-mm-call IS-A calls-call (and so on)
This commit is contained in:
Mohammed Sadiq 2021-04-05 09:30:10 +05:30
parent a30e1eaa8f
commit c30a41ffa9
10 changed files with 422 additions and 434 deletions

View file

@ -37,25 +37,16 @@ struct _CallsDummyCall
CallsCallState state; CallsCallState state;
}; };
static void calls_dummy_call_message_source_interface_init (CallsCallInterface *iface); static void calls_dummy_call_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_dummy_call_call_interface_init (CallsCallInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, CALLS_TYPE_CALL,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_call_message_source_interface_init) calls_dummy_call_message_source_interface_init))
G_IMPLEMENT_INTERFACE (CALLS_TYPE_CALL,
calls_dummy_call_call_interface_init))
enum { enum {
PROP_0, PROP_0,
PROP_NUMBER_CONSTRUCTOR, PROP_NUMBER_CONSTRUCTOR,
PROP_INBOUND_CONSTRUCTOR, PROP_INBOUND_CONSTRUCTOR,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP PROP_LAST_PROP
}; };
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
@ -73,15 +64,39 @@ change_state (CallsCall *call,
} }
self->state = state; self->state = state;
g_object_notify_by_pspec (G_OBJECT (call), props[PROP_CALL_STATE]); g_object_notify (G_OBJECT (self), "state");
g_signal_emit_by_name (call, g_signal_emit_by_name (call,
"state-changed", "state-changed",
state, state,
old_state); old_state);
} }
static const char *
calls_dummy_call_get_number (CallsCall *call)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
return self->number;
}
static CallsCallState
calls_dummy_call_get_state (CallsCall *call)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
return self->state;
}
static gboolean
calls_dummy_call_get_inbound (CallsCall *call)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (call);
return self->inbound;
}
static void static void
answer (CallsCall *call) calls_dummy_call_answer (CallsCall *call)
{ {
CallsDummyCall *self; CallsDummyCall *self;
@ -94,7 +109,7 @@ answer (CallsCall *call)
} }
static void static void
hang_up (CallsCall *call) calls_dummy_call_hang_up (CallsCall *call)
{ {
CallsDummyCall *self; CallsDummyCall *self;
@ -104,19 +119,6 @@ hang_up (CallsCall *call)
change_state (call, self, CALLS_CALL_STATE_DISCONNECTED); change_state (call, self, CALLS_CALL_STATE_DISCONNECTED);
} }
static void
tone_start (CallsCall *call, gchar key)
{
g_info ("Beep! (%c)", (int)key);
}
static void
tone_stop (CallsCall *call, gchar key)
{
g_info ("Beep end (%c)", (int)key);
}
static gboolean static gboolean
outbound_timeout_cb (CallsDummyCall *self) outbound_timeout_cb (CallsDummyCall *self)
{ {
@ -197,39 +199,6 @@ constructed (GObject *object)
G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object); G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object);
} }
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
switch (property_id) {
case PROP_CALL_INBOUND:
g_value_set_boolean (value, self->inbound);
break;
case PROP_CALL_NUMBER:
g_value_set_string (value, self->number);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
case PROP_CALL_NAME:
g_value_set_string (value, NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void static void
finalize (GObject *object) finalize (GObject *object)
{ {
@ -245,12 +214,18 @@ static void
calls_dummy_call_class_init (CallsDummyCallClass *klass) calls_dummy_call_class_init (CallsDummyCallClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
object_class->get_property = get_property;
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->finalize = finalize; object_class->finalize = finalize;
call_class->get_number = calls_dummy_call_get_number;
call_class->get_state = calls_dummy_call_get_state;
call_class->get_inbound = calls_dummy_call_get_inbound;
call_class->answer = calls_dummy_call_answer;
call_class->hang_up = calls_dummy_call_hang_up;
props[PROP_NUMBER_CONSTRUCTOR] = props[PROP_NUMBER_CONSTRUCTOR] =
g_param_spec_string ("number-constructor", g_param_spec_string ("number-constructor",
"Number (constructor)", "Number (constructor)",
@ -266,32 +241,10 @@ calls_dummy_call_class_init (CallsDummyCallClass *klass)
FALSE, FALSE,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_INBOUND_CONSTRUCTOR, props[PROP_INBOUND_CONSTRUCTOR]); g_object_class_install_property (object_class, PROP_INBOUND_CONSTRUCTOR, props[PROP_INBOUND_CONSTRUCTOR]);
#define IMPLEMENTS(ID, NAME) \
g_object_class_override_property (object_class, ID, NAME); \
props[ID] = g_object_class_find_property(object_class, NAME);
IMPLEMENTS(PROP_CALL_NUMBER, "number");
IMPLEMENTS(PROP_CALL_INBOUND, "inbound");
IMPLEMENTS(PROP_CALL_STATE, "state");
IMPLEMENTS(PROP_CALL_NAME, "name");
#undef IMPLEMENTS
} }
static void static void
calls_dummy_call_call_interface_init (CallsCallInterface *iface) calls_dummy_call_message_source_interface_init (CallsMessageSourceInterface *iface)
{
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;
iface->tone_stop = tone_stop;
}
static void
calls_dummy_call_message_source_interface_init (CallsCallInterface *iface)
{ {
} }

View file

@ -27,11 +27,13 @@
#include <glib-object.h> #include <glib-object.h>
#include "calls-call.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLS_TYPE_DUMMY_CALL (calls_dummy_call_get_type ()) #define CALLS_TYPE_DUMMY_CALL (calls_dummy_call_get_type ())
G_DECLARE_FINAL_TYPE (CallsDummyCall, calls_dummy_call, CALLS, DUMMY_CALL, GObject); G_DECLARE_FINAL_TYPE (CallsDummyCall, calls_dummy_call, CALLS, DUMMY_CALL, CallsCall)
CallsDummyCall *calls_dummy_call_new (const gchar *number, CallsDummyCall *calls_dummy_call_new (const gchar *number,
gboolean inbound); gboolean inbound);

View file

@ -40,24 +40,15 @@ struct _CallsMMCall
gchar *disconnect_reason; gchar *disconnect_reason;
}; };
static void calls_mm_call_message_source_interface_init (CallsCallInterface *iface); static void calls_mm_call_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_mm_call_call_interface_init (CallsCallInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsMMCall, calls_mm_call, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (CallsMMCall, calls_mm_call, CALLS_TYPE_CALL,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_mm_call_message_source_interface_init) calls_mm_call_message_source_interface_init))
G_IMPLEMENT_INTERFACE (CALLS_TYPE_CALL,
calls_mm_call_call_interface_init))
enum { enum {
PROP_0, PROP_0,
PROP_MM_CALL, PROP_MM_CALL,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP, PROP_LAST_PROP,
}; };
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
@ -74,7 +65,7 @@ change_state (CallsMMCall *self,
} }
self->state = state; self->state = state;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_STATE]); g_object_notify (G_OBJECT (self), "state");
g_signal_emit_by_name (CALLS_CALL (self), g_signal_emit_by_name (CALLS_CALL (self),
"state-changed", "state-changed",
state, state,
@ -87,7 +78,7 @@ notify_number_cb (CallsMMCall *self,
const gchar *number) const gchar *number)
{ {
g_string_assign (self->number, number); g_string_assign (self->number, number);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_NUMBER]); g_object_notify (G_OBJECT (self), "number");
} }
@ -198,6 +189,32 @@ state_changed_cb (CallsMMCall *self,
} }
} }
static const char *
calls_mm_call_get_number (CallsCall *call)
{
CallsMMCall *self = CALLS_MM_CALL (call);
return self->number->str;
}
static CallsCallState
calls_mm_call_get_state (CallsCall *call)
{
CallsMMCall *self = CALLS_MM_CALL (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;
}
struct CallsMMOperationData struct CallsMMOperationData
{ {
@ -244,13 +261,13 @@ operation_cb (MMCall *mm_call,
data); \ data); \
} }
DEFINE_OPERATION(accept, answer, "accepting"); DEFINE_OPERATION(accept, calls_mm_call_answer, "accepting");
DEFINE_OPERATION(hangup, hang_up, "hanging up"); DEFINE_OPERATION(hangup, calls_mm_call_hang_up, "hanging up");
DEFINE_OPERATION(start, start_call, "starting outgoing call"); DEFINE_OPERATION(start, calls_mm_call_start_call, "starting outgoing call");
static void static void
tone_start (CallsCall *call, gchar key) calls_mm_call_tone_start (CallsCall *call, gchar key)
{ {
CallsMMCall *self = CALLS_MM_CALL (call); CallsMMCall *self = CALLS_MM_CALL (call);
struct CallsMMOperationData *data; struct CallsMMOperationData *data;
@ -315,47 +332,12 @@ constructed (GObject *object)
if (state == MM_CALL_STATE_UNKNOWN if (state == MM_CALL_STATE_UNKNOWN
&& mm_call_get_direction (self->mm_call) == MM_CALL_DIRECTION_OUTGOING) && mm_call_get_direction (self->mm_call) == MM_CALL_DIRECTION_OUTGOING)
{ {
start_call (CALLS_CALL (self)); calls_mm_call_start_call (CALLS_CALL (self));
} }
G_OBJECT_CLASS (calls_mm_call_parent_class)->constructed (object); G_OBJECT_CLASS (calls_mm_call_parent_class)->constructed (object);
} }
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsMMCall *self = CALLS_MM_CALL (object);
switch (property_id) {
case PROP_CALL_INBOUND:
g_value_set_boolean (value,
mm_call_get_direction (self->mm_call)
== MM_CALL_DIRECTION_INCOMING);
break;
case PROP_CALL_NAME:
g_value_set_string(value, NULL);
break;
case PROP_CALL_NUMBER:
g_value_set_string(value, self->number->str);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void static void
dispose (GObject *object) dispose (GObject *object)
{ {
@ -383,48 +365,34 @@ static void
calls_mm_call_class_init (CallsMMCallClass *klass) calls_mm_call_class_init (CallsMMCallClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
object_class->get_property = get_property;
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->finalize = finalize; object_class->finalize = finalize;
call_class->get_number = calls_mm_call_get_number;
call_class->get_state = calls_mm_call_get_state;
call_class->get_inbound = calls_mm_call_get_inbound;
call_class->answer = calls_mm_call_answer;
call_class->hang_up = calls_mm_call_hang_up;
call_class->tone_start = calls_mm_call_tone_start;
props[PROP_MM_CALL] = g_param_spec_object ("mm-call", props[PROP_MM_CALL] = g_param_spec_object ("mm-call",
"MM call", "MM call",
"A libmm-glib proxy object for the underlying call object", "A libmm-glib proxy object for the underlying call object",
MM_TYPE_CALL, MM_TYPE_CALL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_MM_CALL, props[PROP_MM_CALL]); g_object_class_install_property (object_class, PROP_MM_CALL, props[PROP_MM_CALL]);
#define IMPLEMENTS(ID, NAME) \
g_object_class_override_property (object_class, ID, NAME); \
props[ID] = g_object_class_find_property(object_class, NAME);
IMPLEMENTS(PROP_CALL_NUMBER, "number");
IMPLEMENTS(PROP_CALL_INBOUND, "inbound");
IMPLEMENTS(PROP_CALL_STATE, "state");
IMPLEMENTS(PROP_CALL_NAME, "name");
#undef IMPLEMENTS
} }
static void static void
calls_mm_call_message_source_interface_init (CallsCallInterface *iface) calls_mm_call_message_source_interface_init (CallsMessageSourceInterface *iface)
{ {
} }
static void
calls_mm_call_call_interface_init (CallsCallInterface *iface)
{
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;
}
static void static void
calls_mm_call_init (CallsMMCall *self) calls_mm_call_init (CallsMMCall *self)
{ {

View file

@ -28,11 +28,13 @@
#include <libmm-glib.h> #include <libmm-glib.h>
#include <glib-object.h> #include <glib-object.h>
#include "calls-call.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLS_TYPE_MM_CALL (calls_mm_call_get_type ()) #define CALLS_TYPE_MM_CALL (calls_mm_call_get_type ())
G_DECLARE_FINAL_TYPE (CallsMMCall, calls_mm_call, CALLS, MM_CALL, GObject); G_DECLARE_FINAL_TYPE (CallsMMCall, calls_mm_call, CALLS, MM_CALL, CallsCall)
CallsMMCall *calls_mm_call_new (MMCall *mm_call); CallsMMCall *calls_mm_call_new (MMCall *mm_call);
const gchar *calls_mm_call_get_object_path (CallsMMCall *call); const gchar *calls_mm_call_get_object_path (CallsMMCall *call);

View file

@ -44,25 +44,16 @@ struct _CallsOfonoCall
gboolean inbound; gboolean inbound;
}; };
static void calls_ofono_call_message_source_interface_init (CallsCallInterface *iface); static void calls_ofono_call_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_ofono_call_call_interface_init (CallsCallInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsOfonoCall, calls_ofono_call, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (CallsOfonoCall, calls_ofono_call, CALLS_TYPE_CALL,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_ofono_call_message_source_interface_init) calls_ofono_call_message_source_interface_init))
G_IMPLEMENT_INTERFACE (CALLS_TYPE_CALL,
calls_ofono_call_call_interface_init))
enum { enum {
PROP_0, PROP_0,
PROP_VOICE_CALL, PROP_VOICE_CALL,
PROP_PROPERTIES, PROP_PROPERTIES,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP, PROP_LAST_PROP,
}; };
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
@ -85,13 +76,44 @@ change_state (CallsOfonoCall *self,
} }
self->state = state; self->state = state;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_STATE]); g_object_notify (G_OBJECT (self), "state");
g_signal_emit_by_name (CALLS_CALL (self), g_signal_emit_by_name (CALLS_CALL (self),
"state-changed", "state-changed",
state, state,
old_state); old_state);
} }
static const char *
calls_ofono_call_get_number (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->number;
}
static const char *
calls_ofono_call_get_name (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->name;
}
static CallsCallState
calls_ofono_call_get_state (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->state;
}
static gboolean
calls_ofono_call_get_inbound (CallsCall *call)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
return self->state;
}
struct CallsCallOperationData struct CallsCallOperationData
{ {
@ -122,7 +144,7 @@ operation_cb (GDBOVoiceCall *voice_call,
static void static void
answer (CallsCall *call) calls_ofono_call_answer (CallsCall *call)
{ {
CallsOfonoCall *self = CALLS_OFONO_CALL (call); CallsOfonoCall *self = CALLS_OFONO_CALL (call);
struct CallsCallOperationData *data; struct CallsCallOperationData *data;
@ -140,7 +162,7 @@ answer (CallsCall *call)
static void static void
hang_up (CallsCall *call) calls_ofono_call_hang_up (CallsCall *call)
{ {
CallsOfonoCall *self = CALLS_OFONO_CALL (call); CallsOfonoCall *self = CALLS_OFONO_CALL (call);
struct CallsCallOperationData *data; struct CallsCallOperationData *data;
@ -158,7 +180,7 @@ hang_up (CallsCall *call)
static void static void
tone_start (CallsCall *call, gchar key) calls_ofono_call_tone_start (CallsCall *call, gchar key)
{ {
CallsOfonoCall *self = CALLS_OFONO_CALL (call); CallsOfonoCall *self = CALLS_OFONO_CALL (call);
if (self->state != CALLS_CALL_STATE_ACTIVE) if (self->state != CALLS_CALL_STATE_ACTIVE)
@ -218,37 +240,6 @@ set_property (GObject *object,
} }
} }
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
switch (property_id) {
case PROP_CALL_INBOUND:
g_value_set_boolean (value, self->state);
break;
case PROP_CALL_NAME:
g_value_set_string(value, self->name);
break;
case PROP_CALL_NUMBER:
g_value_set_string(value, self->number);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void static void
property_changed_cb (CallsOfonoCall *self, property_changed_cb (CallsOfonoCall *self,
const gchar *name, const gchar *name,
@ -349,14 +340,22 @@ static void
calls_ofono_call_class_init (CallsOfonoCallClass *klass) calls_ofono_call_class_init (CallsOfonoCallClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
GType tone_arg_types = G_TYPE_CHAR; GType tone_arg_types = G_TYPE_CHAR;
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->finalize = finalize; object_class->finalize = finalize;
call_class->get_number = calls_ofono_call_get_number;
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->answer = calls_ofono_call_answer;
call_class->hang_up = calls_ofono_call_hang_up;
call_class->tone_start = calls_ofono_call_tone_start;
props[PROP_VOICE_CALL] = props[PROP_VOICE_CALL] =
g_param_spec_object ("voice-call", g_param_spec_object ("voice-call",
"Voice call", "Voice call",
@ -374,17 +373,6 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_PROPERTIES, props[PROP_PROPERTIES]); g_object_class_install_property (object_class, PROP_PROPERTIES, props[PROP_PROPERTIES]);
#define IMPLEMENTS(ID, NAME) \
g_object_class_override_property (object_class, ID, NAME); \
props[ID] = g_object_class_find_property(object_class, NAME);
IMPLEMENTS(PROP_CALL_NUMBER, "number");
IMPLEMENTS(PROP_CALL_INBOUND, "inbound");
IMPLEMENTS(PROP_CALL_STATE, "state");
IMPLEMENTS(PROP_CALL_NAME, "name");
#undef IMPLEMENTS
signals[SIGNAL_TONE] = signals[SIGNAL_TONE] =
g_signal_newv ("tone", g_signal_newv ("tone",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
@ -396,20 +384,10 @@ calls_ofono_call_class_init (CallsOfonoCallClass *klass)
static void static void
calls_ofono_call_message_source_interface_init (CallsCallInterface *iface) calls_ofono_call_message_source_interface_init (CallsMessageSourceInterface *iface)
{ {
} }
static void
calls_ofono_call_call_interface_init (CallsCallInterface *iface)
{
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;
}
static void static void
calls_ofono_call_init (CallsOfonoCall *self) calls_ofono_call_init (CallsOfonoCall *self)
{ {

View file

@ -26,14 +26,15 @@
#define CALLS_OFONO_CALL_H__ #define CALLS_OFONO_CALL_H__
#include <libgdbofono/gdbo-call.h> #include <libgdbofono/gdbo-call.h>
#include <glib-object.h> #include <glib-object.h>
#include "calls-call.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLS_TYPE_OFONO_CALL (calls_ofono_call_get_type ()) #define CALLS_TYPE_OFONO_CALL (calls_ofono_call_get_type ())
G_DECLARE_FINAL_TYPE (CallsOfonoCall, calls_ofono_call, CALLS, OFONO_CALL, GObject); G_DECLARE_FINAL_TYPE (CallsOfonoCall, calls_ofono_call, CALLS, OFONO_CALL, CallsCall)
CallsOfonoCall *calls_ofono_call_new (GDBOVoiceCall *voice_call, CallsOfonoCall *calls_ofono_call_new (GDBOVoiceCall *voice_call,
GVariant *properties); GVariant *properties);

View file

@ -48,29 +48,46 @@ struct _CallsSipCall
nua_handle_t *nh; nua_handle_t *nh;
}; };
static void calls_sip_call_message_source_interface_init (CallsCallInterface *iface); static void calls_sip_call_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_sip_call_call_interface_init (CallsCallInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsSipCall, calls_sip_call, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (CallsSipCall, calls_sip_call, CALLS_TYPE_CALL,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_sip_call_message_source_interface_init) calls_sip_call_message_source_interface_init))
G_IMPLEMENT_INTERFACE (CALLS_TYPE_CALL,
calls_sip_call_call_interface_init))
enum { enum {
PROP_0, PROP_0,
PROP_CALL_HANDLE, PROP_CALL_HANDLE,
PROP_CALL_NUMBER,
PROP_CALL_INBOUND,
PROP_CALL_STATE,
PROP_CALL_NAME,
PROP_LAST_PROP PROP_LAST_PROP
}; };
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
static const char *
calls_sip_call_get_number (CallsCall *call)
{
CallsSipCall *self = CALLS_SIP_CALL (call);
return self->number;
}
static CallsCallState
calls_sip_call_get_state (CallsCall *call)
{
CallsSipCall *self = CALLS_SIP_CALL (call);
return self->state;
}
static gboolean
calls_sip_call_get_inbound (CallsCall *call)
{
CallsSipCall *self = CALLS_SIP_CALL (call);
return self->inbound;
}
static void static void
answer (CallsCall *call) calls_sip_call_answer (CallsCall *call)
{ {
CallsSipCall *self; CallsSipCall *self;
g_autofree gchar *local_sdp = NULL; g_autofree gchar *local_sdp = NULL;
@ -107,7 +124,7 @@ answer (CallsCall *call)
} }
static void static void
hang_up (CallsCall *call) calls_sip_call_hang_up (CallsCall *call)
{ {
CallsSipCall *self; CallsSipCall *self;
@ -142,19 +159,6 @@ hang_up (CallsCall *call)
} }
} }
static void
tone_start (CallsCall *call, gchar key)
{
g_info ("Beep! (%c)", (int)key);
}
static void
tone_stop (CallsCall *call, gchar key)
{
g_info ("Beep end (%c)", (int)key);
}
static void static void
calls_sip_call_set_property (GObject *object, calls_sip_call_set_property (GObject *object,
guint property_id, guint property_id,
@ -184,22 +188,6 @@ calls_sip_call_get_property (GObject *object,
CallsSipCall *self = CALLS_SIP_CALL (object); CallsSipCall *self = CALLS_SIP_CALL (object);
switch (property_id) { switch (property_id) {
case PROP_CALL_INBOUND:
g_value_set_boolean (value, self->inbound);
break;
case PROP_CALL_NUMBER:
g_value_set_string (value, self->number);
break;
case PROP_CALL_STATE:
g_value_set_enum (value, self->state);
break;
case PROP_CALL_NAME:
g_value_set_string (value, NULL);
break;
case PROP_CALL_HANDLE: case PROP_CALL_HANDLE:
g_value_set_pointer (value, self->nh); g_value_set_pointer (value, self->nh);
break; break;
@ -230,43 +218,28 @@ static void
calls_sip_call_class_init (CallsSipCallClass *klass) calls_sip_call_class_init (CallsSipCallClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
object_class->get_property = calls_sip_call_get_property; object_class->get_property = calls_sip_call_get_property;
object_class->set_property = calls_sip_call_set_property; object_class->set_property = calls_sip_call_set_property;
object_class->finalize = calls_sip_call_finalize; object_class->finalize = calls_sip_call_finalize;
call_class->get_number = calls_sip_call_get_number;
call_class->get_state = calls_sip_call_get_state;
call_class->get_inbound = calls_sip_call_get_inbound;
call_class->answer = calls_sip_call_answer;
call_class->hang_up = calls_sip_call_hang_up;
props[PROP_CALL_HANDLE] = props[PROP_CALL_HANDLE] =
g_param_spec_pointer ("nua-handle", g_param_spec_pointer ("nua-handle",
"NUA handle", "NUA handle",
"The used NUA handler", "The used NUA handler",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_CALL_HANDLE, props[PROP_CALL_HANDLE]); g_object_class_install_property (object_class, PROP_CALL_HANDLE, props[PROP_CALL_HANDLE]);
#define IMPLEMENTS(ID, NAME) \
g_object_class_override_property (object_class, ID, NAME); \
props[ID] = g_object_class_find_property(object_class, NAME);
IMPLEMENTS(PROP_CALL_NUMBER, "number");
IMPLEMENTS(PROP_CALL_INBOUND, "inbound");
IMPLEMENTS(PROP_CALL_STATE, "state");
IMPLEMENTS(PROP_CALL_NAME, "name");
#undef IMPLEMENTS
} }
static void static void
calls_sip_call_call_interface_init (CallsCallInterface *iface) calls_sip_call_message_source_interface_init (CallsMessageSourceInterface *iface)
{
iface->answer = answer;
iface->hang_up = hang_up;
iface->tone_start = tone_start;
iface->tone_stop = tone_stop;
}
static void
calls_sip_call_message_source_interface_init (CallsCallInterface *iface)
{ {
} }
@ -374,7 +347,7 @@ calls_sip_call_set_state (CallsSipCall *self,
} }
self->state = state; self->state = state;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CALL_STATE]); g_object_notify (G_OBJECT (self), "state");
g_signal_emit_by_name (CALLS_CALL (self), g_signal_emit_by_name (CALLS_CALL (self),
"state-changed", "state-changed",
state, state,

View file

@ -33,7 +33,7 @@ G_BEGIN_DECLS
#define CALLS_TYPE_SIP_CALL (calls_sip_call_get_type ()) #define CALLS_TYPE_SIP_CALL (calls_sip_call_get_type ())
G_DECLARE_FINAL_TYPE (CallsSipCall, calls_sip_call, CALLS, SIP_CALL, GObject); G_DECLARE_FINAL_TYPE (CallsSipCall, calls_sip_call, CALLS, SIP_CALL, CallsCall)
CallsSipCall *calls_sip_call_new (const gchar *number, CallsSipCall *calls_sip_call_new (const gchar *number,
gboolean inbound, gboolean inbound,

View file

@ -31,59 +31,6 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
void
calls_call_state_to_string (GString *string,
CallsCallState state)
{
GEnumClass *klass;
GEnumValue *value;
klass = g_type_class_ref (CALLS_TYPE_CALL_STATE);
value = g_enum_get_value (klass, (gint)state);
if (!value)
{
return g_string_printf (string,
"Unknown call state (%d)",
(gint)state);
}
g_string_assign (string, value->value_nick);
string->str[0] = g_ascii_toupper (string->str[0]);
g_type_class_unref (klass);
}
gboolean
calls_call_state_parse_nick (CallsCallState *state,
const gchar *nick)
{
GEnumClass *klass;
GEnumValue *value;
gboolean ret;
g_return_val_if_fail (state != NULL, FALSE);
g_return_val_if_fail (nick != NULL, FALSE);
klass = g_type_class_ref (CALLS_TYPE_CALL_STATE);
value = g_enum_get_value_by_nick (klass, nick);
if (value)
{
*state = (CallsCallState) value->value;
ret = TRUE;
}
else
{
ret = FALSE;
}
g_type_class_unref (klass);
return ret;
}
/** /**
* SECTION:calls-call * SECTION:calls-call
* @short_description: A call. * @short_description: A call.
@ -100,56 +47,150 @@ calls_call_state_parse_nick (CallsCallState *state,
*/ */
G_DEFINE_INTERFACE (CallsCall, calls_call, CALLS_TYPE_MESSAGE_SOURCE); G_DEFINE_ABSTRACT_TYPE (CallsCall, calls_call, G_TYPE_OBJECT)
enum { enum {
SIGNAL_STATE_CHANGED, PROP_0,
SIGNAL_LAST_SIGNAL, PROP_INBOUND,
PROP_NUMBER,
PROP_NAME,
PROP_STATE,
N_PROPS,
}; };
static guint signals [SIGNAL_LAST_SIGNAL];
enum {
STATE_CHANGED,
N_SIGNALS,
};
static GParamSpec *properties[N_PROPS];
static guint signals[N_SIGNALS];
static const char *
calls_call_real_get_number (CallsCall *self)
{
return NULL;
}
static const char *
calls_call_real_get_name (CallsCall *self)
{
return NULL;
}
static CallsCallState
calls_call_real_get_state (CallsCall *self)
{
return 0;
}
static gboolean
calls_call_real_get_inbound (CallsCall *self)
{
return FALSE;
}
static void static void
calls_call_default_init (CallsCallInterface *iface) calls_call_real_answer (CallsCall *self)
{ {
GType arg_types[2] = }
{
CALLS_TYPE_CALL_STATE,
CALLS_TYPE_CALL_STATE
};
g_object_interface_install_property ( static void
iface, calls_call_real_hang_up (CallsCall *self)
{
}
static void
calls_call_real_tone_start (CallsCall *self,
char key)
{
g_info ("Beep! (%c)", (int)key);
}
static void
calls_call_real_tone_stop (CallsCall *self,
char key)
{
g_info ("Beep end (%c)", (int)key);
}
static void
calls_call_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
CallsCall *self = CALLS_CALL (object);
switch (prop_id)
{
case PROP_INBOUND:
g_value_set_boolean (value, calls_call_get_inbound (self));
break;
case PROP_NUMBER:
g_value_set_string (value, calls_call_get_number (self));
break;
case PROP_NAME:
g_value_set_string (value, calls_call_get_name (self));
break;
case PROP_STATE:
g_value_set_enum (value, calls_call_get_state (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
calls_call_class_init (CallsCallClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = calls_call_get_property;
klass->get_number = calls_call_real_get_number;
klass->get_name = calls_call_real_get_name;
klass->get_state = calls_call_real_get_state;
klass->get_inbound = calls_call_real_get_inbound;
klass->answer = calls_call_real_answer;
klass->hang_up = calls_call_real_hang_up;
klass->tone_start = calls_call_real_tone_start;
klass->tone_stop = calls_call_real_tone_stop;
properties[PROP_INBOUND] =
g_param_spec_boolean ("inbound", g_param_spec_boolean ("inbound",
"Inbound", "Inbound",
"Whether the call is inbound", "Whether the call is inbound",
FALSE, FALSE,
G_PARAM_READABLE)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_interface_install_property ( properties[PROP_NUMBER] =
iface,
g_param_spec_string ("number", g_param_spec_string ("number",
"Number", "Number",
"The number the call is connected to if known", "The number the call is connected to if known",
NULL, NULL,
G_PARAM_READABLE)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_interface_install_property ( properties[PROP_NAME] =
iface,
g_param_spec_string ("name", g_param_spec_string ("name",
"Name", "Name",
"The name of the party the call is connected to, if the network provides it", "The name of the party the call is connected to, if the network provides it",
NULL, NULL,
G_PARAM_READABLE)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_interface_install_property ( properties[PROP_STATE] =
iface,
g_param_spec_enum ("state", g_param_spec_enum ("state",
"State", "State",
"The current state of the call", "The current state of the call",
CALLS_TYPE_CALL_STATE, CALLS_TYPE_CALL_STATE,
CALLS_CALL_STATE_ACTIVE, CALLS_CALL_STATE_ACTIVE,
G_PARAM_READABLE)); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
/** /**
* CallsCall::state-changed: * CallsCall::state-changed:
@ -160,22 +201,19 @@ calls_call_default_init (CallsCallInterface *iface)
* This signal is emitted when the state of the call changes, for * This signal is emitted when the state of the call changes, for
* example when it's answered or when the call is disconnected. * example when it's answered or when the call is disconnected.
*/ */
signals[SIGNAL_STATE_CHANGED] = signals[STATE_CHANGED] =
g_signal_newv ("state-changed", g_signal_new ("state-changed",
G_TYPE_FROM_INTERFACE (iface), G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL,
G_TYPE_NONE, G_TYPE_NONE,
2, arg_types); 2, CALLS_TYPE_CALL_STATE, CALLS_TYPE_CALL_STATE);
} }
static void
#define DEFINE_CALL_GETTER(prop,rettype,errval) \ calls_call_init (CallsCall *self)
CALLS_DEFINE_IFACE_GETTER(call, Call, CALL, prop, rettype, errval) {
}
#define DEFINE_CALL_FUNC_VOID(function) \
CALLS_DEFINE_IFACE_FUNC_VOID(call, Call, CALL, function)
/** /**
* calls_call_get_number: * calls_call_get_number:
@ -187,7 +225,13 @@ calls_call_default_init (CallsCallInterface *iface)
* *
* Returns: the number, or NULL * Returns: the number, or NULL
*/ */
DEFINE_CALL_GETTER(number, const gchar *, NULL); const char *
calls_call_get_number (CallsCall *self)
{
g_return_val_if_fail (CALLS_IS_CALL (self), NULL);
return CALLS_CALL_GET_CLASS (self)->get_number (self);
}
/** /**
* calls_call_get_name: * calls_call_get_name:
@ -198,7 +242,13 @@ DEFINE_CALL_GETTER(number, const gchar *, NULL);
* *
* Returns: the number, or NULL * Returns: the number, or NULL
*/ */
DEFINE_CALL_GETTER(name, const gchar *, NULL); const char *
calls_call_get_name (CallsCall *self)
{
g_return_val_if_fail (CALLS_IS_CALL (self), NULL);
return CALLS_CALL_GET_CLASS (self)->get_name (self);
}
/** /**
* calls_call_get_state: * calls_call_get_state:
@ -208,7 +258,13 @@ DEFINE_CALL_GETTER(name, const gchar *, NULL);
* *
* Returns: the state * Returns: the state
*/ */
DEFINE_CALL_GETTER(state, CallsCallState, ((CallsCallState)0)); CallsCallState
calls_call_get_state (CallsCall *self)
{
g_return_val_if_fail (CALLS_IS_CALL (self), 0);
return CALLS_CALL_GET_CLASS (self)->get_state (self);
}
/** /**
* calls_call_answer: * calls_call_answer:
@ -217,7 +273,13 @@ DEFINE_CALL_GETTER(state, CallsCallState, ((CallsCallState)0));
* If the call is incoming, answer it. * If the call is incoming, answer it.
* *
*/ */
DEFINE_CALL_FUNC_VOID(answer); void
calls_call_answer (CallsCall *self)
{
g_return_if_fail (CALLS_IS_CALL (self));
CALLS_CALL_GET_CLASS (self)->answer (self);
}
/** /**
* calls_call_hang_up: * calls_call_hang_up:
@ -226,7 +288,13 @@ DEFINE_CALL_FUNC_VOID(answer);
* Hang up the call. * Hang up the call.
* *
*/ */
DEFINE_CALL_FUNC_VOID(hang_up); void
calls_call_hang_up (CallsCall *self)
{
g_return_if_fail (CALLS_IS_CALL (self));
CALLS_CALL_GET_CLASS (self)->hang_up (self);
}
/** /**
@ -237,7 +305,13 @@ DEFINE_CALL_FUNC_VOID(hang_up);
* *
* Returns: TRUE if inbound, FALSE if outbound. * Returns: TRUE if inbound, FALSE if outbound.
*/ */
DEFINE_CALL_GETTER(inbound, gboolean, FALSE); gboolean
calls_call_get_inbound (CallsCall *self)
{
g_return_val_if_fail (CALLS_IS_CALL (self), FALSE);
return CALLS_CALL_GET_CLASS (self)->get_inbound (self);
}
static inline gboolean static inline gboolean
tone_key_is_valid (gchar key) tone_key_is_valid (gchar key)
@ -265,15 +339,10 @@ void
calls_call_tone_start (CallsCall *self, calls_call_tone_start (CallsCall *self,
gchar key) gchar key)
{ {
CallsCallInterface *iface;
g_return_if_fail (CALLS_IS_CALL (self)); g_return_if_fail (CALLS_IS_CALL (self));
g_return_if_fail (tone_key_is_valid (key)); g_return_if_fail (tone_key_is_valid (key));
iface = CALLS_CALL_GET_IFACE (self); CALLS_CALL_GET_CLASS (self)->tone_start (self, key);
g_return_if_fail (iface->tone_start != NULL);
iface->tone_start (self, key);
} }
/** /**
@ -291,13 +360,9 @@ calls_call_tone_start (CallsCall *self,
gboolean gboolean
calls_call_tone_stoppable (CallsCall *self) calls_call_tone_stoppable (CallsCall *self)
{ {
CallsCallInterface *iface;
g_return_val_if_fail (CALLS_IS_CALL (self), FALSE); g_return_val_if_fail (CALLS_IS_CALL (self), FALSE);
iface = CALLS_CALL_GET_IFACE (self); return CALLS_CALL_GET_CLASS (self)->tone_stop != calls_call_real_tone_stop;
return iface->tone_stop != NULL;
} }
/** /**
@ -313,18 +378,10 @@ void
calls_call_tone_stop (CallsCall *self, calls_call_tone_stop (CallsCall *self,
gchar key) gchar key)
{ {
CallsCallInterface *iface;
g_return_if_fail (CALLS_IS_CALL (self)); g_return_if_fail (CALLS_IS_CALL (self));
g_return_if_fail (tone_key_is_valid (key)); g_return_if_fail (tone_key_is_valid (key));
iface = CALLS_CALL_GET_IFACE (self); CALLS_CALL_GET_CLASS (self)->tone_stop (self, key);
if (!iface->tone_stop)
{
return;
}
iface->tone_stop (self, key);
} }
/** /**
@ -345,3 +402,54 @@ calls_call_get_contact (CallsCall *self)
return calls_contacts_provider_lookup_phone_number (contacts_provider, return calls_contacts_provider_lookup_phone_number (contacts_provider,
calls_call_get_number (self)); calls_call_get_number (self));
} }
void
calls_call_state_to_string (GString *string,
CallsCallState state)
{
GEnumClass *klass;
GEnumValue *value;
klass = g_type_class_ref (CALLS_TYPE_CALL_STATE);
value = g_enum_get_value (klass, (gint)state);
if (!value)
{
return g_string_printf (string,
"Unknown call state (%d)",
(gint)state);
}
g_string_assign (string, value->value_nick);
string->str[0] = g_ascii_toupper (string->str[0]);
g_type_class_unref (klass);
}
gboolean
calls_call_state_parse_nick (CallsCallState *state,
const char *nick)
{
GEnumClass *klass;
GEnumValue *value;
gboolean ret;
g_return_val_if_fail (state != NULL, FALSE);
g_return_val_if_fail (nick != NULL, FALSE);
klass = g_type_class_ref (CALLS_TYPE_CALL_STATE);
value = g_enum_get_value_by_nick (klass, nick);
if (value)
{
*state = (CallsCallState) value->value;
ret = TRUE;
}
else
{
ret = FALSE;
}
g_type_class_unref (klass);
return ret;
}

View file

@ -33,7 +33,7 @@ G_BEGIN_DECLS
#define CALLS_TYPE_CALL (calls_call_get_type ()) #define CALLS_TYPE_CALL (calls_call_get_type ())
G_DECLARE_INTERFACE (CallsCall, calls_call, CALLS, CALL, GObject); G_DECLARE_DERIVABLE_TYPE (CallsCall, calls_call, CALLS, CALL, GObject)
typedef enum typedef enum
{ {
@ -46,26 +46,24 @@ typedef enum
CALLS_CALL_STATE_DISCONNECTED CALLS_CALL_STATE_DISCONNECTED
} CallsCallState; } CallsCallState;
void calls_call_state_to_string (GString *string, struct _CallsCallClass
CallsCallState state);
gboolean calls_call_state_parse_nick (CallsCallState *state,
const gchar *nick);
struct _CallsCallInterface
{ {
GTypeInterface parent_iface; GObjectClass parent_iface;
void (*answer) (CallsCall *self); const char *(*get_number) (CallsCall *self);
void (*hang_up) (CallsCall *self); const char *(*get_name) (CallsCall *self);
void (*tone_start) (CallsCall *self, CallsCallState (*get_state) (CallsCall *self);
gchar key); gboolean (*get_inbound) (CallsCall *self);
void (*tone_stop) (CallsCall *self, void (*answer) (CallsCall *self);
gchar key); void (*hang_up) (CallsCall *self);
void (*tone_start) (CallsCall *self,
char key);
void (*tone_stop) (CallsCall *self,
char key);
}; };
const char *calls_call_get_number (CallsCall *self);
const gchar * calls_call_get_number (CallsCall *self); const char *calls_call_get_name (CallsCall *self);
const gchar * calls_call_get_name (CallsCall *self);
CallsCallState calls_call_get_state (CallsCall *self); CallsCallState calls_call_get_state (CallsCall *self);
gboolean calls_call_get_inbound (CallsCall *self); gboolean calls_call_get_inbound (CallsCall *self);
void calls_call_answer (CallsCall *self); void calls_call_answer (CallsCall *self);
@ -77,6 +75,11 @@ void calls_call_tone_stop (CallsCall *self,
gchar key); gchar key);
CallsBestMatch * calls_call_get_contact (CallsCall *self); CallsBestMatch * calls_call_get_contact (CallsCall *self);
void calls_call_state_to_string (GString *string,
CallsCallState state);
gboolean calls_call_state_parse_nick (CallsCallState *state,
const char *nick);
G_END_DECLS G_END_DECLS