nxdk_pgraph_tests
A collection of tests for the Xbox nv2a graphics processor
 
Loading...
Searching...
No Matches
ftp_logger.h
1#ifndef FTPLOGGER_H
2#define FTPLOGGER_H
3
4#include <atomic>
5#include <cstdint>
6#include <functional>
7#include <string>
8#include <thread>
9#include <vector>
10
11extern "C" struct FTPClient;
12
14class FTPLogger {
16 // before bailing.
17 static constexpr uint32_t kDefaultReconnectRetries = 4;
18 static constexpr uint32_t kDefaultTimeoutMilliseconds = 250;
19
20 public:
21 FTPLogger() = delete;
22 FTPLogger(uint32_t server_ip_host_ordered, uint16_t server_port_host_ordered, const std::string& username,
23 const std::string& password, uint32_t timeout_milliseconds)
24 : FTPLogger(server_ip_host_ordered, server_port_host_ordered, username, password, timeout_milliseconds,
25 kDefaultReconnectRetries) {}
26 FTPLogger(uint32_t server_ip_host_ordered, uint16_t ftp_server_port_host_ordered, std::string username,
27 std::string password, uint32_t timeout_milliseconds, uint32_t reconnect_retries)
28 : ftp_server_ip_{server_ip_host_ordered},
29 ftp_server_port_{ftp_server_port_host_ordered},
30 ftp_user_{std::move(username)},
31 ftp_password_{std::move(password)},
32 ftp_timeout_milliseconds_{timeout_milliseconds},
33 reconnect_retries_{reconnect_retries} {};
34
35 ~FTPLogger() { Disconnect(); }
36
37 bool Connect();
38 bool Disconnect();
39
40 bool IsConnected() const;
41
42 static constexpr char kProgressLogFilename[] = "nxdk_pgraph_tests_progress.log";
43
45 bool WriteFile(const std::string& filename, const std::string& content);
47 bool AppendFile(const std::string& filename, const std::string& content);
48
50 bool LogProgress(const std::string& message);
52 bool LogDebug(const std::string& message);
53
54 bool PutFile(const std::string& local_filename, const std::string& remote_filename = "");
55
56 void QueuePutFile(const std::string& local_filename, const std::string& remote_filename = "") {
57 send_file_queue_.emplace_back(local_filename, remote_filename);
58 }
59
61 const std::vector<std::pair<std::string, std::string>> send_file_queue() const { return send_file_queue_; }
62
63 void ClearSendQueue() { send_file_queue_.clear(); }
64
65 const std::vector<std::string>& error_log() const { return error_log_; }
66
67 private:
68 void ClearLog();
69 void LogError(std::string message);
70
71 private:
72 uint32_t ftp_server_ip_;
73 uint16_t ftp_server_port_;
74 std::string ftp_user_;
75 std::string ftp_password_;
76 uint32_t ftp_timeout_milliseconds_;
77 uint32_t reconnect_retries_;
78
79 FTPClient* ftp_client_{nullptr};
80
81 std::vector<std::string> error_log_;
82 std::vector<std::pair<std::string, std::string>> send_file_queue_;
83};
84
85#endif // FTPLOGGER_H
Handles sending log artifacts to an FTP server.
Definition ftp_logger.h:14
bool WriteFile(const std::string &filename, const std::string &content)
Truncate the remote file with the given name and set its content.
Definition ftp_logger.cpp:75
bool LogDebug(const std::string &message)
Append a debug-prefixed line to the standard progress log file.
Definition ftp_logger.cpp:142
bool LogProgress(const std::string &message)
Append a line to the standard progress log file.
Definition ftp_logger.cpp:133
bool AppendFile(const std::string &filename, const std::string &content)
Append the given content to the remote file with the given name.
Definition ftp_logger.cpp:103
const std::vector< std::pair< std::string, std::string > > send_file_queue() const
(Local path, Remote path) pairs that have been queued for sending.
Definition ftp_logger.h:61