Skip to content

Commit

Permalink
libcore|FS|Network: Updated remote file system classes
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 346a363 commit 67b410f
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 232 deletions.
17 changes: 5 additions & 12 deletions doomsday/libs/core/include/de/filesys/remote/link.h
Expand Up @@ -42,23 +42,18 @@ namespace filesys {
class DE_PUBLIC Link
{
public:
enum State
{
Deinitialized, Initializing, Ready
};
enum State { Deinitialized, Initializing, Ready };

typedef std::function<Link * (String const &address)> Constructor;
using Constructor = std::function<Link * (String const &address)>;

public:
virtual ~Link();

virtual void setLocalRoot(String const &rootPath);

Folder &localRoot() const;

String address() const;

State state() const;
String address() const;
State state() const;

/**
* Uses locally available indexes to determine which remote paths for a set of
Expand Down Expand Up @@ -99,10 +94,8 @@ class DE_PUBLIC Link
void cancelAllQueries();
void cleanupQueries();

//void packagePathsReceived(QueryId id, PackagePaths const &remotePaths);

void metadataReceived(QueryId id, DictionaryValue const &metadata);
void chunkReceived(QueryId id, duint64 startOffset, Block const &chunk, duint64 fileSize);
void chunkReceived(QueryId id, duint64 startOffset, const Block &chunk, duint64 fileSize);

virtual void wasConnected();
virtual void wasDisconnected();
Expand Down
6 changes: 2 additions & 4 deletions doomsday/libs/core/include/de/filesys/remote/nativelink.h
Expand Up @@ -21,8 +21,7 @@

#include "link.h"

namespace de {
namespace filesys {
namespace de { namespace filesys {

/**
* Link to a native Doomsday remote repository (see RemoteFeedUser on server).
Expand All @@ -48,7 +47,6 @@ class DE_PUBLIC NativeLink : public Link
DE_PRIVATE(d)
};

} // namespace filesys
} // namespace de
}} // namespace de::filesys

#endif // DE_FILESYS_NATIVELINK_H
21 changes: 10 additions & 11 deletions doomsday/libs/core/include/de/filesys/remote/query.h
Expand Up @@ -33,23 +33,22 @@ using QueryId = IdentifiedPacket::Id;

struct DE_PUBLIC RepositoryPath
{
Link const *link = nullptr;
String localPath;
String remotePath;
const Link *link = nullptr;
String localPath;
String remotePath;

RepositoryPath() = default;

RepositoryPath(Link const &link, String const &localPath, String const &remotePath)
RepositoryPath(const Link &link, const String &localPath, const String &remotePath)
: link(&link)
, localPath(localPath)
, remotePath(remotePath)
{}
};

typedef Hash<String, RepositoryPath> PackagePaths;

typedef std::function<void (DictionaryValue const &)> FileMetadata;
typedef std::function<void (duint64 startOffset, Block const &, duint64 remainingBytes)> FileContents;
using PackagePaths = Hash<String, RepositoryPath>;
using FileMetadata = std::function<void(DictionaryValue const &)>;
using FileContents = std::function<void(duint64 startOffset, Block const &, duint64 remainingBytes)>;

template <typename Callback>
using Request = std::shared_ptr<AsyncCallback<Callback>>;
Expand All @@ -61,8 +60,8 @@ using Request = std::shared_ptr<AsyncCallback<Callback>>;
struct DE_PUBLIC Query
{
// Query parameters:
QueryId id;
String path;
QueryId id;
String path;
StringList packageIds;

// Callbacks:
Expand All @@ -71,7 +70,7 @@ struct DE_PUBLIC Query

// Internal status:
duint64 receivedBytes = 0;
duint64 fileSize = 0;
duint64 fileSize = 0;

public:
Query(Request<FileMetadata> req, String path);
Expand Down
7 changes: 3 additions & 4 deletions doomsday/libs/core/include/de/filesys/remote/remotefeed.h
Expand Up @@ -33,11 +33,10 @@ class DE_PUBLIC RemoteFeed : public Feed
public:
RemoteFeed(String const &repository, String const &remotePath = String("/"));

String repository() const;

String description() const;
String repository() const;
String description() const;
PopulatedFiles populate(Folder const &folder);
bool prune(File &file) const;
bool prune(File &file) const;

protected:
RemoteFeed(RemoteFeed const &parentFeed, String const &remotePath);
Expand Down
31 changes: 12 additions & 19 deletions doomsday/libs/core/include/de/filesys/remote/remotefeedrelay.h
Expand Up @@ -26,8 +26,7 @@
#include "../Query"
#include "../Link"

namespace de {
namespace filesys {
namespace de { namespace filesys {

/**
* Connects to one or more remote file repositories and provides metadata and file
Expand All @@ -54,13 +53,10 @@ class DE_PUBLIC RemoteFeedRelay
*/
void defineLink(const Link::Constructor &linkConstructor);

void addRepository(String const &address, String const &localRootPath);

void removeRepository(String const &address);

Link *repository(String const &address) const;

StringList repositories() const;
void addRepository (String const &address, String const &localRootPath);
void removeRepository (String const &address);
Link * repository (String const &address) const;
StringList repositories () const;

bool isConnected(String const &address) const;

Expand All @@ -74,21 +70,18 @@ class DE_PUBLIC RemoteFeedRelay
*/
PackagePaths locatePackages(StringList const &packageIds) const;

Request<FileMetadata> fetchFileList(String const &repository,
String folderPath,
FileMetadata metadataReceived);

Request<FileContents> fetchFileContents(String const &repository,
String filePath,
FileContents contentsReceived);
Request<FileMetadata> fetchFileList(const String &repository,
String folderPath,
FileMetadata metadataReceived);

// QNetworkAccessManager &network();
Request<FileContents> fetchFileContents(const String &repository,
String filePath,
FileContents contentsReceived);

private:
DE_PRIVATE(d)
};

} // namespace filesys
} // namespace de
}} // namespace de::filesys

#endif // LIBCORE_REMOTEFEEDRELAY_H
20 changes: 9 additions & 11 deletions doomsday/libs/core/include/de/filesys/remote/remotefile.h
Expand Up @@ -40,25 +40,23 @@ class DE_PUBLIC RemoteFile : public LinkFile, public Asset, public IDownloadable
static String const CACHE_PATH;

public:
RemoteFile(String const &name, String const &remotePath, Block const &remoteMetaId,
String const &repositoryAddress = String());
RemoteFile(const String &name,
const String &remotePath,
const Block & remoteMetaId,
const String &repositoryAddress = {});

String describe() const override;
Block metaId() const override;
String describe() const override;
Block metaId() const override;
Asset & asset() override;
const Asset &asset() const override;
dsize downloadSize() const override;

/**
* Initiates downloading of the file contents from the remote backend.
*/
void download() override;

void cancelDownload() override;

Asset &asset() override;

Asset const &asset() const override;

dsize downloadSize() const override;

void deleteCache();

// File streaming.
Expand Down
12 changes: 4 additions & 8 deletions doomsday/libs/core/include/de/filesys/remote/webhostedlink.h
Expand Up @@ -22,8 +22,7 @@
#include "../Link"
#include "../../PathTree"

namespace de {
namespace filesys {
namespace de { namespace filesys {

/**
* Repository of files hosted on a web server as a file tree. Assumed to come
Expand All @@ -32,14 +31,12 @@ namespace filesys {
class DE_PUBLIC WebHostedLink : public Link
{
public:
struct DE_PUBLIC FileEntry : public PathTree::Node
{
struct DE_PUBLIC FileEntry : public PathTree::Node {
duint64 size = 0;
Time modTime;
Time modTime;

FileEntry(PathTree::NodeArgs const &args) : Node(args) {}
FileEntry() = delete;

Block metaId(Link const &link) const;
};

Expand Down Expand Up @@ -67,7 +64,6 @@ class DE_PUBLIC WebHostedLink : public Link
DE_PRIVATE(d)
};

} // namespace filesys
} // namespace de
}} // namespace de::filesys

#endif // DE_FILESYS_WEBHOSTEDLINK_H
22 changes: 17 additions & 5 deletions doomsday/libs/core/include/de/net/webrequest.h
Expand Up @@ -32,8 +32,9 @@ namespace de {
class DE_PUBLIC WebRequest
{
public:
DE_DEFINE_AUDIENCE2(Progress, void webRequestProgress(WebRequest &, dsize currentSize, dsize totalSize))
DE_DEFINE_AUDIENCE2(Finished, void webRequestFinished(WebRequest &))
DE_DEFINE_AUDIENCE2(Progress, void webRequestProgress(WebRequest &, dsize currentSize, dsize totalSize))
DE_DEFINE_AUDIENCE2(ReadyRead, void webRequestReadyRead(WebRequest &))
DE_DEFINE_AUDIENCE2(Finished, void webRequestFinished(WebRequest &))

/// The WebRequest object is busy pending the results of a started request. @ingroup errors
DE_ERROR(PendingError);
Expand All @@ -48,13 +49,24 @@ class DE_PUBLIC WebRequest
const Block & content,
const char * httpContentType = "application/octet-stream");

bool isPending() const;
bool isFinished() const;
bool isFailed() const;
bool isPending() const;
bool isFinished() const;
bool isSucceeded() const;
bool isFailed() const;
String errorMessage() const;

dsize contentLength() const;
Block result() const;

/**
* Reads all data received so far and removes it from the result buffer.
* This is useful if the data should be processed as it is received (e.g., streaming).
* Note that called result() will not return anything after called readAll().
*
* @return Received bytes.
*/
Block readAll();

public:
static bool splitUriComponents(const String &uri,
String * scheme = nullptr,
Expand Down
30 changes: 8 additions & 22 deletions doomsday/libs/core/src/filesys/remote/link.cpp
Expand Up @@ -25,16 +25,16 @@
#include <de/Garbage>
#include <de/charsymbols.h>

namespace de {
namespace filesys {
namespace de { namespace filesys {

DE_PIMPL(Link), public AsyncScope
{
String localRootPath;
State state = Initializing;
String address;
QueryId nextQueryId = 1;
List<Query> deferredQueries;
State state = Initializing;

QueryId nextQueryId = 1;
List<Query> deferredQueries;
Hash<QueryId, Query> pendingQueries;

Impl(Public *i) : Base(i)
Expand Down Expand Up @@ -250,18 +250,6 @@ File *Link::populateRemotePath(String const &, RepositoryPath const &path) const
return FS::tryLocate<File>(path.localPath);
}

//void Link::packagePathsReceived(QueryId id, PackagePaths const &remotePaths)
//{
// if (auto *query = findQuery(id))
// {
// if (query->remotePaths)
// {
// query->remotePaths->call(id, remotePaths);
// }
// d->pendingQueries.remove(id);
// }
//}

void Link::metadataReceived(QueryId id, DictionaryValue const &metadata)
{
if (auto *query = findQuery(id))
Expand All @@ -274,7 +262,7 @@ void Link::metadataReceived(QueryId id, DictionaryValue const &metadata)
}
}

void Link::chunkReceived(QueryId id, duint64 startOffset, Block const &chunk, duint64 fileSize)
void Link::chunkReceived(QueryId id, duint64 startOffset, const Block &chunk, duint64 fileSize)
{
if (auto *query = findQuery(id))
{
Expand All @@ -295,8 +283,7 @@ void Link::chunkReceived(QueryId id, duint64 startOffset, Block const &chunk, du
query->receivedBytes += chunk.size();

// Notify about progress and provide the data chunk to the requestor.
query->fileContents->call(startOffset, chunk,
fileSize - query->receivedBytes);
query->fileContents->call(startOffset, chunk, fileSize - query->receivedBytes);

if (fileSize == query->receivedBytes)
{
Expand All @@ -306,5 +293,4 @@ void Link::chunkReceived(QueryId id, duint64 startOffset, Block const &chunk, du
}
}

} // namespace filesys
} // namespace de
}} // namespace de::filesys
22 changes: 10 additions & 12 deletions doomsday/libs/core/src/filesys/remote/nativelink.cpp
Expand Up @@ -26,8 +26,7 @@
#include "de/RemoteFeedProtocol"
#include "de/Socket"

namespace de {
namespace filesys {
namespace de { namespace filesys {

const char *NativeLink::URL_SCHEME = "doomsday:";

Expand Down Expand Up @@ -157,14 +156,14 @@ PackagePaths NativeLink::locatePackages(const StringList &packageIds) const

LoopResult filesys::NativeLink::forPackageIds(std::function<LoopResult (String const &)> func) const
{
return FS::locate<Folder>(DE_STR("/remote/server")).forContents([&func] (String name, File &) -> LoopResult
{
if (auto result = func(name))
{
return result;
}
return LoopContinue;
});
return FS::locate<Folder>(DE_STR("/remote/server"))
.forContents([&func](String name, File &) -> LoopResult {
if (auto result = func(name))
{
return result;
}
return LoopContinue;
});
}

void NativeLink::wasConnected()
Expand All @@ -191,5 +190,4 @@ void NativeLink::transmit(Query const &query)
d->socket.sendPacket(packet);
}

} // namespace filesys
} // namespace de
}} // namespace de::filesys

0 comments on commit 67b410f

Please sign in to comment.