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
43 bool WriteFile(const std::string& filename, const std::string& content);
45 bool AppendFile(const std::string& filename, const std::string& content);
46
47 bool PutFile(const std::string& local_filename, const std::string& remote_filename = "");
48
49 void QueuePutFile(const std::string& local_filename, const std::string& remote_filename = "") {
50 send_file_queue_.emplace_back(local_filename, remote_filename);
51 }
52
54 const std::vector<std::pair<std::string, std::string>> send_file_queue() const { return send_file_queue_; }
55
56 void ClearSendQueue() { send_file_queue_.clear(); }
57
58 const std::vector<std::string>& error_log() const { return error_log_; }
59
60 private:
61 void ClearLog();
62 void LogError(std::string message);
63
64 private:
65 uint32_t ftp_server_ip_;
66 uint16_t ftp_server_port_;
67 std::string ftp_user_;
68 std::string ftp_password_;
69 uint32_t ftp_timeout_milliseconds_;
70 uint32_t reconnect_retries_;
71
72 FTPClient* ftp_client_{nullptr};
73
74 std::vector<std::string> error_log_;
75 std::vector<std::pair<std::string, std::string>> send_file_queue_;
76};
77
78#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 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:54