-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplayer.cpp
69 lines (55 loc) · 1.67 KB
/
replayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "parse_cfg.h"
#include "zmq.hpp"
#include <atomic>
#include <chrono>
#include <csignal>
#include <iostream>
#include <memory>
#include <thread>
#include "replayer.hpp"
std::atomic<bool> shutdown(false);
void signal_handler(int sig) {
shutdown.store(true);
}
void usage() {
printf("usage: zmq_replayer [options]\n");
printf("options:\n");
printf(" --file src file for replay, default zmq.bin\n");
printf(" --mode mode for replayer, [pub: default|req]\n");
}
void print_cfg(std::unordered_map<std::string, std::string>& args) {
printf("zmq zmq_replayer config:\n");
printf(" file: %s\n", args["file"].c_str());
printf(" mode: %s\n", args["mode"].c_str());
}
void reg_default_kv(std::unordered_map<std::string, std::string>& args, std::string k, std::string v) {
if (args.find(k) == args.end()) {
args[k] = v;
}
}
// Replayer Replayer;
int main(int argc, char** argv) {
std::shared_ptr<Replayer> replayer_ = std::make_shared<Replayer>();
signal(SIGINT, signal_handler);
std::unordered_map<std::string, std::string> args;
try {
args = parse_cfg(argc, argv);
reg_default_kv(args, "mode", "pub");
reg_default_kv(args, "file", "zmq.bin");
}
catch (std::invalid_argument& e) {
std::cerr << e.what() << "\n";
usage();
exit(0);
}
print_cfg(args);
// Perception result from zmq, to binary
replayer_->Init(args.at("file"), args.at("mode"));
replayer_->Run();
while (!shutdown.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
replayer_->Stop();
printf("Exiting gracefully...\n");
return 0;
}