MMManager * mmcli_get_manager_sync (GDBusConnection *connection) { MMManager *manager; gchar *name_owner; GError *error = NULL; manager = mm_manager_new_sync (connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, NULL, &error); if (!manager) { g_printerr ("error: couldn't create manager: %s\n", error ? error->message : "unknown error"); exit (EXIT_FAILURE); } name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager)); if (!name_owner) { g_printerr ("error: couldn't find the ModemManager process in the bus\n"); exit (EXIT_FAILURE); } g_debug ("ModemManager process found at '%s'", name_owner); g_free (name_owner); return manager; }
static void dun_start (NmaBtDevice *self) { NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); gboolean have_mm = FALSE, have_mm1 = TRUE; g_message ("%s: starting DUN device discovery...", __func__); _set_status (self, _("Detecting phone configuration...")); /* ModemManager stuff */ priv->mm_proxy = dbus_g_proxy_new_for_name (priv->bus, MM_SERVICE, MM_PATH, MM_INTERFACE); g_assert (priv->mm_proxy); have_mm = _name_has_owner (priv->bus, MM_SERVICE); dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, G_TYPE_BOXED, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->mm_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->mm_proxy, "DeviceAdded", G_CALLBACK (modem_added), self, NULL); dbus_g_proxy_add_signal (priv->mm_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->mm_proxy, "DeviceRemoved", G_CALLBACK (modem_removed), self, NULL); #if WITH_MODEM_MANAGER_1 /* ModemManager1 stuff */ { priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); if (priv->dbus_connection) { priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, NULL, NULL); if (priv->modem_manager_1) { g_signal_connect (priv->modem_manager_1, "object-added", G_CALLBACK (modem_object_added), self); g_signal_connect (priv->modem_manager_1, "object-removed", G_CALLBACK (modem_object_removed), self); } } have_mm1 = !!priv->modem_manager_1; } #endif /* Ensure at least one of ModemManager or ModemManager1 are around */ if (!have_mm && !have_mm1) { dun_error (self, __func__, NULL, _("ModemManager is not running")); return; } /* Bluez */ priv->dun_proxy = dbus_g_proxy_new_for_name (priv->bus, BLUEZ_SERVICE, priv->object_path, BLUEZ_SERIAL_INTERFACE); g_assert (priv->dun_proxy); priv->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, self); g_message ("%s: calling Connect...", __func__); /* Watch for BT device property changes */ dbus_g_object_register_marshaller (_nma_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->dun_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->dun_proxy, "PropertyChanged", G_CALLBACK (dun_property_changed), self, NULL); /* Request a connection to the device and get the port */ dbus_g_proxy_begin_call_with_timeout (priv->dun_proxy, "Connect", dun_connect_cb, self, NULL, 20000, G_TYPE_STRING, "dun", G_TYPE_INVALID); g_message ("%s: waiting for Connect success...", __func__); }