// Jackson Coxson #pragma once #include #include #include #include #include #include namespace IdeviceFFI { using AfcClientPtr = std::unique_ptr>; class AfcFile; class AfcClient { public: // Factory: connect via Provider (AFC) static Result connect(Provider& provider); // Factory: connect via Provider (AFC2) static Result connect_afc2(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); // Ops Result, FfiError> list_directory(const std::string& path); Result make_directory(const std::string& path); Result get_file_info(const std::string& path); Result get_device_info(); Result remove_path(const std::string& path); Result remove_path_and_contents(const std::string& path); Result file_open(const std::string& path, AfcFopenMode mode); Result make_link(const std::string& target, const std::string& source, AfcLinkType link_type); Result rename_path(const std::string& source, const std::string& target); // RAII / moves ~AfcClient() noexcept = default; AfcClient(AfcClient&&) noexcept = default; AfcClient& operator=(AfcClient&&) noexcept = default; AfcClient(const AfcClient&) = delete; AfcClient& operator=(const AfcClient&) = delete; AfcClientHandle* raw() const noexcept { return handle_.get(); } static AfcClient adopt(AfcClientHandle* h) noexcept { return AfcClient(h); } private: explicit AfcClient(AfcClientHandle* h) noexcept : handle_(h) {} AfcClientPtr handle_{}; }; class AfcFile { public: // Ops Result close(); Result, FfiError> read(size_t len); Result, FfiError> read_all(); Result seek(int64_t offset, int whence); Result tell(); Result write(const uint8_t* data, size_t length); // RAII / moves ~AfcFile() noexcept; AfcFile(AfcFile&&) noexcept; AfcFile& operator=(AfcFile&&) noexcept; AfcFile(const AfcFile&) = delete; AfcFile& operator=(const AfcFile&) = delete; AfcFileHandle* raw() const noexcept { return handle_; } static AfcFile adopt(AfcFileHandle* h) noexcept { return AfcFile(h); } private: explicit AfcFile(AfcFileHandle* h) noexcept : handle_(h) {} AfcFileHandle* handle_ = nullptr; }; } // namespace IdeviceFFI