From 6ec0a751d2e65f80863d0bc20ceb7692e08e1df6 Mon Sep 17 00:00:00 2001 From: Curve Date: Wed, 24 Jan 2024 21:31:14 +0100 Subject: [PATCH] feat(proxy): add props --- CMakeLists.txt | 2 +- include/rohrkabel/proxy.hpp | 4 +++- src/proxy.cpp | 29 ++++++++++++++++++----------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 903f6ad..78fa63a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.21) -project(rohrkabel LANGUAGES CXX VERSION 2.7) +project(rohrkabel LANGUAGES CXX VERSION 3.0) # -------------------------------------------------------------------------------------------------------- # Library options diff --git a/include/rohrkabel/proxy.hpp b/include/rohrkabel/proxy.hpp index 8615369..762b2fd 100644 --- a/include/rohrkabel/proxy.hpp +++ b/include/rohrkabel/proxy.hpp @@ -1,4 +1,5 @@ #pragma once +#include "spa/dict.hpp" #include "utils/lazy.hpp" #include @@ -20,13 +21,14 @@ namespace pipewire virtual ~proxy(); public: - proxy(pw_proxy *); proxy(proxy &&) noexcept; + proxy(pw_proxy *, spa::dict); public: proxy &operator=(proxy &&) noexcept; public: + [[nodiscard]] spa::dict props() const; [[nodiscard]] std::string type() const; [[nodiscard]] std::uint32_t id() const; [[nodiscard]] std::uint32_t version() const; diff --git a/src/proxy.cpp b/src/proxy.cpp index 4c212e2..0821333 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -15,24 +15,31 @@ namespace pipewire struct proxy::impl { + spa::dict props; std::unique_ptr proxy; }; proxy::~proxy() = default; - proxy::proxy(pw_proxy *proxy) : m_impl(std::make_unique()) + proxy::proxy(proxy &&other) noexcept : m_impl(std::move(other.m_impl)) {} + + proxy::proxy(pw_proxy *proxy, spa::dict props) : m_impl(std::make_unique()) { m_impl->proxy.reset(proxy); + m_impl->props = std::move(props); } - proxy::proxy(proxy &&other) noexcept : m_impl(std::move(other.m_impl)) {} - proxy &proxy::operator=(proxy &&other) noexcept { m_impl = std::move(other.m_impl); return *this; } + spa::dict proxy::props() const + { + return m_impl->props; + } + std::string proxy::type() const { return pw_proxy_get_type(m_impl->proxy.get(), nullptr); @@ -67,22 +74,22 @@ namespace pipewire { listener hook; pw_proxy_events events; - std::promise> done; + std::promise> props; }; auto m_state = std::make_shared(); m_state->events.version = PW_VERSION_PROXY_EVENTS; - m_state->events.bound = [](void *data, uint32_t) + m_state->events.bound_props = [](void *data, uint32_t, const spa_dict *props) { auto &m_state = *reinterpret_cast(data); - m_state.done.set_value({}); + m_state.props.set_value(props); }; m_state->events.error = [](void *data, int seq, int res, const char *message) { auto &m_state = *reinterpret_cast(data); - m_state.done.set_value(tl::make_unexpected({seq, res, message})); + m_state.props.set_value(tl::make_unexpected({seq, res, message})); }; pw_proxy_add_listener(raw, m_state->hook.get(), &m_state->events, m_state.get()); @@ -90,14 +97,14 @@ namespace pipewire return make_lazy>( [m_state, raw]() -> expected { - auto res = m_state->done.get_future().get(); + auto props = m_state->props.get_future().get(); - if (!res.has_value()) + if (!props.has_value()) { - return tl::make_unexpected(res.error()); + return tl::make_unexpected(props.error()); } - return raw; + return proxy{raw, std::move(props.value())}; }); } } // namespace pipewire