Skip to content

Commit 23a0051

Browse files
committed
fdsdump: use iemgr singleton
1 parent a46229b commit 23a0051

23 files changed

+75
-102
lines changed

src/tools/fdsdump/src/aggregator/mode.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <vector>
33

44
#include <common/flowProvider.hpp>
5+
#include <common/ieMgr.hpp>
56

67
#include <aggregator/aggregator.hpp>
78
#include <aggregator/mode.hpp>
@@ -13,19 +14,19 @@ namespace fdsdump {
1314
namespace aggregator {
1415

1516
void
16-
mode_aggregate(const shared_iemgr &iemgr, const Options &opts)
17+
mode_aggregate(const Options &opts)
1718
{
1819
ViewDefinition view_def = make_view_def(
1920
opts.get_aggregation_keys(),
2021
opts.get_aggregation_values(),
21-
iemgr.get());
22+
IEMgr::instance().ptr());
2223
std::vector<SortField> sort_fields = make_sort_def(
2324
view_def,
2425
opts.get_order_by());
2526
std::unique_ptr<Printer> printer = printer_factory(
2627
view_def,
2728
opts.get_output_specifier());
28-
FlowProvider flows {iemgr};
29+
FlowProvider flows;
2930
Aggregator aggr(view_def);
3031

3132
const size_t rec_limit = opts.get_output_limit();

src/tools/fdsdump/src/aggregator/mode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace fdsdump {
77
namespace aggregator {
88

99
void
10-
mode_aggregate(const shared_iemgr &iemgr, const Options &opts);
10+
mode_aggregate(const Options &opts);
1111

1212
} // aggregator
1313
} // fdsdump

src/tools/fdsdump/src/common/field.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
#include <stdexcept>
44

55
#include <common/field.hpp>
6+
#include <common/ieMgr.hpp>
67

78
namespace fdsdump {
89

9-
Field::Field(std::string name, const shared_iemgr &iemgr)
10-
: m_name(name), m_iemgr(iemgr)
10+
Field::Field(std::string name)
11+
: m_name(name)
1112
{
1213
string_trim(m_name);
1314

14-
m_alias = fds_iemgr_alias_find(m_iemgr.get(), m_name.c_str());
15+
auto *iemgr = IEMgr::instance().ptr();
16+
17+
m_alias = fds_iemgr_alias_find(iemgr, m_name.c_str());
1518
if (m_alias) {
1619
// Success
1720
m_type = get_type_of_alias(m_alias);
1821
return;
1922
}
2023

21-
m_elem = fds_iemgr_elem_find_name(m_iemgr.get(), m_name.c_str());
24+
m_elem = fds_iemgr_elem_find_name(iemgr, m_name.c_str());
2225
if (m_elem) {
2326
// Success
2427
m_type = get_type_of_element(m_elem);

src/tools/fdsdump/src/common/field.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ struct Field {
3939
* @brief Create a new getter for an alias or an IPFIX Field.
4040
*
4141
* @param name Name of alias or an IPFIX Element to lookup
42-
* @param iemgr IE manager where to look for the field
4342
* @throw std::invalid_argument If the alias or element cannot be found.
4443
*/
45-
Field(std::string name, const shared_iemgr &iemgr);
44+
Field(std::string name);
4645
~Field() = default;
4746

4847
/**
@@ -93,8 +92,6 @@ struct Field {
9392
private:
9493
// Name of the field (trimmed)
9594
std::string m_name;
96-
// Reference to the IE manager
97-
shared_iemgr m_iemgr;
9895
// Data type of the the field
9996
FieldType m_type;
10097
// Alias definition (might be nullptr)

src/tools/fdsdump/src/common/flowProvider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include <common/fieldView.hpp>
77
#include <common/flowProvider.hpp>
8+
#include <common/ieMgr.hpp>
89

910
namespace fdsdump {
1011

11-
FlowProvider::FlowProvider(const shared_iemgr &iemgr)
12-
: m_iemgr(iemgr)
12+
FlowProvider::FlowProvider()
1313
{
1414
int ret;
1515

@@ -18,7 +18,7 @@ FlowProvider::FlowProvider(const shared_iemgr &iemgr)
1818
throw std::runtime_error("fds_file_init() has failed");
1919
}
2020

21-
ret = fds_file_set_iemgr(m_file.get(), m_iemgr.get());
21+
ret = fds_file_set_iemgr(m_file.get(), IEMgr::instance().ptr());
2222
if (ret != FDS_OK) {
2323
throw std::runtime_error("fds_file_set_iemgr() has failed: " + std::to_string(ret));
2424
}
@@ -36,7 +36,7 @@ FlowProvider::set_filter(const std::string &expr)
3636
fds_ipfix_filter_t *filter;
3737
int ret;
3838

39-
ret = fds_ipfix_filter_create(&filter, m_iemgr.get(), expr.c_str());
39+
ret = fds_ipfix_filter_create(&filter, IEMgr::instance().ptr(), expr.c_str());
4040
m_filter.reset(filter);
4141

4242
if (ret != FDS_OK) {

src/tools/fdsdump/src/common/flowProvider.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace fdsdump {
1414

1515
class FlowProvider {
1616
public:
17-
FlowProvider(const shared_iemgr &iemgr);
17+
FlowProvider();
1818
~FlowProvider() = default;
1919

2020
FlowProvider(const FlowProvider &) = delete;
@@ -65,7 +65,6 @@ class FlowProvider {
6565

6666
std::list<std::string> m_remains;
6767

68-
shared_iemgr m_iemgr;
6968
unique_filter m_filter {nullptr, &fds_ipfix_filter_destroy};
7069
unique_file m_file {nullptr, &fds_file_close};
7170
bool m_file_ready = false;

src/tools/fdsdump/src/lister/csvPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace fdsdump {
1212
namespace lister {
1313

14-
CsvPrinter::CsvPrinter(const shared_iemgr &iemgr, const std::string &args)
14+
CsvPrinter::CsvPrinter(const std::string &args)
1515
{
1616
std::string args_fields;
1717
std::string args_opts;
@@ -23,7 +23,7 @@ CsvPrinter::CsvPrinter(const shared_iemgr &iemgr, const std::string &args)
2323
? args.substr(delim_pos + 1, std::string::npos)
2424
: "";
2525

26-
parse_fields(args_fields, iemgr);
26+
parse_fields(args_fields);
2727
parse_opts(args_opts);
2828

2929
m_buffer.reserve(1024);
@@ -34,7 +34,7 @@ CsvPrinter::~CsvPrinter()
3434
}
3535

3636
void
37-
CsvPrinter::parse_fields(const std::string &str, const shared_iemgr &iemgr)
37+
CsvPrinter::parse_fields(const std::string &str)
3838
{
3939
std::vector<std::string> field_names;
4040

@@ -45,7 +45,7 @@ CsvPrinter::parse_fields(const std::string &str, const shared_iemgr &iemgr)
4545
field_names = string_split(str, ",");
4646

4747
for (const std::string &name : field_names) {
48-
m_fields.emplace_back(Field {name, iemgr}, name);
48+
m_fields.emplace_back(Field {name}, name);
4949
}
5050
}
5151

src/tools/fdsdump/src/lister/csvPrinter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace lister {
1111

1212
class CsvPrinter : public Printer {
1313
public:
14-
CsvPrinter(const shared_iemgr &iemgr, const std::string &args);
14+
CsvPrinter(const std::string &args);
1515

1616
virtual
1717
~CsvPrinter();
@@ -34,7 +34,7 @@ class CsvPrinter : public Printer {
3434
: m_field(field), m_name(name) {}
3535
};
3636

37-
void parse_fields(const std::string &str, const shared_iemgr &iemgr);
37+
void parse_fields(const std::string &str);
3838
void parse_opts(const std::string &str);
3939

4040
void print_record(struct fds_drec *rec, bool reverse);

src/tools/fdsdump/src/lister/jsonPrinter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include <string>
66

77
#include <common/common.hpp>
8+
#include <common/ieMgr.hpp>
89

910
#include <lister/jsonPrinter.hpp>
1011

1112
namespace fdsdump {
1213
namespace lister {
1314

14-
JsonPrinter::JsonPrinter(const shared_iemgr &iemgr, const std::string &args)
15+
JsonPrinter::JsonPrinter(const std::string &args)
1516
{
1617
std::string args_fields;
1718
std::string args_opts;
@@ -23,7 +24,7 @@ JsonPrinter::JsonPrinter(const shared_iemgr &iemgr, const std::string &args)
2324
? args.substr(delim_pos + 1, std::string::npos)
2425
: "";
2526

26-
parse_fields(args_fields, iemgr);
27+
parse_fields(args_fields);
2728
parse_opts(args_opts);
2829

2930
m_buffer.reserve(1024);
@@ -34,7 +35,7 @@ JsonPrinter::~JsonPrinter()
3435
}
3536

3637
void
37-
JsonPrinter::parse_fields(const std::string &str, const shared_iemgr &iemgr)
38+
JsonPrinter::parse_fields(const std::string &str)
3839
{
3940
std::vector<std::string> field_names;
4041

@@ -45,7 +46,7 @@ JsonPrinter::parse_fields(const std::string &str, const shared_iemgr &iemgr)
4546
field_names = string_split(str, ",");
4647

4748
for (const std::string &name : field_names) {
48-
m_fields.emplace_back(name, iemgr);
49+
m_fields.emplace_back(name);
4950
}
5051
}
5152

src/tools/fdsdump/src/lister/jsonPrinter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace lister {
1212

1313
class JsonPrinter : public Printer {
1414
public:
15-
JsonPrinter(const shared_iemgr &iemgr, const std::string &args);
15+
JsonPrinter(const std::string &args);
1616

1717
virtual
1818
~JsonPrinter();
@@ -27,7 +27,7 @@ class JsonPrinter : public Printer {
2727
print_epilogue() override;
2828

2929
private:
30-
void parse_fields(const std::string &str, const shared_iemgr &iemgr);
30+
void parse_fields(const std::string &str);
3131
void parse_opts(const std::string &str);
3232

3333
void print_record(struct fds_drec *rec, bool reverse);

0 commit comments

Comments
 (0)