mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:37:34 +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:
parent
3dc87be891
commit
653e61d9cf
6 changed files with 112 additions and 28 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue