// Jackson Coxson #pragma once #include #include #include #include #include #include namespace IdeviceFFI { using MobileBackup2Ptr = std::unique_ptr>; /// Callback types for BackupDelegate operations. /// The C++ caller provides these to drive filesystem I/O during backup/restore. struct BackupDelegateCallbacks { /// Return available disk space in bytes for the given path std::function get_free_disk_space; /// Read an entire file and return its contents std::function(const std::string&)> open_file_read; /// Create/truncate a file for writing (called before write_chunk) std::function create_file_write; /// Write a chunk of data to the currently open file std::function write_chunk; /// Close the current file (called after all write_chunk calls) std::function close_file; /// Recursively create a directory and all parents std::function create_dir_all; /// Remove a file or directory recursively std::function remove; /// Rename/move a file or directory std::function rename; /// Copy a file or directory std::function copy; /// Check if a path exists std::function exists; /// Check if a path is a directory std::function is_dir; /// Optional progress callback: bytes_done, bytes_total, overall_progress std::function on_progress; }; class MobileBackup2 { public: // Factory: connect via Provider static Result connect(Provider& provider); // Factory: connect via RSD tunnel static Result connect_rsd(AdapterHandle* adapter, RsdHandshakeHandle* handshake); // Factory: wrap an existing Idevice socket (consumes it on success) static Result from_socket(Idevice&& socket); // Operations Result backup(const std::string& backup_root, Option source_identifier, Option options, BackupDelegateCallbacks& delegate); Result restore(const std::string& backup_root, Option source_identifier, Option options, BackupDelegateCallbacks& delegate); Result change_password(const std::string& backup_root, Option old_password, Option new_password, BackupDelegateCallbacks& delegate); Result disconnect(); // RAII / moves ~MobileBackup2() noexcept = default; MobileBackup2(MobileBackup2&&) noexcept = default; MobileBackup2& operator=(MobileBackup2&&) noexcept = default; MobileBackup2(const MobileBackup2&) = delete; MobileBackup2& operator=(const MobileBackup2&) = delete; MobileBackup2ClientHandle* raw() const noexcept { return handle_.get(); } static MobileBackup2 adopt(MobileBackup2ClientHandle* h) noexcept { return MobileBackup2(h); } private: explicit MobileBackup2(MobileBackup2ClientHandle* h) noexcept : handle_(h) {} MobileBackup2Ptr handle_{}; }; } // namespace IdeviceFFI