Alexander Hansen | a0fe02c | 2025-03-10 18:26:56 +0100 | [diff] [blame] | 1 | #include "server/Test/aserver.hpp" |
| 2 | #include "server/Test/client.hpp" |
| 3 | #include "server/Test2/aserver.hpp" |
| 4 | #include "server/Test2/client.hpp" |
| 5 | #include "server/Test3/aserver.hpp" |
| 6 | |
| 7 | #include <sdbusplus/async/context.hpp> |
| 8 | #include <sdbusplus/async/match.hpp> |
| 9 | #include <sdbusplus/async/timer.hpp> |
| 10 | |
| 11 | class A |
| 12 | {}; |
| 13 | |
| 14 | auto constructInterfaces(sdbusplus::async::context& ctx, std::string& busName) |
| 15 | -> sdbusplus::async::task<> |
| 16 | { |
| 17 | auto x = std::variant<sdbusplus::common::server::Test::EnumOne, std::string, |
| 18 | sdbusplus::common::server::Test::EnumTwo>( |
| 19 | sdbusplus::common::server::Test::EnumOne::OneA); |
| 20 | |
| 21 | sdbusplus::common::server::Test::properties_t props{ |
| 22 | 832, 0, 0, 0, 0, 0, 0, std::string("/my/path"), 1.0, 1.0, 1.0, 1.0, x}; |
| 23 | |
| 24 | sdbusplus::common::server::Test2::properties_t props2{4200, 2}; |
| 25 | |
| 26 | sdbusplus::aserver::server::Test<A> a0(ctx, "/0"); |
| 27 | |
| 28 | sdbusplus::aserver::server::Test<A> a1(ctx, "/1", props); |
| 29 | |
| 30 | // construct without properties |
| 31 | sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test> a2( |
| 32 | ctx, "/2"); |
| 33 | |
| 34 | // construct Test with properties |
| 35 | auto a3 = std::make_unique< |
| 36 | sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test>>( |
| 37 | ctx, "/3", props); |
| 38 | |
| 39 | // construct Test2 with properties |
| 40 | sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test2> a4( |
| 41 | ctx, "/4", props2); |
| 42 | |
| 43 | // does not compile, (wronge type of properties!) |
| 44 | // sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test2> ax(ctx, |
| 45 | // "/x", props); |
| 46 | |
| 47 | // construct with both interfaces, no properties |
| 48 | sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test, |
| 49 | sdbusplus::aserver::server::Test2> |
| 50 | a5(ctx, "/5"); |
| 51 | |
| 52 | // construct with both interfaces and properties |
| 53 | auto a6 = std::make_unique< |
| 54 | sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test, |
| 55 | sdbusplus::aserver::server::Test2>>( |
| 56 | ctx, "/6", props, props2); |
| 57 | |
| 58 | // does not compile, (wrong order of properties!) |
| 59 | // auto a7 = std::make_unique< |
| 60 | // sdbusplus::async::server_t<A, sdbusplus::aserver::server::Test, |
| 61 | // sdbusplus::aserver::server::Test2>>( |
| 62 | // ctx, "/7", props2, props); |
| 63 | |
| 64 | auto a8 = std::make_unique<sdbusplus::async::server_t< |
| 65 | A, sdbusplus::aserver::server::Test, sdbusplus::aserver::server::Test2, |
| 66 | sdbusplus::aserver::server::Test3>>(ctx, "/8", props, props2, |
| 67 | std::nullopt); |
| 68 | |
| 69 | auto client = |
| 70 | sdbusplus::client::server::Test(ctx).service(busName).path("/3"); |
| 71 | |
| 72 | assert(co_await client.some_value() == 832); |
| 73 | |
| 74 | auto client2 = |
| 75 | sdbusplus::client::server::Test2(ctx).service(busName).path("/6"); |
| 76 | |
| 77 | assert(co_await client2.new_value() == 4200); |
| 78 | |
| 79 | ctx.request_stop(); |
| 80 | |
| 81 | co_return; |
| 82 | } |
| 83 | |
| 84 | int main() |
| 85 | { |
| 86 | sdbusplus::async::context ctx; |
| 87 | |
| 88 | std::srand(std::chrono::system_clock::now().time_since_epoch().count()); |
| 89 | std::string busName = "xyz.openbmc_project.TestingMultipleInterfaces" + |
| 90 | std::to_string(rand()); |
| 91 | |
| 92 | ctx.request_name(busName.c_str()); |
| 93 | |
| 94 | sdbusplus::server::manager_t manager(ctx.get_bus(), "/test"); |
| 95 | |
| 96 | ctx.spawn(constructInterfaces(ctx, busName)); |
| 97 | |
| 98 | ctx.run(); |
| 99 | |
| 100 | return 0; |
| 101 | } |