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;
|
|
|
|
};
|
|
|
|
|
2021-04-05 04:00:10 +00:00
|
|
|
static void calls_dummy_call_message_source_interface_init (CallsMessageSourceInterface *iface);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-04-05 04:00:10 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (CallsDummyCall, calls_dummy_call, CALLS_TYPE_CALL,
|
2018-06-11 11:42:16 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_dummy_call_message_source_interface_init))
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-04-26 10:00:02 +00:00
|
|
|
static const char*
|
|
|
|
calls_dummy_call_get_protocol (CallsCall *call)
|
|
|
|
{
|
|
|
|
return "tel";
|
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_dummy_call_answer (CallsCall *call)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (CALLS_IS_DUMMY_CALL (call));
|
2021-12-10 08:02:39 +00:00
|
|
|
g_return_if_fail (calls_call_get_state (call) == CALLS_CALL_STATE_INCOMING);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-12-10 08:02:39 +00:00
|
|
|
calls_call_set_state (call, CALLS_CALL_STATE_ACTIVE);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_dummy_call_hang_up (CallsCall *call)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (CALLS_IS_DUMMY_CALL (call));
|
|
|
|
|
2021-12-10 08:02:39 +00:00
|
|
|
calls_call_set_state (call, CALLS_CALL_STATE_DISCONNECTED);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 13:06:34 +00:00
|
|
|
static void
|
|
|
|
calls_dummy_call_send_dtmf_tone (CallsCall *call,
|
|
|
|
char key)
|
|
|
|
{
|
|
|
|
g_debug ("Beep! (%c)", key);
|
|
|
|
}
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
static gboolean
|
|
|
|
outbound_timeout_cb (CallsDummyCall *self)
|
|
|
|
{
|
2021-12-10 08:02:39 +00:00
|
|
|
CallsCall *call;
|
|
|
|
|
|
|
|
g_assert (CALLS_IS_DUMMY_CALL (self));
|
|
|
|
|
|
|
|
call = CALLS_CALL (self);
|
|
|
|
|
|
|
|
switch (calls_call_get_state (call)) {
|
2021-12-10 07:32:46 +00:00
|
|
|
case CALLS_CALL_STATE_DIALING:
|
2021-12-10 08:02:39 +00:00
|
|
|
calls_call_set_state (call, CALLS_CALL_STATE_ALERTING);
|
2021-12-10 07:32:46 +00:00
|
|
|
g_timeout_add_seconds
|
|
|
|
(3, (GSourceFunc)outbound_timeout_cb, self);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CALLS_CALL_STATE_ALERTING:
|
2021-12-10 08:02:39 +00:00
|
|
|
calls_call_set_state (call, CALLS_CALL_STATE_ACTIVE);
|
2021-12-10 07:32:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
2019-06-28 08:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsDummyCall *
|
2021-10-22 05:21:11 +00:00
|
|
|
calls_dummy_call_new (const gchar *id,
|
2019-06-28 08:59:41 +00:00
|
|
|
gboolean inbound)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
return g_object_new (CALLS_TYPE_DUMMY_CALL,
|
2021-12-10 08:46:32 +00:00
|
|
|
"id", id,
|
2021-12-10 07:00:11 +00:00
|
|
|
"inbound", inbound,
|
2022-02-12 13:37:28 +00:00
|
|
|
"call-type", CALLS_CALL_TYPE_CELLULAR,
|
2018-05-17 13:16:51 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
CallsDummyCall *self = CALLS_DUMMY_CALL (object);
|
|
|
|
|
2021-12-10 08:02:39 +00:00
|
|
|
if (!calls_call_get_inbound (CALLS_CALL (object)))
|
2021-12-10 07:00:11 +00:00
|
|
|
g_timeout_add_seconds (1, (GSourceFunc)outbound_timeout_cb, self);
|
2019-06-28 08:59:41 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
calls_dummy_call_class_init (CallsDummyCallClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2021-04-05 04:00:10 +00:00
|
|
|
CallsCallClass *call_class = CALLS_CALL_CLASS (klass);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2019-06-28 08:59:41 +00:00
|
|
|
object_class->constructed = constructed;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-04-26 10:00:02 +00:00
|
|
|
call_class->get_protocol = calls_dummy_call_get_protocol;
|
2021-04-05 04:00:10 +00:00
|
|
|
call_class->answer = calls_dummy_call_answer;
|
|
|
|
call_class->hang_up = calls_dummy_call_hang_up;
|
2021-11-16 13:06:34 +00:00
|
|
|
call_class->send_dtmf_tone = calls_dummy_call_send_dtmf_tone;
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_dummy_call_message_source_interface_init (CallsMessageSourceInterface *iface)
|
2018-06-11 11:42:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_dummy_call_init (CallsDummyCall *self)
|
|
|
|
{
|
|
|
|
}
|