mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-30 07:42:23 +02:00
src: watch ofono service for new modem
If system is using ofono, use ofono dbus service to figure out the modem's USB id.
This commit is contained in:
@@ -8,22 +8,111 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <libgdbofono/gdbo-manager.h>
|
||||
#include <libgdbofono/gdbo-modem.h>
|
||||
|
||||
#define OFONO_SERVICE "org.ofono"
|
||||
|
||||
static void modem_added_cb(GDBOManager *manager_proxy,
|
||||
const gchar *path,
|
||||
GVariant *properties,
|
||||
struct EG25Manager *manager)
|
||||
{
|
||||
GVariant *modem_path;
|
||||
g_debug("Adding ofono modem '%s'", path);
|
||||
|
||||
if (manager->modem_state == EG25_STATE_RESUMING) {
|
||||
if (manager->modem_recovery_timer) {
|
||||
g_source_remove(manager->modem_recovery_timer);
|
||||
manager->modem_recovery_timer = 0;
|
||||
}
|
||||
modem_resume_post(manager);
|
||||
manager->modem_state = EG25_STATE_CONFIGURED;
|
||||
}
|
||||
|
||||
if (manager->modem_state < EG25_STATE_ACQUIRED)
|
||||
manager->modem_state = EG25_STATE_ACQUIRED;
|
||||
|
||||
if (manager->modem_state < EG25_STATE_CONFIGURED)
|
||||
modem_configure(manager);
|
||||
|
||||
modem_path = g_variant_lookup_value(properties, "SystemPath", G_VARIANT_TYPE_STRING);
|
||||
if (manager->modem_usb_id)
|
||||
g_free(manager->modem_usb_id);
|
||||
manager->modem_usb_id = g_strdup(strrchr(g_variant_dup_string(modem_path, NULL), '/') + 1);
|
||||
}
|
||||
|
||||
static void modem_removed_cb(GDBOManager *manager_proxy,
|
||||
const gchar *path,
|
||||
struct EG25Manager *manager)
|
||||
{
|
||||
}
|
||||
|
||||
static void get_modems_cb(GDBOManager *manager_proxy,
|
||||
GAsyncResult *res,
|
||||
struct EG25Manager *manager)
|
||||
{
|
||||
gboolean ok;
|
||||
GVariant *modems;
|
||||
GVariantIter *modems_iter = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
const gchar *path;
|
||||
GVariant *properties;
|
||||
|
||||
ok = gdbo_manager_call_get_modems_finish(manager_proxy, &modems,
|
||||
res, &error);
|
||||
if (!ok) {
|
||||
g_warning("Error getting modems from ofono manager: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
g_variant_get(modems, "a(oa{sv})", &modems_iter);
|
||||
while(g_variant_iter_loop(modems_iter, "(&o@a{sv})", &path, &properties)) {
|
||||
g_debug("Got modem object path '%s'", path);
|
||||
modem_added_cb(manager_proxy, path, properties, manager);
|
||||
}
|
||||
g_variant_iter_free(modems_iter);
|
||||
g_variant_unref(modems);
|
||||
}
|
||||
|
||||
static void ofono_appeared_cb(GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
const gchar *name_owner,
|
||||
struct EG25Manager *manager)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_message("oFono appeared on D-Bus");
|
||||
|
||||
if (manager->modem_iface != MODEM_IFACE_NONE) {
|
||||
g_critical("Modem interface already found! Make sure to only run either of ModemManager or oFono.");
|
||||
return;
|
||||
}
|
||||
/* now connect to oFono! */
|
||||
manager->ofono_connection = connection;
|
||||
manager->ofono_manager = gdbo_manager_proxy_new_sync(connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
OFONO_SERVICE,
|
||||
"/",
|
||||
NULL,
|
||||
&error);
|
||||
if (!manager->ofono_manager) {
|
||||
g_critical("Error creating ofono object manager proxy: %s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
manager->modem_iface = MODEM_IFACE_OFONO;
|
||||
|
||||
/* now connect to oFono! */
|
||||
g_signal_connect(manager->ofono_manager, "modem-added",
|
||||
G_CALLBACK(modem_added_cb), manager);
|
||||
g_signal_connect(manager->ofono_manager, "modem-removed",
|
||||
G_CALLBACK(modem_removed_cb), manager);
|
||||
|
||||
gdbo_manager_call_get_modems(manager->ofono_manager,
|
||||
NULL,
|
||||
(GAsyncReadyCallback) get_modems_cb,
|
||||
manager);
|
||||
}
|
||||
|
||||
static void ofono_vanished_cb(GDBusConnection *connection,
|
||||
|
Reference in New Issue
Block a user