Skip to content

Commit

Permalink
feat(proxy): add props
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Jan 24, 2024
1 parent d1a34b4 commit 6ec0a75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion include/rohrkabel/proxy.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "spa/dict.hpp"
#include "utils/lazy.hpp"

#include <string>
Expand All @@ -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;
Expand Down
29 changes: 18 additions & 11 deletions src/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ namespace pipewire

struct proxy::impl
{
spa::dict props;
std::unique_ptr<pw_proxy, deleter> proxy;
};

proxy::~proxy() = default;

proxy::proxy(pw_proxy *proxy) : m_impl(std::make_unique<impl>())
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<impl>())
{
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);
Expand Down Expand Up @@ -67,37 +74,37 @@ namespace pipewire
{
listener hook;
pw_proxy_events events;
std::promise<expected<void>> done;
std::promise<expected<spa::dict>> props;
};

auto m_state = std::make_shared<state>();
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<state *>(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<state *>(data);
m_state.done.set_value(tl::make_unexpected<error>({seq, res, message}));
m_state.props.set_value(tl::make_unexpected<error>({seq, res, message}));
};

pw_proxy_add_listener(raw, m_state->hook.get(), &m_state->events, m_state.get());

return make_lazy<expected<proxy>>(
[m_state, raw]() -> expected<proxy>
{
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

0 comments on commit 6ec0a75

Please sign in to comment.