1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-11-04 15:41:19 +00:00

Let calls-provider be an abstract class

And adapt to changes.

A calls-mm-provider IS-A calls-provider (and so on)
This commit is contained in:
Mohammed Sadiq 2021-01-25 21:02:14 +05:30 committed by Evangelos Ribeiro Tzaras
parent 1c8eb87e7f
commit 5684d54bbd
8 changed files with 177 additions and 201 deletions

View file

@ -33,55 +33,30 @@
struct _CallsDummyProvider struct _CallsDummyProvider
{ {
GObject parent_instance; CallsProvider parent_instance;
GList *origins; GList *origins;
}; };
static void calls_dummy_provider_message_source_interface_init (CallsProviderInterface *iface); static void calls_dummy_provider_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_dummy_provider_provider_interface_init (CallsProviderInterface *iface);
#ifdef FOR_TESTING #ifdef FOR_TESTING
G_DEFINE_TYPE_WITH_CODE G_DEFINE_TYPE_WITH_CODE
(CallsDummyProvider, calls_dummy_provider, G_TYPE_OBJECT, (CallsDummyProvider, calls_dummy_provider, CALLS_TYPE_PROVIDER,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_provider_message_source_interface_init) calls_dummy_provider_message_source_interface_init))
G_IMPLEMENT_INTERFACE (CALLS_TYPE_PROVIDER,
calls_dummy_provider_provider_interface_init))
#else #else
G_DEFINE_DYNAMIC_TYPE_EXTENDED G_DEFINE_DYNAMIC_TYPE_EXTENDED
(CallsDummyProvider, calls_dummy_provider, G_TYPE_OBJECT, 0, (CallsDummyProvider, calls_dummy_provider, CALLS_TYPE_PROVIDER, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_provider_message_source_interface_init) calls_dummy_provider_message_source_interface_init))
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_PROVIDER,
calls_dummy_provider_provider_interface_init))
#endif /* FOR_TESTING */ #endif /* FOR_TESTING */
enum {
PROP_0,
PROP_STATUS,
PROP_LAST_PROP,
};
static const gchar *
get_name (CallsProvider *iface)
{
return "Dummy provider";
}
static GList *
get_origins (CallsProvider *iface)
{
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (iface);
return g_list_copy (self->origins);
}
static gboolean static gboolean
usr1_handler (CallsDummyProvider *self) usr1_handler (CallsDummyProvider *self)
@ -98,6 +73,25 @@ usr1_handler (CallsDummyProvider *self)
return TRUE; return TRUE;
} }
static const char *
calls_dummy_provider_get_name (CallsProvider *provider)
{
return "Dummy provider";
}
static const char *
calls_dummy_provider_get_status (CallsProvider *provider)
{
return "Normal";
}
static GList *
calls_dummy_provider_get_origins (CallsProvider *provider)
{
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (provider);
return g_list_copy (self->origins);
}
static void static void
constructed (GObject *object) constructed (GObject *object)
@ -114,24 +108,6 @@ constructed (GObject *object)
} }
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_STATUS:
g_value_set_string (value, "Normal");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void static void
dispose (GObject *object) dispose (GObject *object)
{ {
@ -157,29 +133,23 @@ static void
calls_dummy_provider_class_init (CallsDummyProviderClass *klass) calls_dummy_provider_class_init (CallsDummyProviderClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsProviderClass *provider_class = CALLS_PROVIDER_CLASS (klass);
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose; object_class->dispose = dispose;
g_object_class_override_property (object_class, PROP_STATUS, "status"); provider_class->get_name = calls_dummy_provider_get_name;
provider_class->get_status = calls_dummy_provider_get_status;
provider_class->get_origins = calls_dummy_provider_get_origins;
} }
static void static void
calls_dummy_provider_message_source_interface_init (CallsProviderInterface *iface) calls_dummy_provider_message_source_interface_init (CallsMessageSourceInterface *iface)
{ {
} }
static void
calls_dummy_provider_provider_interface_init (CallsProviderInterface *iface)
{
iface->get_name = get_name;
iface->get_origins = get_origins;
}
static void static void
calls_dummy_provider_init (CallsDummyProvider *self) calls_dummy_provider_init (CallsDummyProvider *self)
{ {

View file

@ -27,11 +27,13 @@
#include <glib-object.h> #include <glib-object.h>
#include "calls-provider.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLS_TYPE_DUMMY_PROVIDER (calls_dummy_provider_get_type ()) #define CALLS_TYPE_DUMMY_PROVIDER (calls_dummy_provider_get_type ())
G_DECLARE_FINAL_TYPE (CallsDummyProvider, calls_dummy_provider, CALLS, DUMMY_PROVIDER, GObject); G_DECLARE_FINAL_TYPE (CallsDummyProvider, calls_dummy_provider, CALLS, DUMMY_PROVIDER, CallsProvider)
CallsDummyProvider *calls_dummy_provider_new (); CallsDummyProvider *calls_dummy_provider_new ();
void calls_dummy_provider_add_origin (CallsDummyProvider *self, void calls_dummy_provider_add_origin (CallsDummyProvider *self,

View file

@ -34,7 +34,7 @@
struct _CallsMMProvider struct _CallsMMProvider
{ {
GObject parent_instance; CallsProvider parent_instance;
/* The status property */ /* The status property */
gchar *status; gchar *status;
@ -46,37 +46,12 @@ struct _CallsMMProvider
GHashTable *origins; GHashTable *origins;
}; };
static void calls_mm_provider_message_source_interface_init (CallsProviderInterface *iface); static void calls_mm_provider_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_mm_provider_provider_interface_init (CallsProviderInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED G_DEFINE_DYNAMIC_TYPE_EXTENDED
(CallsMMProvider, calls_mm_provider, G_TYPE_OBJECT, 0, (CallsMMProvider, calls_mm_provider, CALLS_TYPE_PROVIDER, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE,
calls_mm_provider_message_source_interface_init) calls_mm_provider_message_source_interface_init))
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_PROVIDER,
calls_mm_provider_provider_interface_init))
enum {
PROP_0,
PROP_STATUS,
PROP_LAST_PROP,
};
static const gchar *
get_name (CallsProvider *iface)
{
return "ModemManager";
}
static GList *
get_origins (CallsProvider *iface)
{
CallsMMProvider *self = CALLS_MM_PROVIDER (iface);
return g_hash_table_get_values (self->origins);
}
static void static void
@ -357,6 +332,28 @@ mm_vanished_cb (GDBusConnection *connection,
} }
static const char *
calls_mm_provider_get_name (CallsProvider *provider)
{
return "ModemManager";
}
static const char *
calls_mm_provider_get_status (CallsProvider *provider)
{
CallsMMProvider *self = CALLS_MM_PROVIDER (provider);
return self->status;
}
static GList *
calls_mm_provider_get_origins (CallsProvider *provider)
{
CallsMMProvider *self = CALLS_MM_PROVIDER (provider);
return g_hash_table_get_values (self->origins);
}
static void static void
constructed (GObject *object) constructed (GObject *object)
{ {
@ -376,26 +373,6 @@ constructed (GObject *object)
} }
static void
get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
CallsMMProvider *self = CALLS_MM_PROVIDER (object);
switch (property_id) {
case PROP_STATUS:
g_value_set_string (value, self->status);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void static void
dispose (GObject *object) dispose (GObject *object)
{ {
@ -429,13 +406,15 @@ static void
calls_mm_provider_class_init (CallsMMProviderClass *klass) calls_mm_provider_class_init (CallsMMProviderClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsProviderClass *provider_class = CALLS_PROVIDER_CLASS (klass);
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->finalize = finalize; object_class->finalize = finalize;
g_object_class_override_property (object_class, PROP_STATUS, "status"); provider_class->get_name = calls_mm_provider_get_name;
provider_class->get_status = calls_mm_provider_get_status;
provider_class->get_origins = calls_mm_provider_get_origins;
} }
@ -445,19 +424,11 @@ calls_mm_provider_class_finalize (CallsMMProviderClass *klass)
} }
static void static void
calls_mm_provider_message_source_interface_init (CallsProviderInterface *iface) calls_mm_provider_message_source_interface_init (CallsMessageSourceInterface *iface)
{ {
} }
static void
calls_mm_provider_provider_interface_init (CallsProviderInterface *iface)
{
iface->get_name = get_name;
iface->get_origins = get_origins;
}
static void static void
calls_mm_provider_init (CallsMMProvider *self) calls_mm_provider_init (CallsMMProvider *self)
{ {

View file

@ -28,11 +28,13 @@
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "calls-provider.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLS_TYPE_MM_PROVIDER (calls_mm_provider_get_type ()) #define CALLS_TYPE_MM_PROVIDER (calls_mm_provider_get_type ())
G_DECLARE_FINAL_TYPE (CallsMMProvider, calls_mm_provider, CALLS, MM_PROVIDER, GObject); G_DECLARE_FINAL_TYPE (CallsMMProvider, calls_mm_provider, CALLS, MM_PROVIDER, CallsProvider)
G_END_DECLS G_END_DECLS

View file

@ -37,7 +37,7 @@
struct _CallsOfonoProvider struct _CallsOfonoProvider
{ {
GObject parent_instance; CallsProvider parent_instance;
/** D-Bus connection */ /** D-Bus connection */
GDBusConnection *connection; GDBusConnection *connection;
@ -50,23 +50,13 @@ struct _CallsOfonoProvider
}; };
static void calls_ofono_provider_message_source_interface_init (CallsProviderInterface *iface); static void calls_ofono_provider_message_source_interface_init (CallsMessageSourceInterface *iface);
static void calls_ofono_provider_provider_interface_init (CallsProviderInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED G_DEFINE_DYNAMIC_TYPE_EXTENDED
(CallsOfonoProvider, calls_ofono_provider, G_TYPE_OBJECT, 0, (CallsOfonoProvider, calls_ofono_provider, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE, G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE,
calls_ofono_provider_message_source_interface_init) calls_ofono_provider_message_source_interface_init))
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_PROVIDER,
calls_ofono_provider_provider_interface_init))
static const gchar *
get_name (CallsProvider *iface)
{
return "oFono";
}
static void static void
@ -78,19 +68,6 @@ add_origin_to_list (const gchar *path,
} }
static GList *
get_origins (CallsProvider *iface)
{
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (iface);
GList *list = NULL;
g_hash_table_foreach (self->origins,
(GHFunc)add_origin_to_list, &list);
return g_list_reverse (list);
}
static void static void
add_origin (CallsOfonoProvider *self, add_origin (CallsOfonoProvider *self,
const gchar *path, const gchar *path,
@ -376,6 +353,30 @@ get_modems_cb (GDBOManager *manager,
g_variant_unref (modems); g_variant_unref (modems);
} }
static const char *
calls_ofono_provider_get_name (CallsProvider *provider)
{
return "Ofono";
}
static const char *
calls_ofono_provider_get_status (CallsProvider *provider)
{
return "";
}
static GList *
calls_ofono_provider_get_origins (CallsProvider *provider)
{
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (provider);
GList *list = NULL;
g_hash_table_foreach (self->origins,
(GHFunc)add_origin_to_list, &list);
return g_list_reverse (list);
}
static void static void
constructed (GObject *object) constructed (GObject *object)
@ -446,10 +447,15 @@ static void
calls_ofono_provider_class_init (CallsOfonoProviderClass *klass) calls_ofono_provider_class_init (CallsOfonoProviderClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
CallsProviderClass *provider_class = CALLS_PROVIDER_CLASS (klass);
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->dispose = dispose; object_class->dispose = dispose;
object_class->finalize = finalize; object_class->finalize = finalize;
provider_class->get_name = calls_ofono_provider_get_name;
provider_class->get_status = calls_ofono_provider_get_status;
provider_class->get_origins = calls_ofono_provider_get_origins;
} }
@ -460,19 +466,11 @@ calls_ofono_provider_class_finalize (CallsOfonoProviderClass *klass)
static void static void
calls_ofono_provider_message_source_interface_init (CallsProviderInterface *iface) calls_ofono_provider_message_source_interface_init (CallsMessageSourceInterface *iface)
{ {
} }
static void
calls_ofono_provider_provider_interface_init (CallsProviderInterface *iface)
{
iface->get_name = get_name;
iface->get_origins = get_origins;
}
static void static void
calls_ofono_provider_init (CallsOfonoProvider *self) calls_ofono_provider_init (CallsOfonoProvider *self)
{ {

View file

@ -28,11 +28,13 @@
#include <glib-object.h> #include <glib-object.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "calls-provider.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define CALLS_TYPE_OFONO_PROVIDER (calls_ofono_provider_get_type ()) #define CALLS_TYPE_OFONO_PROVIDER (calls_ofono_provider_get_type ())
G_DECLARE_FINAL_TYPE (CallsOfonoProvider, calls_ofono_provider, CALLS, OFONO_PROVIDER, GObject); G_DECLARE_FINAL_TYPE (CallsOfonoProvider, calls_ofono_provider, CALLS, OFONO_PROVIDER, CallsProvider)
G_END_DECLS G_END_DECLS

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Purism SPC * Copyright (C) 2018,2021 Purism SPC
* *
* This file is part of Calls. * This file is part of Calls.
* *
@ -35,7 +35,7 @@
* oFono, Telepathy or some SIP library. * oFono, Telepathy or some SIP library.
* @Title: CallsProvider * @Title: CallsProvider
* *
* The #CallsProvider interface is the root of the interface tree that * The #CallsProvider abstract class is the root of the class tree that
* needs to be implemented by a call provider. A #CallsProvider * needs to be implemented by a call provider. A #CallsProvider
* provides access to a list of #CallsOrigin interfaces, through the * provides access to a list of #CallsOrigin interfaces, through the
* #calls_provider_get_origins function and the #origin-added and * #calls_provider_get_origins function and the #origin-added and
@ -43,7 +43,12 @@
*/ */
G_DEFINE_INTERFACE (CallsProvider, calls_provider, CALLS_TYPE_MESSAGE_SOURCE); typedef struct
{
int dummy;
} CallsProviderPrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (CallsProvider, calls_provider, G_TYPE_OBJECT)
enum { enum {
PROP_0, PROP_0,
@ -61,39 +66,59 @@ enum {
static guint signals [SIGNAL_LAST_SIGNAL]; static guint signals [SIGNAL_LAST_SIGNAL];
static void static void
calls_provider_default_init (CallsProviderInterface *iface) calls_provider_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{ {
GType arg_types = CALLS_TYPE_ORIGIN; CallsProvider *self = CALLS_PROVIDER (object);
switch (prop_id)
{
case PROP_STATUS:
g_value_set_string (value, calls_provider_get_status (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
calls_provider_class_init (CallsProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = calls_provider_get_property;
props[PROP_STATUS] = props[PROP_STATUS] =
g_param_spec_string ("status", g_param_spec_string ("status",
"Status", "Status",
"A text string describing the status for display to the user", "A text string describing the status for display to the user",
"", "",
G_PARAM_READABLE); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_interface_install_property (iface, props[PROP_STATUS]); g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
signals[SIGNAL_ORIGIN_ADDED] = signals[SIGNAL_ORIGIN_ADDED] =
g_signal_newv ("origin-added", g_signal_new ("origin-added",
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, 1, CALLS_TYPE_ORIGIN);
1, &arg_types);
signals[SIGNAL_ORIGIN_REMOVED] = signals[SIGNAL_ORIGIN_REMOVED] =
g_signal_newv ("origin-removed", g_signal_new ("origin-removed",
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, 1, CALLS_TYPE_ORIGIN);
1, &arg_types);
} }
#define DEFINE_PROVIDER_FUNC(function,rettype,errval) \ static void
CALLS_DEFINE_IFACE_FUNC(provider, Provider, PROVIDER, \ calls_provider_init (CallsProvider *self)
function, rettype, errval) {
}
/** /**
* calls_provider_get_name: * calls_provider_get_name:
@ -103,22 +128,21 @@ calls_provider_default_init (CallsProviderInterface *iface)
* *
* Returns: A string containing the name. * Returns: A string containing the name.
*/ */
DEFINE_PROVIDER_FUNC(get_name, const gchar *, NULL); const char *
calls_provider_get_name (CallsProvider *self)
gchar *
calls_provider_get_status (CallsProvider *self)
{ {
gchar *status;
g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL); g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL);
g_object_get (G_OBJECT (self), return CALLS_PROVIDER_GET_CLASS (self)->get_name (self);
"status", &status,
NULL);
return status;
} }
const char *
calls_provider_get_status (CallsProvider *self)
{
g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL);
return CALLS_PROVIDER_GET_CLASS (self)->get_status (self);
}
/** /**
* calls_provider_get_origins: * calls_provider_get_origins:
@ -130,4 +154,10 @@ calls_provider_get_status (CallsProvider *self)
* Returns: A newly-allocated GList of objects implementing * Returns: A newly-allocated GList of objects implementing
* #CallsOrigin or NULL if there was an error. * #CallsOrigin or NULL if there was an error.
*/ */
DEFINE_PROVIDER_FUNC(get_origins, GList *, NULL); GList *
calls_provider_get_origins (CallsProvider *self)
{
g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL);
return CALLS_PROVIDER_GET_CLASS (self)->get_origins (self);
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 Purism SPC * Copyright (C) 2018,2021 Purism SPC
* *
* This file is part of Calls. * This file is part of Calls.
* *
@ -37,21 +37,22 @@ G_BEGIN_DECLS
#define CALLS_TYPE_PROVIDER (calls_provider_get_type ()) #define CALLS_TYPE_PROVIDER (calls_provider_get_type ())
G_DECLARE_INTERFACE (CallsProvider, calls_provider, CALLS, PROVIDER, GObject); G_DECLARE_DERIVABLE_TYPE (CallsProvider, calls_provider, CALLS, PROVIDER, GObject)
struct _CallsProviderInterface struct _CallsProviderClass
{ {
GTypeInterface parent_iface; GObjectClass parent_iface;
const gchar * (*get_name) (CallsProvider *self); const char *(*get_name) (CallsProvider *self);
GList * (*get_origins) (CallsProvider *self); const char *(*get_status) (CallsProvider *self);
GList *(*get_origins) (CallsProvider *self);
}; };
const gchar * calls_provider_get_name (CallsProvider *self); const char *calls_provider_get_name (CallsProvider *self);
gchar * calls_provider_get_status (CallsProvider *self); const char *calls_provider_get_status (CallsProvider *self);
GList * calls_provider_get_origins (CallsProvider *self); GList *calls_provider_get_origins (CallsProvider *self);
G_END_DECLS G_END_DECLS