Create log files on heap.

...for imminent refactor where user can manually start/stop logging, and maybe even change the filename! *swoon*
This commit is contained in:
Jared Boone 2016-02-10 20:53:14 -08:00
parent 58864ebbe7
commit 937dad62ee
8 changed files with 48 additions and 11 deletions

View file

@ -159,6 +159,12 @@ static std::string true_heading(const TrueHeading value) {
} /* namespace format */ } /* namespace format */
} /* namespace ais */ } /* namespace ais */
AISLogger::AISLogger(
const std::string& file_path
) : log_file { file_path }
{
}
void AISLogger::on_packet(const ais::Packet& packet) { void AISLogger::on_packet(const ais::Packet& packet) {
// TODO: Unstuff here, not in baseband! // TODO: Unstuff here, not in baseband!
if( log_file.is_ready() ) { if( log_file.is_ready() ) {
@ -368,6 +374,8 @@ AISAppView::AISAppView(NavigationView&) {
recent_entry_detail_view.on_close = [this]() { recent_entry_detail_view.on_close = [this]() {
this->on_show_list(); this->on_show_list();
}; };
logger = std::make_unique<AISLogger>("ais.txt");
} }
AISAppView::~AISAppView() { AISAppView::~AISAppView() {
@ -389,7 +397,10 @@ void AISAppView::set_parent_rect(const Rect new_parent_rect) {
} }
void AISAppView::on_packet(const ais::Packet& packet) { void AISAppView::on_packet(const ais::Packet& packet) {
logger.on_packet(packet); if( logger ) {
logger->on_packet(packet);
}
const auto updated_entry = recent.on_packet(packet.source_id(), packet); const auto updated_entry = recent.on_packet(packet.source_id(), packet);
recent_entries_view.set_dirty(); recent_entries_view.set_dirty();

View file

@ -90,10 +90,12 @@ using AISRecentEntries = RecentEntries<ais::Packet, AISRecentEntry>;
class AISLogger { class AISLogger {
public: public:
AISLogger(const std::string& file_path);
void on_packet(const ais::Packet& packet); void on_packet(const ais::Packet& packet);
private: private:
LogFile log_file { "ais.txt" }; LogFile log_file;
}; };
namespace ui { namespace ui {
@ -150,7 +152,7 @@ private:
static constexpr uint32_t baseband_bandwidth = 1750000; static constexpr uint32_t baseband_bandwidth = 1750000;
AISRecentEntries recent; AISRecentEntries recent;
AISLogger logger; std::unique_ptr<AISLogger> logger;
AISRecentEntriesView recent_entries_view { recent }; AISRecentEntriesView recent_entries_view { recent };
AISRecentEntryDetailView recent_entry_detail_view; AISRecentEntryDetailView recent_entry_detail_view;

View file

@ -55,6 +55,12 @@ std::string consumption(Consumption value) {
} /* namespace ert */ } /* namespace ert */
ERTLogger::ERTLogger(
const std::string& file_path
) : log_file { file_path }
{
}
void ERTLogger::on_packet(const ert::Packet& packet) { void ERTLogger::on_packet(const ert::Packet& packet) {
if( log_file.is_ready() ) { if( log_file.is_ready() ) {
const auto formatted = packet.symbols_formatted(); const auto formatted = packet.symbols_formatted();
@ -144,6 +150,8 @@ ERTAppView::ERTAppView(NavigationView&) {
.sampling_rate = sampling_rate, .sampling_rate = sampling_rate,
.decimation_factor = 1, .decimation_factor = 1,
}); });
logger = std::make_unique<ERTLogger>("ert.txt");
} }
ERTAppView::~ERTAppView() { ERTAppView::~ERTAppView() {
@ -163,7 +171,9 @@ void ERTAppView::set_parent_rect(const Rect new_parent_rect) {
} }
void ERTAppView::on_packet(const ert::Packet& packet) { void ERTAppView::on_packet(const ert::Packet& packet) {
logger.on_packet(packet); if( logger ) {
logger->on_packet(packet);
}
if( packet.crc_ok() ) { if( packet.crc_ok() ) {
recent.on_packet(packet.id(), packet); recent.on_packet(packet.id(), packet);

View file

@ -60,10 +60,12 @@ struct ERTRecentEntry {
class ERTLogger { class ERTLogger {
public: public:
ERTLogger(const std::string& file_path);
void on_packet(const ert::Packet& packet); void on_packet(const ert::Packet& packet);
private: private:
LogFile log_file { "ert.txt" }; LogFile log_file;
}; };
using ERTRecentEntries = RecentEntries<ert::Packet, ERTRecentEntry>; using ERTRecentEntries = RecentEntries<ert::Packet, ERTRecentEntry>;
@ -93,7 +95,7 @@ public:
private: private:
ERTRecentEntries recent; ERTRecentEntries recent;
ERTLogger logger; std::unique_ptr<ERTLogger> logger;
ERTRecentEntriesView recent_entries_view { recent }; ERTRecentEntriesView recent_entries_view { recent };

View file

@ -27,7 +27,7 @@
using namespace lpc43xx; using namespace lpc43xx;
LogFile::LogFile( LogFile::LogFile(
const std::string file_path const std::string& file_path
) : file_path { file_path } ) : file_path { file_path }
{ {
file.open_for_append(file_path); file.open_for_append(file_path);

View file

@ -32,7 +32,7 @@ using namespace lpc43xx;
class LogFile { class LogFile {
public: public:
LogFile(const std::string file_path); LogFile(const std::string& file_path);
~LogFile(); ~LogFile();
bool is_ready(); bool is_ready();

View file

@ -136,6 +136,12 @@ size_t Packet::crc_valid_length() const {
} /* namespace tpms */ } /* namespace tpms */
TPMSLogger::TPMSLogger(
const std::string& file_path
) : log_file { file_path }
{
}
void TPMSLogger::on_packet(const tpms::Packet& packet, const uint32_t target_frequency) { void TPMSLogger::on_packet(const tpms::Packet& packet, const uint32_t target_frequency) {
const auto hex_formatted = packet.symbols_formatted(); const auto hex_formatted = packet.symbols_formatted();
@ -251,6 +257,8 @@ TPMSAppView::TPMSAppView(NavigationView&) {
.sampling_rate = sampling_rate, .sampling_rate = sampling_rate,
.decimation_factor = 1, .decimation_factor = 1,
}); });
logger = std::make_unique<TPMSLogger>("tpms.txt");
} }
TPMSAppView::~TPMSAppView() { TPMSAppView::~TPMSAppView() {
@ -270,7 +278,9 @@ void TPMSAppView::set_parent_rect(const Rect new_parent_rect) {
} }
void TPMSAppView::on_packet(const tpms::Packet& packet) { void TPMSAppView::on_packet(const tpms::Packet& packet) {
logger.on_packet(packet, target_frequency()); if( logger ) {
logger->on_packet(packet, target_frequency());
}
const auto reading_opt = packet.reading(); const auto reading_opt = packet.reading();
if( reading_opt.is_valid() ) { if( reading_opt.is_valid() ) {

View file

@ -186,10 +186,12 @@ using TPMSRecentEntries = RecentEntries<tpms::Reading, TPMSRecentEntry>;
class TPMSLogger { class TPMSLogger {
public: public:
TPMSLogger(const std::string& file_path);
void on_packet(const tpms::Packet& packet, const uint32_t target_frequency); void on_packet(const tpms::Packet& packet, const uint32_t target_frequency);
private: private:
LogFile log_file { "tpms.txt" }; LogFile log_file;
}; };
namespace ui { namespace ui {
@ -217,7 +219,7 @@ private:
static constexpr uint32_t baseband_bandwidth = 1750000; static constexpr uint32_t baseband_bandwidth = 1750000;
TPMSRecentEntries recent; TPMSRecentEntries recent;
TPMSLogger logger; std::unique_ptr<TPMSLogger> logger;
TPMSRecentEntriesView recent_entries_view { recent }; TPMSRecentEntriesView recent_entries_view { recent };