28 lines
638 B
C++
28 lines
638 B
C++
#include "MockDDS.h"
|
|
#include <map>
|
|
#include <mutex>
|
|
|
|
namespace MockDDS {
|
|
|
|
static std::map<std::string, std::string> g_last_message;
|
|
static std::mutex g_mtx;
|
|
|
|
void publish(const std::string &topic, const std::string &msg) {
|
|
std::lock_guard<std::mutex> lk(g_mtx);
|
|
g_last_message[topic] = msg;
|
|
}
|
|
|
|
std::string take_last(const std::string &topic) {
|
|
std::lock_guard<std::mutex> lk(g_mtx);
|
|
auto it = g_last_message.find(topic);
|
|
if (it == g_last_message.end()) return std::string();
|
|
return it->second;
|
|
}
|
|
|
|
void clear_all() {
|
|
std::lock_guard<std::mutex> lk(g_mtx);
|
|
g_last_message.clear();
|
|
}
|
|
|
|
} // namespace MockDDS
|