mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-07 18:14:41 +02:00

This runs clang-tidy on some other files in launcher/net/. This also makes use of some JSON wrappers in HttpMetaCache, instead of using the Qt stuff directly. Lastly, this removes useless null checks (crashes don't occur because of this, but because of concurrent usage / free of the QByteArray pointer), and fix a fixme in Download.h
66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "net/NetAction.h"
|
|
|
|
#include "Validator.h"
|
|
|
|
namespace Net {
|
|
class Sink {
|
|
public:
|
|
Sink() = default;
|
|
virtual ~Sink() = default;
|
|
|
|
public:
|
|
virtual auto init(QNetworkRequest& request) -> Task::State = 0;
|
|
virtual auto write(QByteArray& data) -> Task::State = 0;
|
|
virtual auto abort() -> Task::State = 0;
|
|
virtual auto finalize(QNetworkReply& reply) -> Task::State = 0;
|
|
|
|
virtual auto hasLocalData() -> bool = 0;
|
|
|
|
void addValidator(Validator* validator)
|
|
{
|
|
if (validator) {
|
|
validators.push_back(std::shared_ptr<Validator>(validator));
|
|
}
|
|
}
|
|
|
|
protected:
|
|
bool initAllValidators(QNetworkRequest& request)
|
|
{
|
|
for (auto& validator : validators) {
|
|
if (!validator->init(request))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
bool finalizeAllValidators(QNetworkReply& reply)
|
|
{
|
|
for (auto& validator : validators) {
|
|
if (!validator->validate(reply))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
bool failAllValidators()
|
|
{
|
|
bool success = true;
|
|
for (auto& validator : validators) {
|
|
success &= validator->abort();
|
|
}
|
|
return success;
|
|
}
|
|
bool writeAllValidators(QByteArray& data)
|
|
{
|
|
for (auto& validator : validators) {
|
|
if (!validator->write(data))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected:
|
|
std::vector<std::shared_ptr<Validator>> validators;
|
|
};
|
|
} // namespace Net
|