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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "calls-dummy-call.h"
|
2018-06-11 11:42:16 +00:00
|
|
|
#include "calls-message-source.h"
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "calls-call.h"
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct _CallsDummyCall
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
gchar *number;
|
2019-06-28 08:59:41 +00:00
|
|
|
gboolean inbound;
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsCallState state;
|
|
|
|
};
|
|
|
|
|
2018-06-11 11:42:16 +00:00
|
|
|
static void calls_dummy_call_message_source_interface_init (CallsCallInterface *iface);
|
2018-05-17 13:16:51 +00:00
|
|
|
static void calls_dummy_call_call_interface_init (CallsCallInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, G_TYPE_OBJECT,
|
2018-06-11 11:42:16 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
|
|
|
|
calls_dummy_call_message_source_interface_init)
|
2018-05-17 13:16:51 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (CALLS_TYPE_CALL,
|
|
|
|
calls_dummy_call_call_interface_init))
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2020-02-22 23:55:45 +00:00
|
|
|
PROP_NUMBER_CONSTRUCTOR,
|
2019-06-28 08:59:41 +00:00
|
|
|
PROP_INBOUND_CONSTRUCTOR,
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-22 23:55:45 +00:00
|
|
|
PROP_CALL_NUMBER,
|
|
|
|
PROP_CALL_INBOUND,
|
|
|
|
PROP_CALL_STATE,
|
|
|
|
PROP_CALL_NAME,
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-22 23:55:45 +00:00
|
|
|
PROP_LAST_PROP
|
|
|
|
};
|
2020-03-17 21:54:25 +00:00
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
change_state (CallsCall *call,
|
|
|
|
CallsDummyCall *self,
|
|
|
|
CallsCallState state)
|
|
|
|
{
|
2018-11-09 12:38:04 +00:00
|
|
|
CallsCallState old_state = self->state;
|
|
|
|
|
|
|
|
if (old_state == state)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
self->state = state;
|
2020-03-17 21:54:25 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (call), props[PROP_CALL_STATE]);
|
2018-11-09 12:38:04 +00:00
|
|
|
g_signal_emit_by_name (call,
|
|
|
|
"state-changed",
|
|
|
|
state,
|
|
|
|
old_state);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
outbound_timeout_cb (CallsDummyCall *self)
|
|
|
|
{
|
|
|
|
switch (self->state)
|
|
|
|
{
|
|
|
|
case CALLS_CALL_STATE_DIALING:
|
|
|
|
change_state (CALLS_CALL (self), self,
|
|
|
|
CALLS_CALL_STATE_ALERTING);
|
|
|
|
g_timeout_add_seconds
|
|
|
|
(3, (GSourceFunc)outbound_timeout_cb, self);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALLS_CALL_STATE_ALERTING:
|
|
|
|
change_state (CALLS_CALL (self), self,
|
|
|
|
CALLS_CALL_STATE_ACTIVE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsDummyCall *
|
2019-06-28 08:59:41 +00:00
|
|
|
calls_dummy_call_new (const gchar *number,
|
|
|
|
gboolean inbound)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (number != NULL, NULL);
|
|
|
|
|
|
|
|
return g_object_new (CALLS_TYPE_DUMMY_CALL,
|
2020-02-22 23:55:45 +00:00
|
|
|
"number-constructor", number,
|
2019-06-28 08:59:41 +00:00
|
|
|
"inbound-constructor", inbound,
|
2018-05-17 13:16:51 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
2020-02-22 23:55:45 +00:00
|
|
|
case PROP_NUMBER_CONSTRUCTOR:
|
2018-05-17 13:16:51 +00:00
|
|
|
self->number = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
case PROP_INBOUND_CONSTRUCTOR:
|
|
|
|
self->inbound = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
|
|
|
|
|
|
|
if (self->inbound)
|
|
|
|
{
|
|
|
|
self->state = CALLS_CALL_STATE_INCOMING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->state = CALLS_CALL_STATE_DIALING;
|
|
|
|
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
|
|
|
|
}
|
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_dummy_call_parent_class)->constructed (object);
|
2019-06-28 08:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
2020-02-22 23:55:45 +00:00
|
|
|
case PROP_CALL_INBOUND:
|
2019-06-28 08:59:41 +00:00
|
|
|
g_value_set_boolean (value, self->inbound);
|
|
|
|
break;
|
|
|
|
|
2020-02-22 23:55:45 +00:00
|
|
|
case PROP_CALL_NUMBER:
|
|
|
|
g_value_set_string (value, self->number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_CALL_STATE:
|
|
|
|
g_value_set_enum (value, self->state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_CALL_NAME:
|
|
|
|
g_value_set_string (value, NULL);
|
|
|
|
break;
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
|
|
|
|
|
|
|
g_free (self->number);
|
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_dummy_call_parent_class)->finalize (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
object_class->get_property = get_property;
|
2018-05-17 13:16:51 +00:00
|
|
|
object_class->set_property = set_property;
|
2019-06-28 08:59:41 +00:00
|
|
|
object_class->constructed = constructed;
|
|
|
|
object_class->finalize = finalize;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-03-17 21:54:25 +00:00
|
|
|
props[PROP_NUMBER_CONSTRUCTOR] =
|
2020-02-22 23:55:45 +00:00
|
|
|
g_param_spec_string ("number-constructor",
|
2020-05-29 18:50:19 +00:00
|
|
|
"Number (constructor)",
|
|
|
|
"The dialed number (dummy class constructor)",
|
2018-05-17 13:16:51 +00:00
|
|
|
"+441234567890",
|
2020-03-17 21:54:25 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
g_object_class_install_property (object_class, PROP_NUMBER_CONSTRUCTOR, props[PROP_NUMBER_CONSTRUCTOR]);
|
2019-06-28 08:59:41 +00:00
|
|
|
|
2020-03-17 21:54:25 +00:00
|
|
|
props[PROP_INBOUND_CONSTRUCTOR] =
|
2019-06-28 08:59:41 +00:00
|
|
|
g_param_spec_boolean ("inbound-constructor",
|
2020-05-29 18:50:19 +00:00
|
|
|
"Inbound (constructor)",
|
|
|
|
"Whether the calls is inbound (dummy class constructor)",
|
2019-06-28 08:59:41 +00:00
|
|
|
FALSE,
|
2020-03-17 21:54:25 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
g_object_class_install_property (object_class, PROP_INBOUND_CONSTRUCTOR, props[PROP_INBOUND_CONSTRUCTOR]);
|
2020-02-22 23:55:45 +00:00
|
|
|
|
2020-03-17 21:54:25 +00:00
|
|
|
#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_CALL_NUMBER, "number");
|
|
|
|
IMPLEMENTS(PROP_CALL_INBOUND, "inbound");
|
|
|
|
IMPLEMENTS(PROP_CALL_STATE, "state");
|
|
|
|
IMPLEMENTS(PROP_CALL_NAME, "name");
|
|
|
|
|
|
|
|
#undef IMPLEMENTS
|
2020-02-22 23:55:45 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_dummy_call_call_interface_init (CallsCallInterface *iface)
|
|
|
|
{
|
|
|
|
iface->answer = answer;
|
|
|
|
iface->hang_up = hang_up;
|
|
|
|
iface->tone_start = tone_start;
|
|
|
|
iface->tone_stop = tone_stop;
|
|
|
|
}
|
|
|
|
|
2018-06-11 11:42:16 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
calls_dummy_call_message_source_interface_init (CallsCallInterface *iface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_dummy_call_init (CallsDummyCall *self)
|
|
|
|
{
|
|
|
|
}
|