1 // Part of Measurement Kit <https://measurement-kit.github.io/>.
2 // Measurement Kit is free software under the BSD license. See AUTHORS
3 // and LICENSE for more information on the copying conditions.
4
5 #include "src/libmeasurement_kit/common/fmap.hpp"
6 #include "src/libmeasurement_kit/common/parallel.hpp"
7
8 #include "src/libmeasurement_kit/common/utils.hpp"
9
10 #include "src/libmeasurement_kit/report/base_reporter.hpp"
11 #include "src/libmeasurement_kit/report/error.hpp"
12 #include "src/libmeasurement_kit/report/report_legacy.hpp"
13
14 namespace mk {
15 namespace report {
16
ReportLegacy()17 ReportLegacy::ReportLegacy() {}
18
add_reporter(SharedPtr<BaseReporter> reporter)19 void ReportLegacy::add_reporter(SharedPtr<BaseReporter> reporter) {
20 reporters_.push_back(reporter);
21 }
22
fill_entry(nlohmann::json & entry) const23 void ReportLegacy::fill_entry(nlohmann::json &entry) const {
24 entry["test_name"] = test_name;
25 entry["test_version"] = test_version;
26 entry["test_start_time"] = *mk::timestamp(&test_start_time);
27 // header["options"] = options;
28 entry["probe_ip"] = probe_ip;
29 entry["probe_asn"] = probe_asn;
30 entry["probe_cc"] = probe_cc;
31 entry["software_name"] = options.get("software_name", software_name);
32 entry["software_version"] =
33 options.get("software_version", software_version);
34 entry["data_format_version"] = data_format_version;
35 entry["annotations"]["platform"] =
36 options.get("platform", std::string{mk_platform()});
37 entry["annotations"]["engine_name"] = "libmeasurement_kit";
38 entry["annotations"]["engine_version"] = MK_VERSION;
39 entry["annotations"]["engine_version_full"] = MK_VERSION_FULL;
40 entry["report_id"] = report_id;
41 }
42
get_dummy_entry() const43 nlohmann::json ReportLegacy::get_dummy_entry() const {
44 nlohmann::json entry;
45 fill_entry(entry);
46 return entry;
47 }
48
49 #define FMAP mk::fmap<SharedPtr<BaseReporter>, Continuation<Error>>
50
open(Callback<Error> callback)51 void ReportLegacy::open(Callback<Error> callback) {
52 mk::parallel(FMAP(reporters_, [=](SharedPtr<BaseReporter> r) {
53 return r->open(*this);
54 }), callback);
55 }
56
write_entry(nlohmann::json entry,Callback<Error> callback,SharedPtr<Logger>)57 void ReportLegacy::write_entry(nlohmann::json entry, Callback<Error> callback,
58 SharedPtr<Logger>) {
59 mk::parallel(FMAP(reporters_, [=](SharedPtr<BaseReporter> r) {
60 return r->write_entry(entry);
61 }), callback);
62 }
63
close(Callback<Error> callback)64 void ReportLegacy::close(Callback<Error> callback) {
65 mk::parallel(FMAP(reporters_, [](SharedPtr<BaseReporter> r) {
66 return r->close();
67 }), callback);
68 }
69
70 #undef FMAP // So long, and thanks for the fish
71
72 } // namespace report
73 } // namespace mk
74