Commit 4e7a0b81 authored by Daniel Abrecht's avatar Daniel Abrecht Committed by Evangelos Ribeiro Tzaras

Replace CallsOrigin getters with properties and add calls_origin_foreach_call method

parent 891ed1fe
......@@ -49,36 +49,20 @@ G_DEFINE_TYPE_WITH_CODE (CallsDummyOrigin, calls_dummy_origin, G_TYPE_OBJECT,
enum {
PROP_0,
/* Property for setting the origins name upon construction */
PROP_DUMMY_NAME_CONSTRUCTOR,
/* The origins name. The implements the name property from CallsOrigin.
* Readonly property, can't be set directly. */
PROP_NAME,
PROP_CALLS,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static const gchar *
get_name (CallsOrigin *origin)
{
CallsDummyOrigin *self;
g_return_val_if_fail (CALLS_IS_DUMMY_ORIGIN (origin), NULL);
self = CALLS_DUMMY_ORIGIN (origin);
return self->name->str;
}
static GList *
get_calls (CallsOrigin *origin)
{
CallsDummyOrigin *self;
g_return_val_if_fail (CALLS_IS_DUMMY_ORIGIN (origin), NULL);
self = CALLS_DUMMY_ORIGIN (origin);
return g_list_copy (self->calls);
}
static void
remove_call (CallsDummyOrigin *self,
CallsCall *call,
......@@ -172,7 +156,7 @@ CallsDummyOrigin *
calls_dummy_origin_new (const gchar *name)
{
return g_object_new (CALLS_TYPE_DUMMY_ORIGIN,
"name", name,
"dummy-name-constructor", name,
NULL);
}
......@@ -186,7 +170,7 @@ set_property (GObject *object,
CallsDummyOrigin *self = CALLS_DUMMY_ORIGIN (object);
switch (property_id) {
case PROP_NAME:
case PROP_DUMMY_NAME_CONSTRUCTOR:
g_string_assign (self->name, g_value_get_string (value));
break;
......@@ -197,6 +181,30 @@ set_property (GObject *object,
}
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsDummyOrigin *self = CALLS_DUMMY_ORIGIN (object);
switch (property_id) {
case PROP_NAME:
g_value_set_string (value, self->name->str);
break;
case PROP_CALLS:
g_value_set_pointer (value, g_list_copy (self->calls));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
......@@ -226,16 +234,26 @@ calls_dummy_origin_class_init (CallsDummyOriginClass *klass)
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
object_class->set_property = set_property;
props[PROP_NAME] =
g_param_spec_string ("name",
props[PROP_DUMMY_NAME_CONSTRUCTOR] =
g_param_spec_string ("dummy-name-constructor",
_("Name"),
_("The name of the origin"),
"Dummy origin",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_DUMMY_NAME_CONSTRUCTOR, props[PROP_DUMMY_NAME_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_NAME, "name");
IMPLEMENTS (PROP_CALLS, "calls");
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
#undef IMPLEMENTS
}
......@@ -248,8 +266,6 @@ calls_dummy_origin_message_source_interface_init (CallsOriginInterface *iface)
static void
calls_dummy_origin_origin_interface_init (CallsOriginInterface *iface)
{
iface->get_name = get_name;
iface->get_calls = get_calls;
iface->dial = dial;
}
......
......@@ -63,6 +63,8 @@ G_DEFINE_TYPE_WITH_CODE (CallsMMOrigin, calls_mm_origin, G_TYPE_OBJECT,
enum {
PROP_0,
PROP_NAME,
PROP_CALLS,
PROP_MODEM,
PROP_LAST_PROP,
};
......@@ -294,21 +296,6 @@ calls_mm_ussd_cancel_finish (CallsUssd *ussd,
return g_task_propagate_boolean (G_TASK (result), error);
}
static const gchar *
get_name (CallsOrigin *origin)
{
CallsMMOrigin *self = CALLS_MM_ORIGIN (origin);
return self->name;
}
static GList *
get_calls (CallsOrigin * origin)
{
CallsMMOrigin *self = CALLS_MM_ORIGIN (origin);
return g_hash_table_get_values (self->calls);
}
static void
dial_cb (MMModemVoice *voice,
......@@ -641,6 +628,30 @@ set_property (GObject *object,
}
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsMMOrigin *self = CALLS_MM_ORIGIN (object);
switch (property_id) {
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_CALLS:
g_value_set_pointer(value, g_hash_table_get_values (self->calls));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gchar *
modem_get_name (MMModem *modem)
{
......@@ -792,6 +803,7 @@ calls_mm_origin_class_init (CallsMMOriginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->constructed = constructed;
object_class->dispose = dispose;
......@@ -803,8 +815,17 @@ calls_mm_origin_class_init (CallsMMOriginClass *klass)
_("A libmm-glib proxy object for the modem"),
MM_TYPE_OBJECT,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_MODEM, props[PROP_MODEM]);
#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_NAME, "name");
IMPLEMENTS (PROP_CALLS, "calls");
#undef IMPLEMENTS
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}
......@@ -830,8 +851,6 @@ calls_mm_origin_ussd_interface_init (CallsUssdInterface *iface)
static void
calls_mm_origin_origin_interface_init (CallsOriginInterface *iface)
{
iface->get_name = get_name;
iface->get_calls = get_calls;
iface->dial = dial;
}
......
......@@ -53,27 +53,14 @@ G_DEFINE_TYPE_WITH_CODE (CallsOfonoOrigin, calls_ofono_origin, G_TYPE_OBJECT,
enum {
PROP_0,
PROP_NAME,
PROP_CALLS,
PROP_MODEM,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static const gchar *
get_name (CallsOrigin *origin)
{
CallsOfonoOrigin *self = CALLS_OFONO_ORIGIN (origin);
return self->name;
}
static GList *
get_calls (CallsOrigin * origin)
{
CallsOfonoOrigin *self = CALLS_OFONO_ORIGIN (origin);
return g_hash_table_get_values (self->calls);
}
static void
dial_cb (GDBOVoiceCallManager *voice,
GAsyncResult *res,
......@@ -144,6 +131,31 @@ set_property (GObject *object,
}
}
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsOfonoOrigin *self = CALLS_OFONO_ORIGIN (object);
switch (property_id) {
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_CALLS:
g_value_set_pointer(value, g_hash_table_get_values (self->calls));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
remove_call (CallsOfonoOrigin *self,
CallsOfonoCall *call,
......@@ -514,6 +526,7 @@ calls_ofono_origin_class_init (CallsOfonoOriginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->constructed = constructed;
object_class->dispose = dispose;
......@@ -525,8 +538,17 @@ calls_ofono_origin_class_init (CallsOfonoOriginClass *klass)
_("A GDBO proxy object for the underlying modem object"),
GDBO_TYPE_MODEM,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_MODEM, props[PROP_MODEM]);
#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_NAME, "name");
IMPLEMENTS (PROP_CALLS, "calls");
#undef IMPLEMENTS
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}
......@@ -539,8 +561,6 @@ calls_ofono_origin_message_source_interface_init (CallsOriginInterface *iface)
static void
calls_ofono_origin_origin_interface_init (CallsOriginInterface *iface)
{
iface->get_name = get_name;
iface->get_calls = get_calls;
iface->dial = dial;
}
......
......@@ -190,12 +190,8 @@ ussd_state_changed_cb (CallsManager *self,
static void
add_origin (CallsManager *self, CallsOrigin *origin, CallsProvider *provider)
{
g_autoptr (GList) calls = NULL;
GList *c;
g_return_if_fail (CALLS_IS_ORIGIN (origin));
calls = calls_origin_get_calls (origin);
g_signal_connect_swapped (origin, "call-added", G_CALLBACK (add_call), self);
g_signal_connect_swapped (origin, "call-removed", G_CALLBACK (remove_call), self);
......@@ -206,30 +202,28 @@ add_origin (CallsManager *self, CallsOrigin *origin, CallsProvider *provider)
g_signal_connect_swapped (origin, "ussd-state-changed", G_CALLBACK (ussd_state_changed_cb), self);
}
for (c = calls; c != NULL; c = c->next)
{
add_call (self, c->data, origin);
}
calls_origin_foreach_call(origin, (CallsOriginForeachCallFunc)add_call, self);
set_state (self, CALLS_MANAGER_STATE_READY);
g_signal_emit (self, signals[SIGNAL_ORIGIN_ADD], 0, origin);
}
static void
remove_call_cb (gpointer self, CallsCall *call, CallsOrigin *origin)
{
remove_call(self, call, NULL, origin);
}
static void
remove_origin (CallsManager *self, CallsOrigin *origin, CallsProvider *provider)
{
g_autoptr (GList) origins = NULL;
g_autoptr (GList) calls = NULL;
GList *c;
g_return_if_fail (CALLS_IS_ORIGIN (origin));
g_signal_handlers_disconnect_by_data (origin, self);
calls = calls_origin_get_calls (origin);
for (c = calls; c != NULL; c = c->next)
{
remove_call (self, c->data, NULL, origin);
}
calls_origin_foreach_call(origin, remove_call_cb, self);
if (self->default_origin == origin)
calls_manager_set_default_origin (self, NULL);
......
......@@ -47,6 +47,21 @@ calls_origin_default_init (CallsOriginInterface *iface)
{
GType arg_types[2] = { CALLS_TYPE_CALL, G_TYPE_STRING };
g_object_interface_install_property (
iface,
g_param_spec_string ("name",
"Name",
"The name of the origin",
NULL,
G_PARAM_READABLE));
g_object_interface_install_property (
iface,
g_param_spec_pointer ("calls",
"Calls",
"The list of current calls",
G_PARAM_READABLE));
signals[SIGNAL_CALL_ADDED] =
g_signal_newv ("call-added",
G_TYPE_FROM_INTERFACE (iface),
......@@ -64,9 +79,8 @@ calls_origin_default_init (CallsOriginInterface *iface)
2, arg_types);
}
#define DEFINE_ORIGIN_FUNC(function,rettype,errval) \
CALLS_DEFINE_IFACE_FUNC(origin, Origin, ORIGIN, \
function, rettype, errval)
#define DEFINE_ORIGIN_GETTER(prop,rettype,errval) \
CALLS_DEFINE_IFACE_GETTER(origin, Origin, ORIGIN, prop, rettype, errval)
/**
* calls_origin_get_name:
......@@ -77,7 +91,7 @@ calls_origin_default_init (CallsOriginInterface *iface)
* Returns: A string containing the name. The string must be freed by
* the caller.
*/
DEFINE_ORIGIN_FUNC(get_name, const gchar *, NULL);
DEFINE_ORIGIN_GETTER(name, const gchar *, NULL);
/**
* calls_origin_get_calls:
......@@ -89,7 +103,33 @@ DEFINE_ORIGIN_FUNC(get_name, const gchar *, NULL);
* Returns: A newly-allocated GList of objects implementing
* #CallsCall or NULL if there was an error.
*/
DEFINE_ORIGIN_FUNC(get_calls, GList *, NULL);
DEFINE_ORIGIN_GETTER(calls, GList *, NULL);
/**
* calls_origin_foreach_call:
* @self: a #CallsOrigin
* @callback: function to be called for each call from the origin
* @param: user data for @callback
*
* Iterate over all current calls from this origin
**/
void
calls_origin_foreach_call(CallsOrigin *self,
CallsOriginForeachCallFunc callback,
gpointer param)
{
g_autoptr(GList) calls = NULL;
GList *node;
calls = calls_origin_get_calls (self);
for (node = calls; node; node = node->next)
{
callback (param, CALLS_CALL (node->data), self);
}
}
/**
* calls_origin_dial:
......
......@@ -42,15 +42,17 @@ struct _CallsOriginInterface
{
GTypeInterface parent_iface;
const gchar * (*get_name) (CallsOrigin *self);
GList * (*get_calls) (CallsOrigin *self);
void (*dial) (CallsOrigin *self,
const gchar *number);
};
typedef void (*CallsOriginForeachCallFunc) (gpointer param, CallsCall* call, CallsOrigin* origin);
const gchar * calls_origin_get_name (CallsOrigin *self);
GList * calls_origin_get_calls (CallsOrigin *self);
void calls_origin_foreach_call(CallsOrigin *self,
CallsOriginForeachCallFunc callback,
gpointer param);
void calls_origin_dial(CallsOrigin *self,
const gchar *number);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment