forked from bmatheny/memkeys
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report type now configurable, closes bmatheny#11
- Loading branch information
Showing
13 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdexcept> | ||
|
||
#include "common.h" | ||
#include "report/report_type.h" | ||
#include "report/csv.h" | ||
#include "report/curses.h" | ||
|
||
namespace mckeys { | ||
|
||
using namespace std; | ||
|
||
// protected constructor | ||
ReportType::ReportType(const string &name) : name(name) | ||
{} | ||
|
||
// static values | ||
ReportType ReportType::CSV = ReportType("CSV"); | ||
ReportType ReportType::NCURSES = ReportType("CURSES"); | ||
|
||
// static methods | ||
ReportType ReportType::fromString(const string &name) { | ||
string reportName = ""; | ||
for (uint32_t i = 0; i < name.length(); i++) { | ||
reportName += toupper(name.at(i)); | ||
} | ||
if (reportName == "CURSES") { | ||
return ReportType::NCURSES; | ||
} else if (reportName == "CSV") { | ||
return ReportType::CSV; | ||
} else { | ||
throw range_error("No such report type with name " + name); | ||
} | ||
} | ||
|
||
// public methods | ||
string ReportType::getName() const { | ||
return name; | ||
} | ||
bool ReportType::operator==(const ReportType &other) const { | ||
return (getName() == other.getName()); | ||
} | ||
|
||
Report* ReportType::makeReport(const Config* cfg, const Pcap* sess, Stats* stats) { | ||
if (cfg->getReportType() == ReportType::NCURSES) { | ||
return new CursesReport(cfg, sess, stats); | ||
} else if (cfg->getReportType() == ReportType::CSV) { | ||
return new CsvReport(cfg, sess, stats); | ||
} else { | ||
throw range_error("Unsupported report type " + cfg->getReportType().getName()); | ||
} | ||
} | ||
|
||
} // end namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef _REPORT_REPORT_TYPE_H | ||
#define _REPORT_REPORT_TYPE_H | ||
|
||
#include <string> | ||
|
||
namespace mckeys { | ||
|
||
// forward declarations because shit we have some recursive dependencies | ||
class Config; | ||
class Pcap; | ||
class Stats; | ||
class Report; | ||
|
||
class ReportType | ||
{ | ||
public: | ||
static ReportType NCURSES; | ||
static ReportType CSV; | ||
|
||
static ReportType fromString(const std::string &name); | ||
|
||
Report* makeReport(const Config* cfg, const Pcap* sess, Stats* stats); | ||
std::string getName() const; | ||
|
||
bool operator==(const ReportType &other) const; | ||
|
||
protected: | ||
std::string name; | ||
ReportType(const std::string &name); | ||
|
||
}; | ||
|
||
} // end namespace | ||
|
||
#endif |