static void look_for_sms_in_modem (GetSmsContext *ctx) { MMModemMessaging *modem; if (!ctx->modems) { g_printerr ("error: couldn't find SMS at '%s': 'not found in any modem'\n", ctx->sms_path); exit (EXIT_FAILURE); } /* Loop looking for the sms in each modem found */ ctx->current = MM_OBJECT (ctx->modems->data); ctx->modems = g_list_delete_link (ctx->modems, ctx->modems); modem = mm_object_get_modem_messaging (ctx->current); if (modem) { g_debug ("Looking for sms '%s' in modem '%s'...", ctx->sms_path, mm_object_get_path (ctx->current)); mm_modem_messaging_list (modem, ctx->cancellable, (GAsyncReadyCallback)list_sms_ready, ctx); g_object_unref (modem); return; } /* Current modem has no messaging capabilities, try with next modem */ look_for_sms_in_modem (ctx); }
static void get_modem_ready (GObject *source, GAsyncResult *result, gpointer none) { ctx->object = mmcli_get_modem_finish (result, &ctx->manager); ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object); /* Setup operation timeout */ if (ctx->modem_messaging) mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging)); ensure_modem_messaging (); if (status_flag) g_assert_not_reached (); /* Request to list SMS? */ if (list_flag) { g_debug ("Asynchronously listing SMS in modem..."); mm_modem_messaging_list (ctx->modem_messaging, ctx->cancellable, (GAsyncReadyCallback)list_ready, NULL); return; } /* Request to create a new SMS? */ if (create_str) { MMSmsProperties *properties; properties = build_sms_properties_from_input (create_str, create_with_data_str); g_debug ("Asynchronously creating new SMS in modem..."); mm_modem_messaging_create (ctx->modem_messaging, properties, ctx->cancellable, (GAsyncReadyCallback)create_ready, NULL); g_object_unref (properties); return; } /* Request to delete a given SMS? */ if (delete_str) { mmcli_get_sms (ctx->connection, delete_str, ctx->cancellable, (GAsyncReadyCallback)get_sms_to_delete_ready, NULL); return; } g_warn_if_reached (); }
void mmcli_modem_messaging_run_synchronous (GDBusConnection *connection) { GError *error = NULL; /* Initialize context */ ctx = g_new0 (Context, 1); ctx->object = mmcli_get_modem_sync (connection, mmcli_get_common_modem_string (), &ctx->manager); ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object); /* Setup operation timeout */ if (ctx->modem_messaging) mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging)); ensure_modem_messaging (); /* Request to get location status? */ if (status_flag) { g_debug ("Printing messaging status..."); print_messaging_status (); return; } /* Request to list the SMS? */ if (list_flag) { GList *result; g_debug ("Synchronously listing SMS messages..."); result = mm_modem_messaging_list_sync (ctx->modem_messaging, NULL, &error); list_process_reply (result, error); return; } /* Request to create a new SMS? */ if (create_str) { MMSms *sms; GError *error = NULL; MMSmsProperties *properties; properties = build_sms_properties_from_input (create_str, create_with_data_str); g_debug ("Synchronously creating new SMS in modem..."); sms = mm_modem_messaging_create_sync (ctx->modem_messaging, properties, NULL, &error); g_object_unref (properties); create_process_reply (sms, error); return; } /* Request to delete a given SMS? */ if (delete_str) { gboolean result; MMSms *sms; MMObject *obj = NULL; sms = mmcli_get_sms_sync (connection, delete_str, NULL, &obj); if (!g_str_equal (mm_object_get_path (obj), mm_modem_messaging_get_path (ctx->modem_messaging))) { g_printerr ("error: SMS '%s' not owned by modem '%s'", mm_sms_get_path (sms), mm_modem_messaging_get_path (ctx->modem_messaging)); exit (EXIT_FAILURE); } result = mm_modem_messaging_delete_sync (ctx->modem_messaging, mm_sms_get_path (sms), NULL, &error); g_object_unref (sms); g_object_unref (obj); delete_process_reply (result, error); return; } g_warn_if_reached (); }
MMSms * mmcli_get_sms_sync (GDBusConnection *connection, const gchar *path_or_index, MMManager **o_manager, MMObject **o_object) { MMManager *manager; GList *modems; GList *l; MMSms *found = NULL; gchar *sms_path; sms_path = get_sms_path (path_or_index); manager = mmcli_get_manager_sync (connection); modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager)); if (!modems) { g_printerr ("error: couldn't find sms at '%s': 'no modems found'\n", sms_path); exit (EXIT_FAILURE); } for (l = modems; !found && l; l = g_list_next (l)) { GError *error = NULL; MMObject *object; MMModemMessaging *modem; GList *sms_list; object = MM_OBJECT (l->data); modem = mm_object_get_modem_messaging (object); /* If this modem doesn't implement messaging, continue to next one */ if (!modem) continue; sms_list = mm_modem_messaging_list_sync (modem, NULL, &error); if (error) { g_printerr ("error: couldn't list SMS at '%s': '%s'\n", mm_modem_messaging_get_path (modem), error->message); exit (EXIT_FAILURE); } found = find_sms_in_list (sms_list, sms_path); g_list_free_full (sms_list, (GDestroyNotify) g_object_unref); if (found && o_object) *o_object = g_object_ref (object); g_object_unref (modem); } if (!found) { g_printerr ("error: couldn't find SMS at '%s': 'not found in any modem'\n", sms_path); exit (EXIT_FAILURE); } g_list_free_full (modems, (GDestroyNotify) g_object_unref); g_free (sms_path); if (o_manager) *o_manager = manager; else g_object_unref (manager); return found; }