2018-05-17 13:16:51 +00:00
|
|
|
/*
|
2021-01-25 15:32:14 +00:00
|
|
|
* Copyright (C) 2018,2021 Purism SPC
|
2018-05-17 13:16:51 +00:00
|
|
|
*
|
|
|
|
* This file is part of Calls.
|
|
|
|
*
|
|
|
|
* Calls is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calls is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Bob Ham <bob.ham@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-06-18 09:10:36 +00:00
|
|
|
#define G_LOG_DOMAIN "CallsProvider"
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "calls-provider.h"
|
|
|
|
#include "calls-origin.h"
|
|
|
|
#include "calls-message-source.h"
|
2021-04-02 14:04:07 +00:00
|
|
|
#include "config.h"
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2018-10-19 10:19:41 +00:00
|
|
|
#include <glib/gi18n.h>
|
2021-04-02 14:04:07 +00:00
|
|
|
#include <libpeas/peas.h>
|
2018-10-19 10:19:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
/**
|
|
|
|
* SECTION:calls-provider
|
|
|
|
* @short_description: An abstraction of call providers, such as
|
|
|
|
* oFono, Telepathy or some SIP library.
|
|
|
|
* @Title: CallsProvider
|
|
|
|
*
|
2021-01-25 15:32:14 +00:00
|
|
|
* The #CallsProvider abstract class is the root of the class tree that
|
2018-05-17 13:16:51 +00:00
|
|
|
* needs to be implemented by a call provider. A #CallsProvider
|
|
|
|
* provides access to a list of #CallsOrigin interfaces, through the
|
|
|
|
* #calls_provider_get_origins function and the #origin-added and
|
|
|
|
* #origin-removed signals.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-04-03 01:52:27 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (CallsProvider, calls_provider, G_TYPE_OBJECT)
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2018-10-19 10:19:41 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_STATUS,
|
|
|
|
PROP_LAST_PROP,
|
|
|
|
};
|
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
|
|
|
|
2021-04-04 12:46:48 +00:00
|
|
|
static const char *
|
|
|
|
calls_provider_real_get_name (CallsProvider *self)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
calls_provider_real_get_status (CallsProvider *self)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-02 17:42:25 +00:00
|
|
|
static GListModel *
|
2021-04-04 12:46:48 +00:00
|
|
|
calls_provider_real_get_origins (CallsProvider *self)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-19 17:07:00 +00:00
|
|
|
static const char * const *
|
|
|
|
calls_provider_real_get_protocols (CallsProvider *self)
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:49:07 +00:00
|
|
|
static gboolean
|
|
|
|
calls_provider_real_is_modem (CallsProvider *self)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
calls_provider_real_is_operational (CallsProvider *self)
|
|
|
|
{
|
|
|
|
GListModel *origins;
|
|
|
|
|
|
|
|
origins = calls_provider_get_origins (self);
|
|
|
|
|
|
|
|
if (origins)
|
|
|
|
return !!g_list_model_get_n_items (origins);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-10-19 10:19:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2021-01-25 15:32:14 +00:00
|
|
|
calls_provider_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsProvider *self = CALLS_PROVIDER (object);
|
|
|
|
|
2021-05-04 15:12:07 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-01-25 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_provider_class_init (CallsProviderClass *klass)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2021-01-25 15:32:14 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = calls_provider_get_property;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-04-04 12:46:48 +00:00
|
|
|
klass->get_name = calls_provider_real_get_name;
|
|
|
|
klass->get_status = calls_provider_real_get_status;
|
|
|
|
klass->get_origins = calls_provider_real_get_origins;
|
2021-04-19 17:07:00 +00:00
|
|
|
klass->get_protocols = calls_provider_real_get_protocols;
|
2021-05-04 19:49:07 +00:00
|
|
|
klass->is_modem = calls_provider_real_is_modem;
|
|
|
|
klass->is_operational = calls_provider_real_is_operational;
|
2021-04-04 12:46:48 +00:00
|
|
|
|
2018-10-19 10:19:41 +00:00
|
|
|
props[PROP_STATUS] =
|
|
|
|
g_param_spec_string ("status",
|
2020-05-29 05:38:11 +00:00
|
|
|
"Status",
|
|
|
|
"A text string describing the status for display to the user",
|
2018-10-19 10:19:41 +00:00
|
|
|
"",
|
2021-01-25 15:32:14 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2018-10-19 10:19:41 +00:00
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
static void
|
|
|
|
calls_provider_init (CallsProvider *self)
|
|
|
|
{
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_provider_get_name:
|
|
|
|
* @self: a #CallsProvider
|
|
|
|
*
|
|
|
|
* Get the user-presentable name of the provider.
|
|
|
|
*
|
|
|
|
* Returns: A string containing the name.
|
|
|
|
*/
|
2021-01-25 15:32:14 +00:00
|
|
|
const char *
|
|
|
|
calls_provider_get_name (CallsProvider *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL);
|
|
|
|
|
|
|
|
return CALLS_PROVIDER_GET_CLASS (self)->get_name (self);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
const char *
|
2018-10-19 10:19:41 +00:00
|
|
|
calls_provider_get_status (CallsProvider *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL);
|
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
return CALLS_PROVIDER_GET_CLASS (self)->get_status (self);
|
2018-10-19 10:19:41 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
/**
|
|
|
|
* calls_provider_get_origins:
|
|
|
|
* @self: a #CallsProvider
|
|
|
|
* @error: a #GError, or #NULL
|
|
|
|
*
|
|
|
|
* Get the list of #CallsOrigin interfaces offered by this provider.
|
|
|
|
*
|
2021-04-26 08:29:24 +00:00
|
|
|
* Returns: (transfer none): A #GListModel of origins
|
2018-05-17 13:16:51 +00:00
|
|
|
*/
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *
|
2021-01-25 15:32:14 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-04-02 14:04:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_provider_load_plugin:
|
|
|
|
* @name: The name of the provider plugin to load
|
|
|
|
*
|
|
|
|
* Get a #CallsProvider plugin by name
|
|
|
|
*
|
2021-04-26 08:29:24 +00:00
|
|
|
* Returns: (transfer full): A #CallsProvider
|
2021-04-02 14:04:07 +00:00
|
|
|
*/
|
|
|
|
CallsProvider *
|
|
|
|
calls_provider_load_plugin (const char *name)
|
|
|
|
{
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
PeasEngine *plugins;
|
|
|
|
PeasPluginInfo *info;
|
|
|
|
PeasExtension *extension;
|
|
|
|
|
|
|
|
plugins = peas_engine_get_default ();
|
|
|
|
|
|
|
|
// Find the plugin
|
|
|
|
info = peas_engine_get_plugin_info (plugins, name);
|
2021-05-04 15:12:07 +00:00
|
|
|
if (!info) {
|
|
|
|
g_debug ("Could not find plugin `%s'", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-04-02 14:04:07 +00:00
|
|
|
|
|
|
|
// Possibly load the plugin
|
2021-05-04 15:12:07 +00:00
|
|
|
if (!peas_plugin_info_is_loaded (info)) {
|
|
|
|
peas_engine_load_plugin (plugins, info);
|
2021-04-02 14:04:07 +00:00
|
|
|
|
2021-05-04 15:12:07 +00:00
|
|
|
if (!peas_plugin_info_is_available (info, &error)) {
|
|
|
|
g_debug ("Error loading plugin `%s': %s", name, error->message);
|
|
|
|
return NULL;
|
2021-04-02 14:04:07 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 15:12:07 +00:00
|
|
|
g_debug ("Loaded plugin `%s'", name);
|
|
|
|
}
|
|
|
|
|
2021-04-02 14:04:07 +00:00
|
|
|
// Check the plugin provides CallsProvider
|
2021-05-04 15:12:07 +00:00
|
|
|
if (!peas_engine_provides_extension (plugins, info, CALLS_TYPE_PROVIDER)) {
|
|
|
|
g_debug ("Plugin `%s' does not have a provider extension", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-04-02 14:04:07 +00:00
|
|
|
|
|
|
|
// Get the extension
|
|
|
|
extension = peas_engine_create_extensionv (plugins, info, CALLS_TYPE_PROVIDER, 0, NULL);
|
2021-05-04 15:12:07 +00:00
|
|
|
if (!extension) {
|
|
|
|
g_debug ("Could not create provider from plugin `%s'", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-04-02 14:04:07 +00:00
|
|
|
|
|
|
|
g_debug ("Created provider from plugin `%s'", name);
|
|
|
|
return CALLS_PROVIDER (extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
calls_provider_unload_plugin (const char *name)
|
|
|
|
{
|
|
|
|
PeasEngine *engine = peas_engine_get_default ();
|
|
|
|
PeasPluginInfo *plugin = peas_engine_get_plugin_info (engine, name);
|
|
|
|
|
|
|
|
if (plugin)
|
|
|
|
peas_engine_unload_plugin (engine, plugin);
|
|
|
|
else
|
|
|
|
g_warning ("Can't unload plugin: No plugin with name %s found", name);
|
|
|
|
}
|
2021-04-19 17:07:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_provider_get_protocols:
|
|
|
|
* @self: A #CallsProvider
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): A null-terminated array of strings
|
|
|
|
*/
|
|
|
|
const char * const *
|
|
|
|
calls_provider_get_protocols (CallsProvider *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (self), NULL);
|
|
|
|
|
|
|
|
return CALLS_PROVIDER_GET_CLASS (self)->get_protocols (self);
|
|
|
|
}
|
2021-05-04 19:49:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_provider_is_modem:
|
|
|
|
* @self: A #CallsProvider
|
|
|
|
*
|
|
|
|
* Returns: %TRUE is this provider handles modems, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
calls_provider_is_modem (CallsProvider *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (self), FALSE);
|
|
|
|
|
|
|
|
return CALLS_PROVIDER_GET_CLASS (self)->is_modem (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_provider_is_operational:
|
|
|
|
* @self: A #CallsProvider
|
|
|
|
*
|
|
|
|
* Returns: %TRUE is this provider is operational, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* If not subclassed this method will simply test if there are any
|
|
|
|
* origins available.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
calls_provider_is_operational (CallsProvider *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (self), FALSE);
|
|
|
|
|
|
|
|
return CALLS_PROVIDER_GET_CLASS (self)->is_operational (self);
|
|
|
|
}
|