arch codereview
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
|
||||
namespace ui {
|
||||
|
||||
class TransferOverlay : public pu::ui::Overlay {
|
||||
private:
|
||||
pu::ui::elm::TextBlock::Ref titleText;
|
||||
pu::ui::elm::TextBlock::Ref statusText;
|
||||
pu::ui::elm::ProgressBar::Ref progressBar;
|
||||
pu::ui::elm::TextBlock::Ref hintText;
|
||||
|
||||
public:
|
||||
static constexpr int OvlX = 200;
|
||||
static constexpr int OvlY = 240;
|
||||
static constexpr int OvlW = 880;
|
||||
static constexpr int OvlH = 240;
|
||||
|
||||
TransferOverlay(const std::string &title)
|
||||
: Overlay(OvlX, OvlY, OvlW, OvlH, pu::ui::Color(30, 30, 30, 220))
|
||||
{
|
||||
titleText = pu::ui::elm::TextBlock::New(OvlX + 40, OvlY + 30, title);
|
||||
titleText->SetColor(pu::ui::Color(255, 255, 255, 255));
|
||||
|
||||
statusText = pu::ui::elm::TextBlock::New(OvlX + 40, OvlY + 90, "");
|
||||
statusText->SetColor(pu::ui::Color(180, 180, 180, 255));
|
||||
|
||||
progressBar = pu::ui::elm::ProgressBar::New(OvlX + 40, OvlY + 140, OvlW - 80, 20, 100.0);
|
||||
progressBar->SetProgressColor(pu::ui::Color(100, 180, 255, 255));
|
||||
progressBar->SetBackgroundColor(pu::ui::Color(70, 70, 70, 255));
|
||||
|
||||
hintText = pu::ui::elm::TextBlock::New(OvlX + 40, OvlY + 195, "Press B to cancel");
|
||||
hintText->SetColor(pu::ui::Color(130, 130, 130, 255));
|
||||
|
||||
this->Add(titleText);
|
||||
this->Add(statusText);
|
||||
this->Add(progressBar);
|
||||
this->Add(hintText);
|
||||
}
|
||||
PU_SMART_CTOR(TransferOverlay)
|
||||
|
||||
void SetStatus(const std::string &status) {
|
||||
statusText->SetText(status);
|
||||
}
|
||||
|
||||
void SetProgress(double val) {
|
||||
progressBar->SetProgress(val);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
struct TransferState {
|
||||
std::atomic<bool> done{false};
|
||||
std::atomic<bool> cancelled{false};
|
||||
std::atomic<uint64_t> bytes_done{0};
|
||||
std::atomic<uint64_t> bytes_total{0};
|
||||
|
||||
std::string status;
|
||||
mutable std::mutex status_mutex;
|
||||
|
||||
void reset() {
|
||||
done = false;
|
||||
cancelled = false;
|
||||
bytes_done = 0;
|
||||
bytes_total = 0;
|
||||
std::lock_guard<std::mutex> lock(status_mutex);
|
||||
status.clear();
|
||||
}
|
||||
|
||||
double progress() const {
|
||||
uint64_t t = bytes_total.load();
|
||||
return t ? (double)bytes_done.load() / (double)t * 100.0 : 0.0;
|
||||
}
|
||||
|
||||
std::string getStatus() const {
|
||||
std::lock_guard<std::mutex> lock(status_mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
void setStatus(const std::string& s) {
|
||||
std::lock_guard<std::mutex> lock(status_mutex);
|
||||
status = s;
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,10 @@
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
namespace fs = std::filesystem;
|
||||
using path = fs::path;
|
||||
|
||||
int transfer_files(path directory);
|
||||
bool isClientTransferDone();
|
||||
void cancelClientTransfer();
|
||||
double getClientProgress();
|
||||
std::string getClientStatusText();
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
|
||||
struct Socket {
|
||||
int fd = -1;
|
||||
|
||||
Socket() = default;
|
||||
explicit Socket(int fd) : fd(fd) {}
|
||||
~Socket() { if (fd >= 0) close(fd); }
|
||||
|
||||
Socket(const Socket&) = delete;
|
||||
Socket& operator=(const Socket&) = delete;
|
||||
Socket(Socket&& o) : fd(o.fd) { o.fd = -1; }
|
||||
|
||||
operator int() const { return fd; }
|
||||
bool valid() const { return fd >= 0; }
|
||||
void release() { fd = -1; }
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace proto {
|
||||
constexpr uint16_t TCP_PORT = 8080;
|
||||
constexpr uint16_t MULTICAST_PORT = 8081;
|
||||
constexpr char MULTICAST_GROUP[] = "239.0.0.1";
|
||||
constexpr size_t BUF_SIZE = 65536;
|
||||
constexpr uint32_t MAX_FILENAME = 4096;
|
||||
constexpr uint32_t EOF_SENTINEL = 0;
|
||||
|
||||
// Wire layout per file:
|
||||
// [filename_len : uint32_t LE] — 0 == end-of-stream
|
||||
// [filename : filename_len bytes]
|
||||
// [file_size : uint64_t LE]
|
||||
// [file_data : file_size bytes]
|
||||
}
|
||||
+7
-1
@@ -1 +1,7 @@
|
||||
int startSendingThread();
|
||||
#include <string>
|
||||
int startSendingThread();
|
||||
bool isServerTransferDone();
|
||||
bool isServerTransferCancelled();
|
||||
void cancelServerTransfer();
|
||||
double getServerProgress();
|
||||
std::string getServerStatusText();
|
||||
Reference in New Issue
Block a user