static void print_messaging_status (void) { MMSmsStorage *supported = NULL; guint supported_len = 0; gchar *supported_str = NULL; mm_modem_messaging_get_supported_storages (ctx->modem_messaging, &supported, &supported_len); if (supported) supported_str = mm_common_build_sms_storages_string (supported, supported_len); #undef VALIDATE_UNKNOWN #define VALIDATE_UNKNOWN(str) (str ? str : "unknown") g_print ("\n" "%s\n" " ----------------------------\n" " Messaging | supported storages: '%s'\n" " | default storage: '%s'\n", mm_modem_messaging_get_path (ctx->modem_messaging), VALIDATE_UNKNOWN (supported_str), VALIDATE_UNKNOWN (mm_sms_storage_get_string ( mm_modem_messaging_get_default_storage ( ctx->modem_messaging)))); g_free (supported_str); }
static void list_sms_ready (MMModemMessaging *modem, GAsyncResult *res, GetSmsContext *ctx) { GList *sms_list; GError *error = NULL; sms_list = mm_modem_messaging_list_finish (modem, res, &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); } ctx->sms = find_sms_in_list (sms_list, ctx->sms_path); g_list_free_full (sms_list, (GDestroyNotify) g_object_unref); /* Found! */ if (ctx->sms) { g_simple_async_result_set_op_res_gpointer ( ctx->result, ctx, (GDestroyNotify)get_sms_context_free); get_sms_context_complete (ctx); return; } /* Not found, try with next modem */ look_for_sms_in_modem (ctx); }
static void get_sms_to_delete_ready (GDBusConnection *connection, GAsyncResult *res) { MMSms *sms; MMObject *obj = NULL; sms = mmcli_get_sms_finish (res, 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); } mm_modem_messaging_delete (ctx->modem_messaging, mm_sms_get_path (sms), ctx->cancellable, (GAsyncReadyCallback)delete_ready, NULL); g_object_unref (sms); g_object_unref (obj); }
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; }