diff options
author | Eddy Pedroni <epedroni@pm.me> | 2025-08-21 14:24:55 +0200 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2025-08-21 14:24:55 +0200 |
commit | 7f1179f01ed200240856e35038da0993f84ec312 (patch) | |
tree | 1a9ea6442c70183f2df06198ceab90a5f71b520e /daemon | |
parent | ce3b2eb271aa68fef345701188fc9f77abee99c8 (diff) |
More robust config parsing
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/Makefile | 5 | ||||
-rw-r--r-- | daemon/src/config.cpp | 31 | ||||
-rw-r--r-- | daemon/src/connection_manager.cpp | 11 | ||||
-rw-r--r-- | daemon/src/connection_manager.h | 4 |
4 files changed, 42 insertions, 9 deletions
diff --git a/daemon/Makefile b/daemon/Makefile index 9bda3d2..3230ca2 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -37,10 +37,13 @@ $(BUILD_DIR)/%.cpp.o: %.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ -.PHONY: clean +.PHONY: clean run clean: rm -r $(BUILD_DIR) +run: $(BUILD_DIR)/$(TARGET_EXEC) + $(BUILD_DIR)/$(TARGET_EXEC) + # Include the .d makefiles. The - at the front suppresses the errors of missing # Makefiles. Initially, all the .d files will be missing, and we don't want those # errors to show up. diff --git a/daemon/src/config.cpp b/daemon/src/config.cpp index b88fd0f..b711d52 100644 --- a/daemon/src/config.cpp +++ b/daemon/src/config.cpp @@ -87,13 +87,24 @@ add_to_routes(Device_Id const & from_device, Route_Table & rt, toml::table & rou { for (auto&& [name, mt] : string2type) { - rt[from_device][mt].push_back(cm.get_sender(to_device)); + if (auto sender = cm.get_sender(to_device)) + { + rt[from_device][mt].push_back(sender.value()); + } } } else { - Message_Type mt = string2type.at(type.as_string()->get()); - rt[from_device][mt].push_back(cm.get_sender(to_device)); + if (!string2type.contains(type.as_string()->get())) + { + continue; + } + + if (auto sender = cm.get_sender(to_device)) + { + Message_Type const mt = string2type.at(type.as_string()->get()); + rt[from_device][mt].push_back(sender.value()); + } } } } @@ -113,6 +124,10 @@ add_type_routes(Device_Map const & device_map, Device_Id const & from_device, Ro } for (auto & device : *devices) { + if (!string2type.contains(type)) + { + continue; + } Message_Type mt = string2type.at(type); std::string to_device = device.as_string()->get(); if (to_device == "all") @@ -120,12 +135,18 @@ add_type_routes(Device_Map const & device_map, Device_Id const & from_device, Ro for (auto&& [name, id] : device_map) { if (id == from_device) continue; - rt[from_device][mt].push_back(cm.get_sender(id)); + if (auto sender = cm.get_sender(id)) + { + rt[from_device][mt].push_back(sender.value()); + } } } else { - rt[from_device][mt].push_back(cm.get_sender(to_device)); + if (auto sender = cm.get_sender(to_device)) + { + rt[from_device][mt].push_back(sender.value()); + } } } } diff --git a/daemon/src/connection_manager.cpp b/daemon/src/connection_manager.cpp index 7467e4e..c3d260e 100644 --- a/daemon/src/connection_manager.cpp +++ b/daemon/src/connection_manager.cpp @@ -43,10 +43,17 @@ Connection_Manager::Connection_Manager(Device_Map const & device_map, Submitter Connection_Manager::~Connection_Manager() = default; -Sender & +std::optional<std::reference_wrapper<Sender>> Connection_Manager::get_sender(Device_Id const & device) const { - return *m_connections.at(device); + if (m_connections.contains(device)) + { + return *m_connections.at(device); + } + else + { + return std::nullopt; + } } void diff --git a/daemon/src/connection_manager.h b/daemon/src/connection_manager.h index d8b0e90..2711d34 100644 --- a/daemon/src/connection_manager.h +++ b/daemon/src/connection_manager.h @@ -8,6 +8,8 @@ #include <memory> #include <map> #include <thread> +#include <optional> +#include <functional> namespace midi_router { @@ -21,7 +23,7 @@ public: ~Connection_Manager(); - Sender & + std::optional<std::reference_wrapper<Sender>> get_sender(Device_Id const & device) const; private: |