Turn providers into plugins courtesy of libpeas

This is an initial, static implementation of plugins.  The
CallsApplication has a plugin name which can be changed with a new
--provider command line option.  This plugin name is used to
instantiate the appropriate plugin when the application is activated.
From then on, the plugin cannot change.

In future, we can expand this support to include loading multiple
plugins at once, configurable through some UI.  This will have
far-reaching implications though, and complicate things like
enumerating the provider hierarchy.  There is also no practical
benefit right now; the mm and ofono plugins can't be used at the same
time because ModemManager and oFono don't play nice together, and the
whole raison d'être of the dummy plugin is undermined if you can make
use of one of the others.  So for now, we just implement one static
plugin.
This commit is contained in:
Bob Ham
2018-11-23 14:34:41 +00:00
parent b6cd5a3fe8
commit 460c0c6c3d
39 changed files with 672 additions and 181 deletions

View File

@@ -0,0 +1,219 @@
/*
* Copyright (C) 2018 Purism SPC
*
* 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
*
*/
#include "calls-dummy-call.h"
#include "calls-message-source.h"
#include "calls-call.h"
#include <glib/gi18n.h>
struct _CallsDummyCall
{
GObject parent_instance;
gchar *number;
CallsCallState state;
};
static void calls_dummy_call_message_source_interface_init (CallsCallInterface *iface);
static void calls_dummy_call_call_interface_init (CallsCallInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_call_message_source_interface_init)
G_IMPLEMENT_INTERFACE (CALLS_TYPE_CALL,
calls_dummy_call_call_interface_init))
enum {
PROP_0,
PROP_NUMBER,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static const gchar *
get_number (CallsCall *iface)
{
CallsDummyCall *self;
g_return_val_if_fail (CALLS_IS_DUMMY_CALL (iface), NULL);
self = CALLS_DUMMY_CALL (iface);
return self->number;
}
static const gchar *
get_name (CallsCall *iface)
{
return NULL;
}
static CallsCallState
get_state (CallsCall *call)
{
CallsDummyCall *self;
g_return_val_if_fail (CALLS_IS_DUMMY_CALL (call), 0);
self = CALLS_DUMMY_CALL (call);
return self->state;
}
static void
change_state (CallsCall *call,
CallsDummyCall *self,
CallsCallState state)
{
CallsCallState old_state = self->state;
if (old_state == state)
{
return;
}
self->state = state;
g_signal_emit_by_name (call,
"state-changed",
state,
old_state);
}
static void
answer (CallsCall *call)
{
CallsDummyCall *self;
g_return_if_fail (CALLS_IS_DUMMY_CALL (call));
self = CALLS_DUMMY_CALL (call);
g_return_if_fail (self->state == CALLS_CALL_STATE_INCOMING);
change_state (call, self, CALLS_CALL_STATE_ACTIVE);
}
static void
hang_up (CallsCall *call)
{
CallsDummyCall *self;
g_return_if_fail (CALLS_IS_DUMMY_CALL (call));
self = CALLS_DUMMY_CALL (call);
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);
}
CallsDummyCall *
calls_dummy_call_new (const gchar *number)
{
g_return_val_if_fail (number != NULL, NULL);
return g_object_new (CALLS_TYPE_DUMMY_CALL,
"number", number,
NULL);
}
static void
set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
switch (property_id) {
case PROP_NUMBER:
self->number = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
finalize (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
g_free (self->number);
parent_class->finalize (object);
}
static void
calls_dummy_call_class_init (CallsDummyCallClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = finalize;
object_class->set_property = set_property;
props[PROP_NUMBER] =
g_param_spec_string ("number",
_("Number"),
_("The dialed number"),
"+441234567890",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}
static void
calls_dummy_call_call_interface_init (CallsCallInterface *iface)
{
iface->get_number = get_number;
iface->get_name = get_name;
iface->get_state = get_state;
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)
{
}
static void
calls_dummy_call_init (CallsDummyCall *self)
{
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 Purism SPC
*
* 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
*
*/
#ifndef CALLS_DUMMY_CALL_H__
#define CALLS_DUMMY_CALL_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define CALLS_TYPE_DUMMY_CALL (calls_dummy_call_get_type ())
G_DECLARE_FINAL_TYPE (CallsDummyCall, calls_dummy_call, CALLS, DUMMY_CALL, GObject);
CallsDummyCall *calls_dummy_call_new (const gchar *number);
G_END_DECLS
#endif /* CALLS_DUMMY_CALL_H__ */

View File

@@ -0,0 +1,247 @@
/*
* Copyright (C) 2018 Purism SPC
*
* 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
*
*/
#include "calls-dummy-origin.h"
#include "calls-message-source.h"
#include "calls-origin.h"
#include "calls-dummy-call.h"
#include <glib/gi18n.h>
#include <glib-object.h>
struct _CallsDummyOrigin
{
GObject parent_instance;
GString *name;
GList *calls;
};
static void calls_dummy_origin_message_source_interface_init (CallsOriginInterface *iface);
static void calls_dummy_origin_origin_interface_init (CallsOriginInterface *iface);
G_DEFINE_TYPE_WITH_CODE (CallsDummyOrigin, calls_dummy_origin, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_origin_message_source_interface_init)
G_IMPLEMENT_INTERFACE (CALLS_TYPE_ORIGIN,
calls_dummy_origin_origin_interface_init))
enum {
PROP_0,
PROP_NAME,
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,
const gchar *reason)
{
CallsOrigin *origin;
origin = CALLS_ORIGIN (self);
g_signal_emit_by_name (origin, "call-removed", call, reason);
self->calls = g_list_remove (self->calls, call);
g_object_unref (G_OBJECT (call));
}
static void
remove_calls (CallsDummyOrigin *self, const gchar *reason)
{
GList *node, *next;
for (node = self->calls; node; node = next)
{
next = node->next;
remove_call (self, CALLS_CALL (node->data), reason);
}
}
static void
call_state_changed_cb (CallsDummyOrigin *self,
CallsCallState new_state,
CallsCallState old_state,
CallsCall *call)
{
if (new_state != CALLS_CALL_STATE_DISCONNECTED)
{
return;
}
g_return_if_fail (CALLS_IS_DUMMY_ORIGIN (self));
g_return_if_fail (CALLS_IS_CALL (call));
remove_call (self, call, "Disconnected");
}
static void
dial (CallsOrigin *origin, const gchar *number)
{
CallsDummyOrigin *self;
CallsDummyCall *dummy_call;
CallsCall *call;
g_return_if_fail (number != NULL);
g_return_if_fail (CALLS_IS_DUMMY_ORIGIN (origin));
self = CALLS_DUMMY_ORIGIN (origin);
dummy_call = calls_dummy_call_new (number);
g_return_if_fail (dummy_call != NULL);
call = CALLS_CALL (dummy_call);
g_signal_connect_swapped (call, "state-changed",
G_CALLBACK (call_state_changed_cb),
self);
self->calls = g_list_append (self->calls, dummy_call);
g_signal_emit_by_name (origin, "call-added", call);
}
CallsDummyOrigin *
calls_dummy_origin_new (const gchar *name)
{
return g_object_new (CALLS_TYPE_DUMMY_ORIGIN,
"name", name,
NULL);
}
static void
set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CallsDummyOrigin *self = CALLS_DUMMY_ORIGIN (object);
switch (property_id) {
case PROP_NAME:
g_string_assign (self->name, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsDummyOrigin *self = CALLS_DUMMY_ORIGIN (object);
remove_calls (self, NULL);
parent_class->dispose (object);
}
static void
finalize (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsDummyOrigin *self = CALLS_DUMMY_ORIGIN (object);
g_string_free (self->name, TRUE);
parent_class->finalize (object);
}
static void
calls_dummy_origin_class_init (CallsDummyOriginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->set_property = set_property;
props[PROP_NAME] =
g_param_spec_string ("name",
_("Name"),
_("The name of the origin"),
"Dummy origin",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}
static void
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;
}
static void
calls_dummy_origin_init (CallsDummyOrigin *self)
{
self->name = g_string_new (NULL);
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 Purism SPC
*
* 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
*
*/
#ifndef CALLS_DUMMY_ORIGIN_H__
#define CALLS_DUMMY_ORIGIN_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define CALLS_TYPE_DUMMY_ORIGIN (calls_dummy_origin_get_type ())
G_DECLARE_FINAL_TYPE (CallsDummyOrigin, calls_dummy_origin, CALLS, DUMMY_ORIGIN, GObject);
CallsDummyOrigin *calls_dummy_origin_new (const gchar *name);
G_END_DECLS
#endif /* CALLS_DUMMY_ORIGIN_H__ */

View File

@@ -0,0 +1,195 @@
/*
* Copyright (C) 2018 Purism SPC
*
* 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
*
*/
#include "calls-dummy-provider.h"
#include "calls-message-source.h"
#include "calls-provider.h"
#include "calls-dummy-origin.h"
#include <libpeas/peas.h>
struct _CallsDummyProvider
{
GObject parent_instance;
GList *origins;
};
static void calls_dummy_provider_message_source_interface_init (CallsProviderInterface *iface);
static void calls_dummy_provider_provider_interface_init (CallsProviderInterface *iface);
#ifdef FOR_TESTING
G_DEFINE_TYPE_WITH_CODE
(CallsDummyProvider, calls_dummy_provider, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_provider_message_source_interface_init)
G_IMPLEMENT_INTERFACE (CALLS_TYPE_PROVIDER,
calls_dummy_provider_provider_interface_init))
#else
G_DEFINE_DYNAMIC_TYPE_EXTENDED
(CallsDummyProvider, calls_dummy_provider, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE,
calls_dummy_provider_message_source_interface_init)
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_PROVIDER,
calls_dummy_provider_provider_interface_init))
#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 void
constructed (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (object);
calls_dummy_provider_add_origin (self, "Dummy origin");
parent_class->constructed (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
dispose (GObject *object)
{
GObjectClass *parent_class = g_type_class_peek (G_TYPE_OBJECT);
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (object);
g_list_free_full (self->origins, g_object_unref);
self->origins = NULL;
parent_class->dispose (object);
}
static void
calls_dummy_provider_class_init (CallsDummyProviderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose;
g_object_class_override_property (object_class, PROP_STATUS, "status");
}
static void
calls_dummy_provider_message_source_interface_init (CallsProviderInterface *iface)
{
}
static void
calls_dummy_provider_provider_interface_init (CallsProviderInterface *iface)
{
iface->get_name = get_name;
iface->get_origins = get_origins;
}
static void
calls_dummy_provider_init (CallsDummyProvider *self)
{
}
void
calls_dummy_provider_add_origin (CallsDummyProvider *self,
const gchar *name)
{
self->origins = g_list_append (self->origins,
calls_dummy_origin_new (name));
}
CallsDummyProvider *
calls_dummy_provider_new ()
{
return g_object_new (CALLS_TYPE_DUMMY_PROVIDER, NULL);
}
#ifndef FOR_TESTING
static void
calls_dummy_provider_class_finalize (CallsDummyProviderClass *klass)
{
}
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
calls_dummy_provider_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
CALLS_TYPE_PROVIDER,
CALLS_TYPE_DUMMY_PROVIDER);
}
#endif /* FOR_TESTING */

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2018 Purism SPC
*
* 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
*
*/
#ifndef CALLS_DUMMY_PROVIDER_H__
#define CALLS_DUMMY_PROVIDER_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define CALLS_TYPE_DUMMY_PROVIDER (calls_dummy_provider_get_type ())
G_DECLARE_FINAL_TYPE (CallsDummyProvider, calls_dummy_provider, CALLS, DUMMY_PROVIDER, GObject);
CallsDummyProvider *calls_dummy_provider_new ();
void calls_dummy_provider_add_origin (CallsDummyProvider *self,
const gchar *name);
G_END_DECLS
#endif /* CALLS_DUMMY_PROVIDER_H__ */

View File

@@ -0,0 +1,7 @@
[Plugin]
Module=dummy
Name=Dummy
Description=Dummy calls provider
Authors=Bob Ham <rah@settrans.net>
Copyright=Copyright (C) 2018 Purism SPC
Website=@PACKAGE_URL_RAW@

56
plugins/dummy/meson.build Normal file
View File

@@ -0,0 +1,56 @@
#
# Copyright (C) 2018 Purism SPC
#
# 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
#
dummy_include = include_directories('.')
dummy_install_dir = join_paths(full_calls_plugin_libdir, 'dummy')
dummy_plugin = configure_file(
input: 'dummy.plugin.in',
output: 'dummy.plugin',
configuration: config_data,
install_dir: dummy_install_dir
)
dummy_deps = [
dependency('gobject-2.0'),
dependency('gtk+-3.0'),
dependency('libpeas-1.0'),
]
dummy_sources = files(
[
'calls-dummy-call.c', 'calls-dummy-call.h',
'calls-dummy-origin.c', 'calls-dummy-origin.h',
'calls-dummy-provider.c', 'calls-dummy-provider.h'
]
)
shared_module(
'dummy',
dummy_sources,
dependencies: dummy_deps,
include_directories: src_include,
install: true,
install_dir: dummy_install_dir
)