1 #pragma once 2 3 #include <nlohmann/json.hpp> 4 #include <sdbusplus/exception.hpp> 5 6 #include <source_location> 7 8 namespace sdbusplus::sdbuspp 9 { 10 11 using register_hook = 12 std::function<void(const nlohmann::json&, const std::source_location&)>; 13 14 void register_event(const std::string&, register_hook); 15 16 template <typename T> 17 struct register_event_helper 18 { hooksdbusplus::sdbuspp::register_event_helper19 static void hook() 20 { 21 register_event(T::errName, throw_event); 22 } 23 throw_eventsdbusplus::sdbuspp::register_event_helper24 static void throw_event(const nlohmann::json& j, 25 const std::source_location& location) 26 { 27 throw T(j, location); 28 } 29 }; 30 } // namespace sdbusplus::sdbuspp 31