1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

LibProtocol: Add a Download object so users don't have to manage ID's

LibProtocol::Client::start_download() now gives you a Download object
with convenient hooks (on_finish & on_progress).

Also, the IPC handshake is snuck into the Client constructor, so you
don't need to perform it after instantiating a Client.

This makes using LibProtocol much more pleasant. :^)
This commit is contained in:
Andreas Kling 2019-11-24 13:20:44 +01:00
parent 3dc87be891
commit 653e61d9cf
6 changed files with 112 additions and 28 deletions

View file

@ -6,6 +6,8 @@
namespace LibProtocol {
class Download;
class Client : public IPC::Client::ConnectionNG<ProtocolClientEndpoint, ProtocolServerEndpoint>
, public ProtocolClientEndpoint {
C_OBJECT(Client)
@ -15,15 +17,15 @@ public:
virtual void handshake() override;
bool is_supported_protocol(const String&);
i32 start_download(const String& url);
bool stop_download(i32 download_id);
RefPtr<Download> start_download(const String& url);
Function<void(i32 download_id, bool success, u32 total_size, i32 shared_buffer_id)> on_download_finish;
Function<void(i32 download_id, u64 total_size, u64 downloaded_size)> on_download_progress;
bool stop_download(Badge<Download>, Download&);
private:
virtual void handle(const ProtocolClient::DownloadProgress&) override;
virtual void handle(const ProtocolClient::DownloadFinished&) override;
HashMap<i32, RefPtr<Download>> m_downloads;
};
}