1 #include "sdbusplus/asio/connection.hpp" 2 #include "sdbusplus/bus/match.hpp" 3 #include "server/Test2/common.hpp" 4 5 #include <print> 6 7 #include <gtest/gtest.h> 8 cb(sdbusplus::message_t & msg)9void cb(sdbusplus::message_t& msg) 10 { 11 // We can access the signal name as a symbol. 12 // The property name is constexpr. 13 14 constexpr auto sigName = 15 sdbusplus::common::server::Test2::signal_names::other_value_changed; 16 17 // The property name can be used as part of error logs. 18 19 std::println("signal {} received on path {}\n", sigName, msg.get_path()); 20 } 21 main()22int main() 23 { 24 // If the signal is removed from the interface definition, it will cause a 25 // build failure in applications still using that signal. That can work 26 // even if the application is not (yet) using PDI-generated bindings for 27 // it's DBus interactions. 28 29 std::println( 30 "using signal {} \n", 31 sdbusplus::common::server::Test2::signal_names::other_value_changed); 32 33 EXPECT_EQ( 34 sdbusplus::common::server::Test2::signal_names::other_value_changed, 35 "OtherValueChanged"); 36 37 boost::asio::io_context io; 38 sdbusplus::asio::connection conn(io); 39 40 std::string matchStr = std::format( 41 "type='signal',member={}", 42 sdbusplus::common::server::Test2::signal_names::other_value_changed); 43 44 auto match = sdbusplus::bus::match_t(conn, matchStr, cb); 45 46 return 0; 47 } 48