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 "CallsOfonoCall"
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "calls-ofono-call.h"
|
|
|
|
#include "calls-call.h"
|
|
|
|
#include "calls-message-source.h"
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct _CallsOfonoCall {
|
|
|
|
GObject parent_instance;
|
2018-05-17 13:16:51 +00:00
|
|
|
GDBOVoiceCall *voice_call;
|
2022-04-24 10:24:55 +00:00
|
|
|
gchar *disconnect_reason;
|
2018-05-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
2021-04-05 04:00:10 +00:00
|
|
|
static void calls_ofono_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 (CallsOfonoCall, calls_ofono_call, CALLS_TYPE_CALL,
|
2018-05-17 13:16:51 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (CALLS_TYPE_MESSAGE_SOURCE,
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_ofono_call_message_source_interface_init))
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_VOICE_CALL,
|
|
|
|
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
|
|
|
|
2018-05-31 10:43:10 +00:00
|
|
|
enum {
|
|
|
|
SIGNAL_TONE,
|
|
|
|
SIGNAL_LAST_SIGNAL,
|
|
|
|
};
|
2022-04-24 10:24:55 +00:00
|
|
|
static guint signals[SIGNAL_LAST_SIGNAL];
|
2018-05-31 10:43:10 +00:00
|
|
|
|
2021-04-26 10:00:02 +00:00
|
|
|
static const char *
|
|
|
|
calls_ofono_call_get_protocol (CallsCall *call)
|
|
|
|
{
|
|
|
|
return "tel";
|
|
|
|
}
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct CallsCallOperationData {
|
|
|
|
const gchar *desc;
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsOfonoCall *self;
|
2022-04-24 10:24:55 +00:00
|
|
|
gboolean (*finish_func) (GDBOVoiceCall *, GAsyncResult *, GError **);
|
2018-05-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
operation_cb (GDBOVoiceCall *voice_call,
|
|
|
|
GAsyncResult *res,
|
|
|
|
struct CallsCallOperationData *data)
|
|
|
|
{
|
2021-02-24 08:26:47 +00:00
|
|
|
g_autoptr (GError) error = NULL;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
gboolean ok;
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
ok = data->finish_func (voice_call, res, &error);
|
2021-12-10 07:12:07 +00:00
|
|
|
if (!ok) {
|
|
|
|
g_warning ("Error %s oFono voice call to `%s': %s",
|
2021-12-10 08:46:32 +00:00
|
|
|
data->desc,
|
|
|
|
calls_call_get_id (CALLS_CALL (data->self)),
|
|
|
|
error->message);
|
2021-12-10 07:12:07 +00:00
|
|
|
CALLS_ERROR (data->self, error);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-04-11 02:31:40 +00:00
|
|
|
g_object_unref (data->self);
|
2018-05-17 13:16:51 +00:00
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_ofono_call_answer (CallsCall *call)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
|
|
|
struct CallsCallOperationData *data;
|
|
|
|
|
|
|
|
data = g_new0 (struct CallsCallOperationData, 1);
|
|
|
|
data->desc = "answering";
|
2021-04-11 02:31:40 +00:00
|
|
|
data->self = g_object_ref (self);
|
2018-05-17 13:16:51 +00:00
|
|
|
data->finish_func = gdbo_voice_call_call_answer_finish;
|
|
|
|
|
|
|
|
gdbo_voice_call_call_answer
|
|
|
|
(self->voice_call, NULL,
|
2022-04-24 10:24:55 +00:00
|
|
|
(GAsyncReadyCallback) operation_cb,
|
|
|
|
data);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_ofono_call_hang_up (CallsCall *call)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
|
|
|
struct CallsCallOperationData *data;
|
|
|
|
|
|
|
|
data = g_new0 (struct CallsCallOperationData, 1);
|
|
|
|
data->desc = "hanging up";
|
2021-04-11 02:31:40 +00:00
|
|
|
data->self = g_object_ref (self);
|
2018-05-17 13:16:51 +00:00
|
|
|
data->finish_func = gdbo_voice_call_call_hangup_finish;
|
|
|
|
|
|
|
|
gdbo_voice_call_call_hangup
|
|
|
|
(self->voice_call, NULL,
|
2022-04-24 10:24:55 +00:00
|
|
|
(GAsyncReadyCallback) operation_cb,
|
|
|
|
data);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-11-16 12:59:06 +00:00
|
|
|
calls_ofono_call_send_dtmf_tone (CallsCall *call, gchar key)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2018-05-31 10:43:10 +00:00
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (call);
|
2022-04-24 10:24:55 +00:00
|
|
|
|
2021-12-10 08:02:39 +00:00
|
|
|
if (calls_call_get_state (call) != CALLS_CALL_STATE_ACTIVE) {
|
2021-12-10 07:12:07 +00:00
|
|
|
g_warning ("Tone start requested for non-active call to `%s'",
|
2021-12-10 08:46:32 +00:00
|
|
|
calls_call_get_id (call));
|
2021-12-10 07:12:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2018-05-31 10:43:10 +00:00
|
|
|
g_signal_emit_by_name (self, "tone", key);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_VOICE_CALL:
|
2018-08-03 09:23:44 +00:00
|
|
|
g_set_object
|
|
|
|
(&self->voice_call, GDBO_VOICE_CALL (g_value_get_object (value)));
|
2018-05-17 13:16:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
property_changed_cb (CallsOfonoCall *self,
|
|
|
|
const gchar *name,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
|
|
|
GVariant *str_var;
|
|
|
|
gchar *str = NULL;
|
|
|
|
CallsCallState state;
|
|
|
|
gboolean ok;
|
2021-12-10 07:12:07 +00:00
|
|
|
g_autofree char *text = g_variant_print (value, TRUE);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-12-10 07:12:07 +00:00
|
|
|
g_debug ("Property `%s' for oFono call to `%s' changed to: %s",
|
2021-12-10 08:46:32 +00:00
|
|
|
name,
|
|
|
|
calls_call_get_id (CALLS_CALL (self)),
|
|
|
|
text);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
if (g_strcmp0 (name, "State") != 0)
|
2021-12-10 07:12:07 +00:00
|
|
|
return;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_variant_get (value, "v", &str_var);
|
|
|
|
g_variant_get (str_var, "&s", &str);
|
|
|
|
g_return_if_fail (str != NULL);
|
|
|
|
|
|
|
|
ok = calls_call_state_parse_nick (&state, str);
|
|
|
|
if (ok)
|
2021-12-10 08:02:39 +00:00
|
|
|
calls_call_set_state (CALLS_CALL (self), state);
|
2018-05-17 13:16:51 +00:00
|
|
|
else
|
2021-12-10 07:12:07 +00:00
|
|
|
g_warning ("Could not parse new state `%s'"
|
|
|
|
" of oFono call to `%s'",
|
2021-12-10 08:46:32 +00:00
|
|
|
str, calls_call_get_id (CALLS_CALL (self)));
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_variant_unref (str_var);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
disconnect_reason_cb (CallsOfonoCall *self,
|
2022-04-24 10:24:55 +00:00
|
|
|
const gchar *reason)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2021-04-12 09:33:57 +00:00
|
|
|
if (reason) {
|
|
|
|
g_free (self->disconnect_reason);
|
|
|
|
self->disconnect_reason = g_strdup (reason);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
|
|
|
|
|
|
|
|
g_return_if_fail (self->voice_call != NULL);
|
|
|
|
|
2021-01-09 17:15:34 +00:00
|
|
|
g_signal_connect_object (self->voice_call, "property-changed",
|
|
|
|
G_CALLBACK (property_changed_cb),
|
|
|
|
self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (self->voice_call, "disconnect-reason",
|
|
|
|
G_CALLBACK (disconnect_reason_cb),
|
|
|
|
self, G_CONNECT_SWAPPED);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_ofono_call_parent_class)->constructed (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
|
|
|
|
|
2018-08-03 09:08:55 +00:00
|
|
|
g_clear_object (&self->voice_call);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_ofono_call_parent_class)->dispose (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CallsOfonoCall *self = CALLS_OFONO_CALL (object);
|
|
|
|
|
2018-08-03 09:14:46 +00:00
|
|
|
g_free (self->disconnect_reason);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_ofono_call_parent_class)->finalize (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_ofono_call_class_init (CallsOfonoCallClass *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-31 10:43:10 +00:00
|
|
|
GType tone_arg_types = G_TYPE_CHAR;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
object_class->constructed = constructed;
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
object_class->finalize = finalize;
|
|
|
|
|
2021-04-26 10:00:02 +00:00
|
|
|
call_class->get_protocol = calls_ofono_call_get_protocol;
|
2021-04-05 04:00:10 +00:00
|
|
|
call_class->answer = calls_ofono_call_answer;
|
|
|
|
call_class->hang_up = calls_ofono_call_hang_up;
|
2021-11-16 12:59:06 +00:00
|
|
|
call_class->send_dtmf_tone = calls_ofono_call_send_dtmf_tone;
|
2021-04-05 04:00:10 +00:00
|
|
|
|
2020-03-17 21:54:25 +00:00
|
|
|
props[PROP_VOICE_CALL] =
|
2018-05-17 13:16:51 +00:00
|
|
|
g_param_spec_object ("voice-call",
|
2020-05-29 18:50:19 +00:00
|
|
|
"Voice call",
|
|
|
|
"A GDBO proxy object for the underlying call object",
|
2018-05-17 13:16:51 +00:00
|
|
|
GDBO_TYPE_VOICE_CALL,
|
2020-03-17 21:54:25 +00:00
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
|
|
|
g_object_class_install_property (object_class, PROP_VOICE_CALL, props[PROP_VOICE_CALL]);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2018-05-31 10:43:10 +00:00
|
|
|
signals[SIGNAL_TONE] =
|
|
|
|
g_signal_newv ("tone",
|
2022-04-24 10:24:55 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
1, &tone_arg_types);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-04-05 04:00:10 +00:00
|
|
|
calls_ofono_call_message_source_interface_init (CallsMessageSourceInterface *iface)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_ofono_call_init (CallsOfonoCall *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CallsOfonoCall *
|
|
|
|
calls_ofono_call_new (GDBOVoiceCall *voice_call,
|
2021-12-10 07:00:11 +00:00
|
|
|
GVariant *call_props)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2021-12-10 07:00:11 +00:00
|
|
|
const char *state_str = NULL;
|
|
|
|
const char *name = NULL;
|
|
|
|
const char *id = NULL;
|
|
|
|
CallsCallState state = CALLS_CALL_STATE_UNKNOWN;
|
|
|
|
gboolean inbound = FALSE;
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
g_return_val_if_fail (GDBO_IS_VOICE_CALL (voice_call), NULL);
|
2021-12-10 07:00:11 +00:00
|
|
|
g_return_val_if_fail (call_props != NULL, NULL);
|
|
|
|
|
|
|
|
g_variant_lookup (call_props, "LineIdentification", "s", &id);
|
|
|
|
g_variant_lookup (call_props, "Name", "s", &name);
|
|
|
|
|
|
|
|
g_variant_lookup (call_props, "State", "&s", &state_str);
|
|
|
|
if (state_str)
|
|
|
|
calls_call_state_parse_nick (&state, state_str);
|
|
|
|
|
|
|
|
/* `inbound` is derived from `state` at construction time.
|
|
|
|
* If the call was already somehow accepted and thus state=active,
|
|
|
|
* then it's not possible to know the correct value for `inbound`. */
|
|
|
|
if (state == CALLS_CALL_STATE_INCOMING)
|
|
|
|
inbound = TRUE;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
return g_object_new (CALLS_TYPE_OFONO_CALL,
|
|
|
|
"voice-call", voice_call,
|
2021-12-10 08:46:32 +00:00
|
|
|
"id", id,
|
2021-12-11 08:24:57 +00:00
|
|
|
"name", name,
|
2021-12-10 07:00:11 +00:00
|
|
|
"inbound", inbound,
|
2021-12-10 08:02:39 +00:00
|
|
|
"state", state,
|
2022-02-12 13:37:28 +00:00
|
|
|
"call-type", CALLS_CALL_TYPE_CELLULAR,
|
2018-05-17 13:16:51 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
calls_ofono_call_get_object_path (CallsOfonoCall *call)
|
|
|
|
{
|
|
|
|
return g_dbus_proxy_get_object_path (G_DBUS_PROXY (call->voice_call));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
calls_ofono_call_get_disconnect_reason (CallsOfonoCall *call)
|
|
|
|
{
|
|
|
|
return call->disconnect_reason;
|
|
|
|
}
|