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 "CallsOfonoProvider"
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
#include "calls-ofono-provider.h"
|
|
|
|
#include "calls-provider.h"
|
|
|
|
#include "calls-ofono-origin.h"
|
|
|
|
#include "calls-message-source.h"
|
2023-01-21 15:42:39 +00:00
|
|
|
#include "calls-util.h"
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
#include <libgdbofono/gdbo-manager.h>
|
|
|
|
#include <libgdbofono/gdbo-modem.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
2018-11-23 14:34:41 +00:00
|
|
|
#include <libpeas/peas.h>
|
|
|
|
|
2021-04-19 17:07:00 +00:00
|
|
|
static const char * const supported_protocols[] = {
|
|
|
|
"tel",
|
|
|
|
NULL
|
|
|
|
};
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct _CallsOfonoProvider {
|
|
|
|
CallsProvider parent_instance;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-04-11 02:41:21 +00:00
|
|
|
/* The status property */
|
2022-04-24 10:24:55 +00:00
|
|
|
gchar *status;
|
2021-03-29 09:48:44 +00:00
|
|
|
/** ID for the D-Bus watch */
|
2022-04-24 10:24:55 +00:00
|
|
|
guint watch_id;
|
2018-05-17 13:16:51 +00:00
|
|
|
/** D-Bus connection */
|
|
|
|
GDBusConnection *connection;
|
|
|
|
/** D-Bus proxy for the oFono Manager object */
|
2022-04-24 10:24:55 +00:00
|
|
|
GDBOManager *manager;
|
2018-05-17 13:16:51 +00:00
|
|
|
/** Map of D-Bus object paths to a struct CallsModemData */
|
2022-04-24 10:24:55 +00:00
|
|
|
GHashTable *modems;
|
2021-02-15 05:34:34 +00:00
|
|
|
/* A list of CallsOrigins */
|
2022-04-24 10:24:55 +00:00
|
|
|
GListStore *origins;
|
2018-05-17 13:16:51 +00:00
|
|
|
};
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
static void calls_ofono_provider_message_source_interface_init (CallsMessageSourceInterface *iface);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
G_DEFINE_DYNAMIC_TYPE_EXTENDED
|
2022-04-24 10:24:55 +00:00
|
|
|
(CallsOfonoProvider, calls_ofono_provider, CALLS_TYPE_PROVIDER, 0,
|
|
|
|
G_IMPLEMENT_INTERFACE_DYNAMIC (CALLS_TYPE_MESSAGE_SOURCE,
|
|
|
|
calls_ofono_provider_message_source_interface_init))
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-04-11 02:41:21 +00:00
|
|
|
static void
|
|
|
|
set_status (CallsOfonoProvider *self,
|
|
|
|
const gchar *new_status)
|
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
if (strcmp (self->status, new_status) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-11 02:41:21 +00:00
|
|
|
|
|
|
|
g_free (self->status);
|
|
|
|
self->status = g_strdup (new_status);
|
|
|
|
g_object_notify (G_OBJECT (self), "status");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_status (CallsOfonoProvider *self)
|
|
|
|
{
|
|
|
|
const gchar *s;
|
|
|
|
GListModel *model;
|
|
|
|
|
|
|
|
model = G_LIST_MODEL (self->origins);
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
if (!self->connection) {
|
|
|
|
s = _("DBus unavailable");
|
|
|
|
} else if (g_list_model_get_n_items (model) == 0) {
|
|
|
|
s = _("No voice-capable modem available");
|
|
|
|
} else {
|
|
|
|
s = _("Normal");
|
|
|
|
}
|
2021-04-11 02:41:21 +00:00
|
|
|
|
|
|
|
set_status (self, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-02 17:42:25 +00:00
|
|
|
static gboolean
|
2021-02-15 05:34:34 +00:00
|
|
|
ofono_find_origin_index (CallsOfonoProvider *self,
|
|
|
|
const char *path,
|
|
|
|
guint *index)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *model;
|
|
|
|
guint n_items;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
g_assert (CALLS_IS_OFONO_PROVIDER (self));
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
model = G_LIST_MODEL (self->origins);
|
|
|
|
n_items = g_list_model_get_n_items (model);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
for (guint i = 0; i < n_items; i++) {
|
|
|
|
g_autoptr (CallsOfonoOrigin) origin = NULL;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
origin = g_list_model_get_item (model, i);
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
if (calls_ofono_origin_matches (origin, path)) {
|
|
|
|
if (index)
|
|
|
|
*index = i;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
update_status (self);
|
2021-04-11 02:41:21 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
return TRUE;
|
2021-02-15 05:34:34 +00:00
|
|
|
}
|
2022-04-24 10:24:55 +00:00
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
return FALSE;
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
object_array_includes (GVariantIter *iter,
|
|
|
|
const gchar *needle)
|
|
|
|
{
|
|
|
|
const gchar *str;
|
|
|
|
gboolean found = FALSE;
|
2022-04-24 10:24:55 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
while (g_variant_iter_loop (iter, "&s", &str))
|
2022-04-24 10:24:55 +00:00
|
|
|
{
|
|
|
|
if (g_strcmp0 (str, needle) == 0) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
2022-04-24 10:24:55 +00:00
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
g_variant_iter_free (iter);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
modem_check_ifaces (CallsOfonoProvider *self,
|
2022-04-24 10:24:55 +00:00
|
|
|
GDBOModem *modem,
|
|
|
|
const gchar *modem_name,
|
|
|
|
GVariant *ifaces)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
gboolean voice;
|
|
|
|
GVariantIter *iter = NULL;
|
|
|
|
const gchar *path;
|
2021-02-15 05:34:34 +00:00
|
|
|
guint index;
|
|
|
|
gboolean has_origin;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_variant_get (ifaces, "as", &iter);
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
voice = object_array_includes (iter, "org.ofono.VoiceCallManager");
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (modem));
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
has_origin = ofono_find_origin_index (self, path, &index);
|
2022-04-24 10:24:55 +00:00
|
|
|
if (voice && !has_origin) {
|
|
|
|
g_autoptr (CallsOfonoOrigin) origin = NULL;
|
2021-02-15 05:34:34 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
g_debug ("Adding oFono Origin with path `%s'", path);
|
2021-02-15 05:34:34 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
origin = calls_ofono_origin_new (modem);
|
|
|
|
g_list_store_append (self->origins, origin);
|
|
|
|
} else if (!voice && has_origin) {
|
|
|
|
g_list_store_remove (self->origins, index);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2022-04-24 10:24:55 +00:00
|
|
|
modem_property_changed_cb (GDBOModem *modem,
|
|
|
|
const gchar *name,
|
|
|
|
GVariant *value,
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsOfonoProvider *self)
|
|
|
|
{
|
|
|
|
gchar *modem_name;
|
|
|
|
|
|
|
|
g_debug ("Modem property `%s' changed", name);
|
|
|
|
|
|
|
|
if (g_strcmp0 (name, "Interfaces") != 0)
|
2022-04-24 10:24:55 +00:00
|
|
|
return;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
modem_name = g_object_get_data (G_OBJECT (modem),
|
|
|
|
"calls-modem-name");
|
|
|
|
|
2021-04-11 02:43:58 +00:00
|
|
|
/* PropertyChanged gives us a variant gvariant containing a string array,
|
2022-04-24 10:24:55 +00:00
|
|
|
but modem_check_ifaces expects the inner string array gvariant */
|
|
|
|
value = g_variant_get_variant (value);
|
2018-05-17 13:16:51 +00:00
|
|
|
modem_check_ifaces (self, modem, modem_name, value);
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
struct CallsModemProxyNewData {
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsOfonoProvider *self;
|
|
|
|
gchar *name;
|
|
|
|
GVariant *ifaces;
|
|
|
|
};
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2022-04-24 10:24:55 +00:00
|
|
|
modem_proxy_new_cb (GDBusConnection *connection,
|
|
|
|
GAsyncResult *res,
|
2018-05-17 13:16:51 +00:00
|
|
|
struct CallsModemProxyNewData *data)
|
|
|
|
{
|
|
|
|
GDBOModem *modem;
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
modem = gdbo_modem_proxy_new_finish (res, &error);
|
2022-04-24 10:24:55 +00:00
|
|
|
if (!modem) {
|
|
|
|
g_variant_unref (data->ifaces);
|
|
|
|
g_free (data->name);
|
|
|
|
g_free (data);
|
2022-09-02 11:11:19 +00:00
|
|
|
g_warning ("Error creating oFono Modem proxy: %s",
|
|
|
|
error->message);
|
2022-04-24 10:24:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_signal_connect (modem, "property-changed",
|
|
|
|
G_CALLBACK (modem_property_changed_cb),
|
|
|
|
data->self);
|
|
|
|
|
|
|
|
|
|
|
|
/* We want to store the oFono modem's Name property so we can pass it
|
|
|
|
to our Origin when we create it */
|
|
|
|
g_object_set_data_full (G_OBJECT (modem), "calls-modem-name",
|
|
|
|
data->name, g_free);
|
|
|
|
|
|
|
|
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (modem));
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
g_hash_table_insert (data->self->modems, g_strdup (path), modem);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
if (data->ifaces) {
|
|
|
|
modem_check_ifaces (data->self, modem,
|
|
|
|
data->name, data->ifaces);
|
|
|
|
g_variant_unref (data->ifaces);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
g_debug ("Modem `%s' added", path);
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static gchar *
|
|
|
|
modem_properties_get_name (GVariant *properties)
|
|
|
|
{
|
|
|
|
gchar *name = NULL;
|
|
|
|
gboolean ok;
|
|
|
|
|
|
|
|
#define try(prop) \
|
|
|
|
ok = g_variant_lookup (properties, prop, "s", &name); \
|
|
|
|
if (ok) { \
|
|
|
|
return name; \
|
|
|
|
}
|
|
|
|
|
|
|
|
try ("Name");
|
|
|
|
try ("Model");
|
|
|
|
try ("Manufacturer");
|
|
|
|
try ("Serial");
|
|
|
|
try ("SystemPath");
|
|
|
|
|
|
|
|
#undef try
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
static const char *const *
|
2021-04-19 17:07:00 +00:00
|
|
|
calls_ofono_provider_get_protocols (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
return supported_protocols;
|
|
|
|
}
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-05-04 19:49:07 +00:00
|
|
|
static gboolean
|
|
|
|
calls_ofono_provider_is_modem (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
modem_added_cb (GDBOManager *manager,
|
|
|
|
const gchar *path,
|
|
|
|
GVariant *properties,
|
|
|
|
CallsOfonoProvider *self)
|
|
|
|
{
|
|
|
|
struct CallsModemProxyNewData *data;
|
|
|
|
|
|
|
|
g_debug ("Adding modem `%s'", path);
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
if (g_hash_table_lookup (self->modems, path)) {
|
|
|
|
g_warning ("Modem `%s' already exists", path);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
data = g_new0 (struct CallsModemProxyNewData, 1);
|
|
|
|
data->self = self;
|
|
|
|
data->name = modem_properties_get_name (properties);
|
|
|
|
|
|
|
|
data->ifaces = g_variant_lookup_value
|
2022-04-24 10:24:55 +00:00
|
|
|
(properties, "Interfaces", G_VARIANT_TYPE_ARRAY);
|
|
|
|
if (data->ifaces) {
|
|
|
|
g_variant_ref (data->ifaces);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
gdbo_modem_proxy_new
|
|
|
|
(self->connection,
|
2022-04-24 10:24:55 +00:00
|
|
|
G_DBUS_PROXY_FLAGS_NONE,
|
|
|
|
g_dbus_proxy_get_name (G_DBUS_PROXY (manager)),
|
|
|
|
path,
|
|
|
|
NULL,
|
|
|
|
(GAsyncReadyCallback) modem_proxy_new_cb,
|
|
|
|
data);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_debug ("Modem `%s' addition in progress", path);
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
modem_removed_cb (GDBOManager *manager,
|
|
|
|
const gchar *path,
|
|
|
|
CallsOfonoProvider *self)
|
|
|
|
{
|
2021-02-15 05:34:34 +00:00
|
|
|
guint index;
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_debug ("Removing modem `%s'", path);
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
if (ofono_find_origin_index (self, path, &index))
|
|
|
|
g_list_store_remove (self->origins, index);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_hash_table_remove (self->modems, path);
|
|
|
|
|
|
|
|
g_debug ("Modem `%s' removed", path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2022-04-24 10:24:55 +00:00
|
|
|
get_modems_cb (GDBOManager *manager,
|
|
|
|
GAsyncResult *res,
|
2018-05-17 13:16:51 +00:00
|
|
|
CallsOfonoProvider *self)
|
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
gboolean ok;
|
|
|
|
GVariant *modems;
|
|
|
|
GVariantIter *modems_iter = NULL;
|
|
|
|
const gchar *path;
|
|
|
|
GVariant *properties;
|
|
|
|
|
|
|
|
ok = gdbo_manager_call_get_modems_finish (manager, &modems,
|
|
|
|
res, &error);
|
2022-04-24 10:24:55 +00:00
|
|
|
if (!ok) {
|
|
|
|
g_warning ("Error getting modems from oFono Manager: %s",
|
|
|
|
error->message);
|
|
|
|
CALLS_ERROR (self, error);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
char *text = g_variant_print (modems, TRUE);
|
|
|
|
g_debug ("Received modems from oFono Manager: %s", text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_get (modems, "a(oa{sv})", &modems_iter);
|
|
|
|
while (g_variant_iter_loop (modems_iter, "(&o@a{sv})",
|
|
|
|
&path, &properties))
|
2022-04-24 10:24:55 +00:00
|
|
|
{
|
|
|
|
g_debug ("Got modem object path `%s'", path);
|
|
|
|
modem_added_cb (manager, path, properties, self);
|
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
g_variant_iter_free (modems_iter);
|
|
|
|
|
|
|
|
g_variant_unref (modems);
|
|
|
|
}
|
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
static const char *
|
|
|
|
calls_ofono_provider_get_name (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
return "Ofono";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
calls_ofono_provider_get_status (CallsProvider *provider)
|
|
|
|
{
|
2021-04-11 02:41:21 +00:00
|
|
|
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (provider);
|
|
|
|
|
|
|
|
return self->status;
|
2021-01-25 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
static GListModel *
|
2021-01-25 15:32:14 +00:00
|
|
|
calls_ofono_provider_get_origins (CallsProvider *provider)
|
|
|
|
{
|
|
|
|
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (provider);
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
return G_LIST_MODEL (self->origins);
|
2021-01-25 15:32:14 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2022-04-24 10:24:55 +00:00
|
|
|
ofono_appeared_cb (GDBusConnection *connection,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *name_owner,
|
2021-03-29 09:48:44 +00:00
|
|
|
CallsOfonoProvider *self)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
2021-03-29 09:48:44 +00:00
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
self->connection = connection;
|
2022-04-24 10:24:55 +00:00
|
|
|
if (!self->connection) {
|
2022-09-02 11:11:19 +00:00
|
|
|
g_warning ("Error creating D-Bus connection: %s",
|
|
|
|
error->message);
|
|
|
|
return;
|
2022-04-24 10:24:55 +00:00
|
|
|
}
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2022-09-02 11:10:33 +00:00
|
|
|
/* TODO this should be async */
|
2018-05-17 13:16:51 +00:00
|
|
|
self->manager = gdbo_manager_proxy_new_sync
|
2022-04-24 10:24:55 +00:00
|
|
|
(self->connection,
|
|
|
|
G_DBUS_PROXY_FLAGS_NONE,
|
|
|
|
"org.ofono",
|
|
|
|
"/",
|
|
|
|
NULL,
|
|
|
|
&error);
|
|
|
|
if (!self->manager) {
|
2022-09-02 11:11:19 +00:00
|
|
|
g_warning ("Error creating ModemManager object manager proxy: %s",
|
|
|
|
error->message);
|
|
|
|
return;
|
2022-04-24 10:24:55 +00:00
|
|
|
}
|
2018-05-17 13:16:51 +00:00
|
|
|
|
|
|
|
g_signal_connect (self->manager, "modem-added",
|
|
|
|
G_CALLBACK (modem_added_cb), self);
|
|
|
|
g_signal_connect (self->manager, "modem-removed",
|
|
|
|
G_CALLBACK (modem_removed_cb), self);
|
|
|
|
|
|
|
|
gdbo_manager_call_get_modems
|
|
|
|
(self->manager,
|
2022-04-24 10:24:55 +00:00
|
|
|
NULL,
|
|
|
|
(GAsyncReadyCallback) get_modems_cb,
|
|
|
|
self);
|
2021-03-29 09:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-02 17:42:25 +00:00
|
|
|
static void
|
2022-04-24 10:24:55 +00:00
|
|
|
ofono_vanished_cb (GDBusConnection *connection,
|
|
|
|
const gchar *name,
|
2021-03-29 09:48:44 +00:00
|
|
|
CallsOfonoProvider *self)
|
|
|
|
{
|
|
|
|
g_debug ("Ofono vanished from D-Bus");
|
|
|
|
g_list_store_remove_all (self->origins);
|
2021-04-11 02:41:21 +00:00
|
|
|
update_status (self);
|
2021-03-29 09:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (object);
|
|
|
|
|
|
|
|
self->watch_id =
|
|
|
|
g_bus_watch_name (G_BUS_TYPE_SYSTEM,
|
|
|
|
"org.ofono",
|
|
|
|
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
|
|
|
(GBusNameAppearedCallback) ofono_appeared_cb,
|
|
|
|
(GBusNameVanishedCallback) ofono_vanished_cb,
|
|
|
|
self, NULL);
|
|
|
|
|
|
|
|
g_debug ("Watching for Ofono");
|
|
|
|
|
2021-02-24 08:26:44 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_ofono_provider_parent_class)->constructed (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (object);
|
|
|
|
|
2018-08-03 09:08:55 +00:00
|
|
|
g_clear_object (&self->manager);
|
|
|
|
g_clear_object (&self->connection);
|
2018-05-17 13:16:51 +00:00
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_ofono_provider_parent_class)->dispose (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CallsOfonoProvider *self = CALLS_OFONO_PROVIDER (object);
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
g_object_unref (self->origins);
|
2021-04-11 02:41:21 +00:00
|
|
|
g_free (self->status);
|
2018-05-17 13:16:51 +00:00
|
|
|
g_hash_table_unref (self->modems);
|
|
|
|
|
2020-02-18 15:01:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_ofono_provider_parent_class)->finalize (object);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_ofono_provider_class_init (CallsOfonoProviderClass *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
|
|
|
|
|
|
|
object_class->constructed = constructed;
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
object_class->finalize = finalize;
|
|
|
|
|
2021-01-25 15:32:14 +00:00
|
|
|
provider_class->get_name = calls_ofono_provider_get_name;
|
|
|
|
provider_class->get_status = calls_ofono_provider_get_status;
|
|
|
|
provider_class->get_origins = calls_ofono_provider_get_origins;
|
2021-04-19 17:07:00 +00:00
|
|
|
provider_class->get_protocols = calls_ofono_provider_get_protocols;
|
2021-05-04 19:49:07 +00:00
|
|
|
provider_class->is_modem = calls_ofono_provider_is_modem;
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2021-01-25 15:32:14 +00:00
|
|
|
calls_ofono_provider_class_finalize (CallsOfonoProviderClass *klass)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
2021-01-25 15:32:14 +00:00
|
|
|
calls_ofono_provider_message_source_interface_init (CallsMessageSourceInterface *iface)
|
2018-05-17 13:16:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-05-17 13:16:51 +00:00
|
|
|
static void
|
|
|
|
calls_ofono_provider_init (CallsOfonoProvider *self)
|
|
|
|
{
|
2022-03-19 22:15:12 +00:00
|
|
|
self->status = g_strdup (_("Initialized"));
|
2018-05-17 13:16:51 +00:00
|
|
|
self->modems = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, g_object_unref);
|
2021-05-13 16:19:21 +00:00
|
|
|
self->origins = g_list_store_new (CALLS_TYPE_ORIGIN);
|
2018-05-17 13:16:51 +00:00
|
|
|
}
|
2018-11-23 14:34:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
G_MODULE_EXPORT void
|
|
|
|
peas_register_types (PeasObjectModule *module)
|
|
|
|
{
|
|
|
|
calls_ofono_provider_register_type (G_TYPE_MODULE (module));
|
|
|
|
|
|
|
|
peas_object_module_register_extension_type (module,
|
|
|
|
CALLS_TYPE_PROVIDER,
|
|
|
|
CALLS_TYPE_OFONO_PROVIDER);
|
|
|
|
}
|