2018-05-17 13:16:51 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-06-18 09:10:36 +00:00
|
|
|
#define G_LOG_DOMAIN "CallsDummyProvider"
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "calls-dummy-provider.h"
|
2018-06-11 11:42:16 +00:00
|
|
|
#include "calls-message-source.h"
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "calls-provider.h"
|
|
|
|
#include "calls-dummy-origin.h"
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
#include <libpeas/peas.h>
|
2019-06-25 10:14:16 +00:00
|
|
|
#include <glib-unix.h>
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-04-19 17:07:00 +00:00
|
|
|
static const char * const supported_protocols[] = {
|
|
|
|
"tel",
|
|
|
|
NULL
|
|
|
|
};
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct _CallsDummyProvider {
|
2021-01-25 15:32:14 +00:00
|
|
|
CallsProvider parent_instance;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
GListStore *origins;
|
2018-05-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
static void calls_dummy_provider_message_source_interface_init (CallsMessageSourceInterface *iface);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
#ifdef FOR_TESTING
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE
|
2022-04-24 10:24:55 +00:00
|
|
|
(CallsDummyProvider, calls_dummy_provider, CALLS_TYPE_PROVIDER,
|
|
|
|
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
|
|
|
|
calls_dummy_provider_message_source_interface_init))
|
2018-11-23 14:34:41 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
G_DEFINE_DYNAMIC_TYPE_EXTENDED
|
2022-04-24 10:24:55 +00:00
|
|
|
(CallsDummyProvider, calls_dummy_provider, CALLS_TYPE_PROVIDER, 0,
|
|
|
|
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE,
|
|
|
|
calls_dummy_provider_message_source_interface_init))
|
2018-11-23 14:34:41 +00:00
|
|
|
|
|
|
|
#endif /* FOR_TESTING */
|
2018-06-11 11:42:16 +00:00
|
|
|
|
|
|
|
|
2019-06-25 10:14:16 +00:00
|
|
|
static gboolean
|
|
|
|
usr1_handler (CallsDummyProvider *self)
|
|
|
|
{
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *model;
|
2022-04-24 10:24:55 +00:00
|
|
|
|
|
|
|
g_autoptr (CallsDummyOrigin) origin = NULL;
|
2019-06-25 10:14:16 +00:00
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
model = G_LIST_MODEL (self->origins);
|
|
|
|
g_return_val_if_fail (g_list_model_get_n_items (model) > 0, FALSE);
|
2019-06-25 10:14:16 +00:00
|
|
|
|
|
|
|
g_debug ("Received SIGUSR1, adding new incoming call");
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
origin = g_list_model_get_item (model, 0);
|
2019-06-25 10:14:16 +00:00
|
|
|
calls_dummy_origin_create_inbound (origin, "0987654321");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-02-17 09:53:14 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
usr2_handler (CallsDummyProvider *self)
|
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
g_autoptr (CallsDummyOrigin) origin = NULL;
|
|
|
|
|
2022-02-17 09:53:14 +00:00
|
|
|
GListModel *model;
|
|
|
|
|
|
|
|
model = G_LIST_MODEL (self->origins);
|
|
|
|
g_return_val_if_fail (g_list_model_get_n_items (model) > 0, FALSE);
|
|
|
|
|
|
|
|
g_debug ("Received SIGUSR2, adding new anonymous incoming call");
|
|
|
|
|
|
|
|
origin = g_list_model_get_item (model, 0);
|
|
|
|
calls_dummy_origin_create_inbound (origin, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
static GListModel *
|
2021-01-25 15:32:14 +00:00
|
|
|
calls_dummy_provider_get_origins (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (provider);
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
return G_LIST_MODEL (self->origins);
|
2021-01-25 15:32:14 +00:00
|
|
|
}
|
2019-06-25 10:14:16 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
static const char *const *
|
2021-04-19 17:07:00 +00:00
|
|
|
calls_dummy_provider_get_protocols (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
return supported_protocols;
|
|
|
|
}
|
|
|
|
|
2022-01-26 13:46:01 +00:00
|
|
|
static gboolean
|
|
|
|
calls_dummy_provider_is_modem (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2018-11-23 14:34:41 +00:00
|
|
|
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (object);
|
|
|
|
|
|
|
|
calls_dummy_provider_add_origin (self, "Dummy origin");
|
|
|
|
|
2019-06-25 10:14:16 +00:00
|
|
|
g_unix_signal_add (SIGUSR1,
|
2022-04-24 10:24:55 +00:00
|
|
|
(GSourceFunc) usr1_handler,
|
2019-06-25 10:14:16 +00:00
|
|
|
self);
|
2022-02-17 09:53:14 +00:00
|
|
|
g_unix_signal_add (SIGUSR2,
|
|
|
|
(GSourceFunc) usr2_handler,
|
|
|
|
self);
|
2019-06-25 10:14:16 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_dummy_provider_parent_class)->constructed (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsDummyProvider *self = CALLS_DUMMY_PROVIDER (object);
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
g_list_store_remove_all (self->origins);
|
|
|
|
g_clear_object (&self->origins);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_dummy_provider_parent_class)->dispose (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-06-11 11:42:16 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_dummy_provider_class_init (CallsDummyProviderClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2021-01-25 15:32:14 +00:00
|
|
|
CallsProviderClass *provider_class = CALLS_PROVIDER_CLASS (klass);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
object_class->constructed = constructed;
|
|
|
|
object_class->dispose = dispose;
|
2018-10-19 10:19:41 +00:00
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
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;
|
2021-04-19 17:07:00 +00:00
|
|
|
provider_class->get_protocols = calls_dummy_provider_get_protocols;
|
2022-01-26 13:46:01 +00:00
|
|
|
provider_class->is_modem = calls_dummy_provider_is_modem;
|
2018-06-11 11:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2021-01-25 15:32:14 +00:00
|
|
|
calls_dummy_provider_message_source_interface_init (CallsMessageSourceInterface *iface)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-11 11:42:16 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_dummy_provider_init (CallsDummyProvider *self)
|
2018-06-11 11:42:16 +00:00
|
|
|
{
|
2021-05-13 16:19:21 +00:00
|
|
|
self->origins = g_list_store_new (CALLS_TYPE_ORIGIN);
|
2018-06-11 11:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
calls_dummy_provider_add_origin (CallsDummyProvider *self,
|
|
|
|
const gchar *name)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2021-03-23 08:48:21 +00:00
|
|
|
g_autoptr (CallsDummyOrigin) origin = NULL;
|
|
|
|
|
|
|
|
origin = calls_dummy_origin_new (name);
|
2021-02-15 05:34:34 +00:00
|
|
|
g_list_store_append (self->origins, origin);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
2018-11-23 14:34:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
CallsDummyProvider *
|
2021-06-02 18:18:50 +00:00
|
|
|
calls_dummy_provider_new (void)
|
2018-11-23 14:34:41 +00:00
|
|
|
{
|
|
|
|
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 */
|