More work on assets (not compiling)

This commit is contained in:
Emil Axelsson
2017-11-14 17:23:58 +01:00
parent 6a4f938bac
commit ce9b75117e
8 changed files with 168 additions and 94 deletions

View File

@@ -111,15 +111,29 @@ std::string TorrentSynchronization::directory() {
}
void TorrentSynchronization::start() {
size_t torrentId = _torrentClient->addMagnetLink(_magnetLink, directory());
resolve();
return;
if (_enabled) {
return;
}
_enabled = true;
_torrentId = _torrentClient->addMagnetLink(
_magnetLink,
directory(),
[this](TorrentClient::Progress p) {
updateTorrentProgress(p);
}
);
}
void TorrentSynchronization::cancel() {
if (_enabled) {
_torrentClient->removeTorrent(_torrentId);
_enabled = false;
}
}
void TorrentSynchronization::clear() {
// Todo: remove directory!
}
@@ -135,4 +149,8 @@ bool TorrentSynchronization::nTotalBytesIsKnown() {
return false;
}
void TorrentSynchronization::updateTorrentProgress(TorrentClient::Progress p) {
// TODO: implement this
}
} // namespace openspace

View File

@@ -25,6 +25,8 @@
#ifndef __OPENSPACE_MODULE_SYNC___TORRENTSYNCHRONIZATION___H__
#define __OPENSPACE_MODULE_SYNC___TORRENTSYNCHRONIZATION___H__
#include <modules/sync/torrentclient.h>
#include <openspace/util/resourcesynchronization.h>
#include <openspace/documentation/documentation.h>
@@ -54,6 +56,10 @@ public:
bool nTotalBytesIsKnown() override;
private:
void updateTorrentProgress(TorrentClient::Progress p);
std::atomic_bool _enabled = false;
size_t _torrentId;
std::string uniformResourceName() const;
std::string _identifier;
std::string _magnetLink;

View File

@@ -101,7 +101,7 @@ void TorrentClient::pollAlerts() {
}
}
size_t TorrentClient::addTorrentFile(std::string torrentFile, std::string destination) {
size_t TorrentClient::addTorrentFile(std::string torrentFile, std::string destination, TorrentProgressCallback cb) {
if (!_session) {
LERROR("Torrent session not initialized when adding torrent");
return -1;
@@ -122,7 +122,8 @@ size_t TorrentClient::addTorrentFile(std::string torrentFile, std::string destin
return id;
}
size_t TorrentClient::addMagnetLink(std::string magnetLink, std::string destination) {
size_t TorrentClient::addMagnetLink(std::string magnetLink, std::string destination, TorrentProgressCallback cb) {
// TODO: register callback!
if (!_session) {
LERROR("Torrent session not initialized when adding torrent");
return -1;

View File

@@ -48,11 +48,17 @@ public:
libtorrent::torrent_handle handle;
};
struct Progress {
};
using TorrentProgressCallback = std::function<void(Progress)>;
TorrentClient();
~TorrentClient();
void initialize();
size_t addTorrentFile(std::string torrentFile, std::string destination);
size_t addMagnetLink(std::string magnetLink, std::string destination);
size_t addTorrentFile(std::string torrentFile, std::string destination, TorrentProgressCallback cb);
size_t addMagnetLink(std::string magnetLink, std::string destination, TorrentProgressCallback cb);
void removeTorrent(size_t id);
void pollAlerts();
private: