Skip to content

Commit 52bd236

Browse files
committed
reformat code
1 parent cb1f320 commit 52bd236

File tree

5 files changed

+103
-109
lines changed

5 files changed

+103
-109
lines changed

infinite_sense_core/include/infinite_sense.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Synchronizer {
6363
*
6464
* @param cam
6565
*/
66-
void UseCam(const std::shared_ptr<Sensor> &cam);
66+
void UseCam(const std::shared_ptr<Sensor>& cam);
6767

6868
/**
6969
* @brief 获取指定设备最近一次的触发时间(静态方法)。

infinite_sense_core/include/messenger.h

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
#include <unordered_map>
99
namespace infinite_sense {
1010
class Messenger {
11-
public:
12-
static Messenger &GetInstance() {
11+
public:
12+
static Messenger& GetInstance() {
1313
static Messenger instance;
1414
return instance;
1515
}
16-
Messenger(const Messenger &) = delete;
17-
Messenger(const Messenger &&) = delete;
18-
Messenger &operator=(const Messenger &) = delete;
16+
Messenger(const Messenger&) = delete;
17+
Messenger(const Messenger&&) = delete;
18+
Messenger& operator=(const Messenger&) = delete;
1919
std::string GetPubEndpoint() const;
20-
void Pub(const std::string &topic, const std::string &metadata);
21-
void PubStruct(const std::string &topic, const void *data, size_t size);
22-
private:
20+
void Pub(const std::string& topic, const std::string& metadata);
21+
void PubStruct(const std::string& topic, const void* data, size_t size);
22+
23+
private:
2324
Messenger();
2425
~Messenger();
2526
zmq::context_t context_{};
@@ -28,50 +29,50 @@ class Messenger {
2829
};
2930

3031
class TopicMonitor {
31-
public:
32-
static TopicMonitor& GetInstance() {
33-
static TopicMonitor instance;
34-
return instance;
35-
}
36-
TopicMonitor(const TopicMonitor&) = delete;
37-
TopicMonitor(TopicMonitor&&) = delete;
38-
TopicMonitor& operator=(const TopicMonitor&) = delete;
39-
TopicMonitor& operator=(TopicMonitor&&) = delete;
40-
std::unordered_set<std::string> GetTopics() const;
41-
friend std::ostream& operator<<(std::ostream& os, const TopicMonitor& monitor) {
42-
std::lock_guard lock(monitor.topics_mutex_);
43-
os << "\n--- Topic Monitor ---\n";
44-
if (monitor.topic_frequencies_.empty()) {
45-
os << " No active topics\n";
46-
} else {
47-
os << " Active Topics (" << monitor.topic_frequencies_.size() << "):\n";
48-
std::vector<std::pair<std::string, size_t>> sorted_topics(
49-
monitor.topic_frequencies_.begin(),
50-
monitor.topic_frequencies_.end());
51-
std::sort(sorted_topics.begin(), sorted_topics.end(),
52-
[](const auto& a, const auto& b) { return b.second < a.second; });
32+
public:
33+
static TopicMonitor& GetInstance() {
34+
static TopicMonitor instance;
35+
return instance;
36+
}
37+
TopicMonitor(const TopicMonitor&) = delete;
38+
TopicMonitor(TopicMonitor&&) = delete;
39+
TopicMonitor& operator=(const TopicMonitor&) = delete;
40+
TopicMonitor& operator=(TopicMonitor&&) = delete;
41+
std::unordered_set<std::string> GetTopics() const;
42+
friend std::ostream& operator<<(std::ostream& os, const TopicMonitor& monitor) {
43+
std::lock_guard lock(monitor.topics_mutex_);
44+
os << "\n--- Topic Monitor ---\n";
45+
if (monitor.topic_frequencies_.empty()) {
46+
os << " No active topics\n";
47+
} else {
48+
os << " Active Topics (" << monitor.topic_frequencies_.size() << "):\n";
49+
std::vector<std::pair<std::string, size_t>> sorted_topics(monitor.topic_frequencies_.begin(),
50+
monitor.topic_frequencies_.end());
51+
std::sort(sorted_topics.begin(), sorted_topics.end(),
52+
[](const auto& a, const auto& b) { return b.second < a.second; });
5353

54-
for (const auto& [topic, count] : sorted_topics) {
55-
os << "" << topic << " (num: " << count << ")\n";
56-
}
54+
for (const auto& [topic, count] : sorted_topics) {
55+
os << "" << topic << " (num: " << count << ")\n";
5756
}
58-
return os << "---------------------\n";
5957
}
60-
// 启动监控线程
61-
void Start();
62-
// 停止监控
63-
void Stop();
64-
private:
65-
TopicMonitor();
66-
~TopicMonitor();
67-
// 监控线程主循环
68-
void MonitorLoop() ;
69-
std::unordered_map<std::string, size_t> topic_frequencies_; // 新增:topic频率统计
70-
zmq::context_t context_;
71-
zmq::socket_t subscriber_;
72-
std::unordered_set<std::string> topics_;
73-
mutable std::mutex topics_mutex_;
74-
std::thread monitor_thread_;
75-
std::atomic<bool> should_run_;
58+
return os << "---------------------\n";
59+
}
60+
// 启动监控线程
61+
void Start();
62+
// 停止监控
63+
void Stop();
64+
65+
private:
66+
TopicMonitor();
67+
~TopicMonitor();
68+
// 监控线程主循环
69+
void MonitorLoop();
70+
std::unordered_map<std::string, size_t> topic_frequencies_; // 新增:topic频率统计
71+
zmq::context_t context_;
72+
zmq::socket_t subscriber_;
73+
std::unordered_set<std::string> topics_;
74+
mutable std::mutex topics_mutex_;
75+
std::thread monitor_thread_;
76+
std::atomic<bool> should_run_;
7677
};
77-
}
78+
} // namespace infinite_sense

infinite_sense_core/include/sensor.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <vector>
44
#include "messenger.h"
55
namespace infinite_sense {
6-
class Sensor{
7-
public:
6+
class Sensor {
7+
public:
88
Sensor();
99
explicit Sensor(const std::map<std::string, TriggerDevice>& params) : params_(params) {}
1010
virtual ~Sensor();
@@ -16,18 +16,19 @@ class Sensor{
1616
virtual void Stop();
1717
virtual void Start();
1818
virtual void Restart() {
19-
Stop();
20-
std::this_thread::sleep_for(std::chrono::milliseconds{500});
21-
if (!Initialization()) {
22-
LOG(INFO) << "Camera initialization failed after restart!";
23-
} else {
24-
Start();
25-
LOG(INFO) << "Cameras successfully restarted!";
26-
}
19+
Stop();
20+
std::this_thread::sleep_for(std::chrono::milliseconds{500});
21+
if (!Initialization()) {
22+
LOG(INFO) << "Camera initialization failed after restart!";
23+
} else {
24+
Start();
25+
LOG(INFO) << "Cameras successfully restarted!";
26+
}
2727
}
2828
void Enable() { is_running_ = true; }
2929
void Disable() { is_running_ = false; }
30-
private:
30+
31+
private:
3132
virtual void Receive(void* handle, const std::string&);
3233
bool is_running_{false};
3334
std::vector<std::thread> cam_threads_{};

infinite_sense_core/src/infinite_sense.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
namespace infinite_sense {
1010
Synchronizer::Synchronizer() {
11-
LOG(INFO) << "\n"
12-
<< " ▗▄▄▄▖▗▖ ▗▖▗▄▄▄▖▗▄▄▄▖▗▖ ▗▖▗▄▄▄▖▗▄▄▄▖▗▄▄▄▖ ▗▄▄▖▗▄▄▄▖▗▖ ▗▖ ▗▄▄▖▗▄▄▄▖" << "\n"
13-
<< " █ ▐▛▚▖▐▌▐▌ █ ▐▛▚▖▐▌ █ █ ▐▌ ▐▌ ▐▌ ▐▛▚▖▐▌▐▌ ▐▌ " << "\n"
14-
<< " █ ▐▌ ▝▜▌▐▛▀▀▘ █ ▐▌ ▝▜▌ █ █ ▐▛▀▀▘ ▝▀▚▖▐▛▀▀▘▐▌ ▝▜▌ ▝▀▚▖▐▛▀▀▘" << "\n"
15-
<< " ▗▄█▄▖▐▌ ▐▌▐▌ ▗▄█▄▖▐▌ ▐▌▗▄█▄▖ █ ▐▙▄▄▖▗▄▄▞▘▐▙▄▄▖▐▌ ▐▌▗▄▄▞▘▐▙▄▄▖";
11+
LOG(INFO) << "\n"
12+
<< " ▗▄▄▄▖▗▖ ▗▖▗▄▄▄▖▗▄▄▄▖▗▖ ▗▖▗▄▄▄▖▗▄▄▄▖▗▄▄▄▖ ▗▄▄▖▗▄▄▄▖▗▖ ▗▖ ▗▄▄▖▗▄▄▄▖" << "\n"
13+
<< " █ ▐▛▚▖▐▌▐▌ █ ▐▛▚▖▐▌ █ █ ▐▌ ▐▌ ▐▌ ▐▛▚▖▐▌▐▌ ▐▌ " << "\n"
14+
<< " █ ▐▌ ▝▜▌▐▛▀▀▘ █ ▐▌ ▝▜▌ █ █ ▐▛▀▀▘ ▝▀▚▖▐▛▀▀▘▐▌ ▝▜▌ ▝▀▚▖▐▛▀▀▘" << "\n"
15+
<< " ▗▄█▄▖▐▌ ▐▌▐▌ ▗▄█▄▖▐▌ ▐▌▗▄█▄▖ █ ▐▙▄▄▖▗▄▄▞▘▐▙▄▄▖▐▌ ▐▌▗▄▄▞▘▐▙▄▄▖";
1616
};
1717
void Synchronizer::SetLogPath(const std::string& path) { SetLogDestination(FATAL, path.c_str()); }
1818
void Synchronizer::SetNetLink(std::string net_dev, const unsigned int port) {
@@ -26,11 +26,9 @@ void Synchronizer::SetUsbLink(std::string serial_dev, const int serial_baud_rate
2626
serial_manager_ = std::make_shared<UsbManager>(serial_dev_, serial_baud_rate_);
2727
net_manager_ = nullptr;
2828
}
29-
void Synchronizer::UseCam(const std::shared_ptr<Sensor> &cam) {
30-
cam_manager_ = cam;
31-
}
29+
void Synchronizer::UseCam(const std::shared_ptr<Sensor>& cam) { cam_manager_ = cam; }
3230
bool Synchronizer::GetLastTriggerTime(const TriggerDevice dev, uint64_t time) {
33-
return GET_LAST_TRIGGER_STATUS(dev,time);
31+
return GET_LAST_TRIGGER_STATUS(dev, time);
3432
}
3533
void Synchronizer::Start() const {
3634
if (net_manager_) {

infinite_sense_core/src/messenger.cpp

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,56 +46,51 @@ void Messenger::PubStruct(const std::string &topic, const void *data, const size
4646
LOG(ERROR) << "Exception: " << e.what();
4747
}
4848
}
49-
std::string Messenger::GetPubEndpoint() const {
50-
return endpoint_;
51-
}
49+
std::string Messenger::GetPubEndpoint() const { return endpoint_; }
5250

5351
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5452

5553
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5654
std::unordered_set<std::string> TopicMonitor::GetTopics() const {
57-
std::lock_guard lock(topics_mutex_);
58-
return topics_; // 返回副本保证线程安全
55+
std::lock_guard lock(topics_mutex_);
56+
return topics_; // 返回副本保证线程安全
5957
}
6058
// 启动监控线程
6159
void TopicMonitor::Start() {
62-
if (monitor_thread_.joinable()) {
63-
return;
64-
}
65-
should_run_.store(true);
66-
monitor_thread_ = std::thread(&TopicMonitor::MonitorLoop, this);
60+
if (monitor_thread_.joinable()) {
61+
return;
62+
}
63+
should_run_.store(true);
64+
monitor_thread_ = std::thread(&TopicMonitor::MonitorLoop, this);
6765
}
6866

6967
// 停止监控
7068
void TopicMonitor::Stop() {
71-
if (!should_run_.load()) {
72-
return;
73-
}
74-
should_run_.store(false);
75-
if (monitor_thread_.joinable()) {
76-
monitor_thread_.join();
77-
}
69+
if (!should_run_.load()) {
70+
return;
71+
}
72+
should_run_.store(false);
73+
if (monitor_thread_.joinable()) {
74+
monitor_thread_.join();
75+
}
7876
}
79-
TopicMonitor::TopicMonitor()
80-
: context_(1),
81-
subscriber_(context_, ZMQ_SUB),
82-
should_run_(false) {
83-
try {
84-
subscriber_.connect(Messenger::GetInstance().GetPubEndpoint());
85-
subscriber_.set(zmq::sockopt::subscribe, "");
86-
} catch (const zmq::error_t& e) {
87-
LOG(ERROR) << "[TopicMonitor] Initialization failed: " << e.what();
88-
throw;
89-
}
77+
TopicMonitor::TopicMonitor() : context_(1), subscriber_(context_, ZMQ_SUB), should_run_(false) {
78+
try {
79+
subscriber_.connect(Messenger::GetInstance().GetPubEndpoint());
80+
subscriber_.set(zmq::sockopt::subscribe, "");
81+
} catch (const zmq::error_t &e) {
82+
LOG(ERROR) << "[TopicMonitor] Initialization failed: " << e.what();
83+
throw;
84+
}
9085
}
9186
TopicMonitor::~TopicMonitor() {
92-
Stop();
93-
try {
94-
subscriber_.close();
95-
context_.close();
96-
} catch (const zmq::error_t& e) {
97-
LOG(ERROR) << "[TopicMonitor] Cleanup error: " << e.what();
98-
}
87+
Stop();
88+
try {
89+
subscriber_.close();
90+
context_.close();
91+
} catch (const zmq::error_t &e) {
92+
LOG(ERROR) << "[TopicMonitor] Cleanup error: " << e.what();
93+
}
9994
}
10095
// 监控线程主循环
10196
void TopicMonitor::MonitorLoop() {
@@ -115,12 +110,11 @@ void TopicMonitor::MonitorLoop() {
115110
subscriber_.recv(dummy);
116111
}
117112
}
118-
} catch (const zmq::error_t& e) {
113+
} catch (const zmq::error_t &e) {
119114
if (e.num() != ETERM) {
120115
}
121116
}
122117
}
123118
}
124119

125-
126120
} // namespace infinite_sense

0 commit comments

Comments
 (0)