Skip to content

Commit

Permalink
refactor: object binding / creation [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Jul 28, 2022
1 parent 500c520 commit f531d2c
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 230 deletions.
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ project(rohrkabel LANGUAGES CXX VERSION 1.2)
# Library options
# --------------------------------------------------------------------------------------------------------

option(rohrkabel_examples "Build examples" OFF)
option(rohrkabel_examples "Build examples" OFF)
option(rohrkabel_prefer_remote "Prefer remote packages over local packages" ON)

# --------------------------------------------------------------------------------------------------------
# Warning for non unix platforms
Expand Down Expand Up @@ -48,13 +49,30 @@ target_sources(${PROJECT_NAME} PRIVATE ${src})
target_include_directories(${PROJECT_NAME} PUBLIC "include")
target_include_directories(${PROJECT_NAME} PRIVATE "include/rohrkabel")

# --------------------------------------------------------------------------------------------------------
# Fetch / Find required libraries
# --------------------------------------------------------------------------------------------------------

include(FetchContent)

if (NOT rohrkabel_prefer_remote)
find_package(tl-expected CONFIG REQUIRED)
else()
set(EXPECTED_BUILD_TESTS OFF)
set(EXPECTED_BUILD_PACKAGE OFF)

FetchContent_Declare(expected GIT_REPOSITORY "https://github.com/TartanLlama/expected")
FetchContent_MakeAvailable(expected)
endif()

# --------------------------------------------------------------------------------------------------------
# Link required libraries
# --------------------------------------------------------------------------------------------------------

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(PipeWire REQUIRED)

target_link_libraries(${PROJECT_NAME} PUBLIC tl::expected)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PipeWire_LIBRARIES} pthread)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${PipeWire_INCLUDE_DIRS} ${Spa_INCLUDE_DIRS})

Expand All @@ -65,7 +83,6 @@ target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${PipeWire_INCLUDE_DIR
if (rohrkabel_examples)
add_subdirectory("examples/roundtrip")
add_subdirectory("examples/virtual-mic")
add_subdirectory("examples/thread-loop")
add_subdirectory("examples/link-app-to-mic")
add_subdirectory("examples/mute-microphone")
endif()
Expand Down
17 changes: 10 additions & 7 deletions include/rohrkabel/client/client.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#pragma once
#include "info.hpp"
#include "../proxy.hpp"

#include <memory>

#include "../utils/annotations.hpp"
struct pw_client;
namespace pipewire
{
class registry;
class client
class client final : public proxy
{
struct impl;

private:
std::unique_ptr<impl> m_impl;

public:
~client();
~client() final;

public:
client(client &&) noexcept;
client(registry &, std::uint32_t);
client(proxy &&, client_info);

public:
static [[needs_update]] lazy_expected<client> bind(pw_client *);

public:
client &operator=(client &&) noexcept;
Expand All @@ -34,4 +36,5 @@ namespace pipewire
static const std::string type;
static const std::uint32_t version;
};
} // namespace pipewire
} // namespace pipewire
#include "../utils/annotations.hpp"
19 changes: 10 additions & 9 deletions include/rohrkabel/core/core.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
#include "events.hpp"
#include "../proxy.hpp"
#include "../context.hpp"

#include "../proxy.hpp"
#include "../node/node.hpp"
#include "../link_factory.hpp"
#include "../link/link.hpp"

#include <memory>

Expand Down Expand Up @@ -44,13 +44,13 @@ namespace pipewire
template <class EventListener> [[needs_update]] [[nodiscard]] EventListener listen() = delete;

template <typename T = proxy>
[[nodiscard]] [[needs_update]] T create(const std::string &factory_name, const properties &props, const std::string &type, std::uint32_t version,
update_strategy strategy = update_strategy::sync) = delete;
[[nodiscard]] [[needs_update]] lazy_expected<T> create(const std::string &factory_name, const properties &props, const std::string &type, std::uint32_t version,
update_strategy strategy = update_strategy::sync) = delete;

public:
template <typename Type>
[[nodiscard]] [[needs_update]] tie_to_t<Type, link_factory> create_simple(std::uint32_t input, std::uint32_t output,
update_strategy strategy = update_strategy::sync) = delete;
[[nodiscard]] [[needs_update]] lazy_expected<tie_to_t<Type, link>> create_simple(std::uint32_t input_port, std::uint32_t output_port,
update_strategy strategy = update_strategy::sync) = delete;

public:
[[nodiscard]] pw_core *get() const;
Expand All @@ -62,9 +62,10 @@ namespace pipewire

template <> core_listener core::listen();

template <> node core::create(const std::string &, const properties &, const std::string &, std::uint32_t, update_strategy);
template <> proxy core::create(const std::string &, const properties &, const std::string &, std::uint32_t, update_strategy);
template <> lazy_expected<node> core::create(const std::string &, const properties &, const std::string &, std::uint32_t, update_strategy);
template <> lazy_expected<link> core::create(const std::string &, const properties &, const std::string &, std::uint32_t, update_strategy);
template <> lazy_expected<proxy> core::create(const std::string &, const properties &, const std::string &, std::uint32_t, update_strategy);

template <> link_factory core::create_simple<link_factory>(std::uint32_t input, std::uint32_t output, update_strategy strategy);
template <> lazy_expected<link> core::create_simple<link>(std::uint32_t input, std::uint32_t output, update_strategy strategy);
} // namespace pipewire
#include "../utils/annotations.hpp"
15 changes: 5 additions & 10 deletions include/rohrkabel/device/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
#include "../proxy.hpp"
#include "../spa/pod/pod.hpp"

#include <map>
#include <future>
#include <memory>
#include <cstdint>

#include "../utils/annotations.hpp"
struct pw_device;
namespace pipewire
{
class registry;
class device final : public proxy
{
struct impl;
using params_t = std::future<std::map<std::uint32_t, spa::pod>>;

private:
std::unique_ptr<impl> m_impl;
Expand All @@ -25,19 +18,21 @@ namespace pipewire
~device() final;

public:
device(pw_device *);
device(device &&) noexcept;
device(registry &, std::uint32_t);
device(proxy &&, device_info);

public:
device &operator=(device &&) noexcept;

public:
static [[needs_update]] lazy_expected<device> bind(pw_device *);

public:
[[needs_update]] void set_param(std::uint32_t id, const spa::pod &pod);

public:
[[nodiscard]] device_info info() const;
[[nodiscard]] [[needs_update]] params_t params() const;
[[nodiscard]] [[needs_update]] std::future<std::map<std::uint32_t, spa::pod>> params() const;

public:
[[nodiscard]] pw_device *get() const;
Expand Down
4 changes: 4 additions & 0 deletions include/rohrkabel/error.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <string>
#include <future>
#include <stdexcept>
#include <tl/expected.hpp>

namespace pipewire
{
Expand All @@ -17,4 +19,6 @@ namespace pipewire
int res() const noexcept;
const char *what() const noexcept override;
};

template <typename T> using lazy_expected = std::future<tl::expected<T, error>>;
} // namespace pipewire
21 changes: 11 additions & 10 deletions include/rohrkabel/metadata/metadata.hpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#pragma once
#include "../proxy.hpp"
#include "property.hpp"

#include <map>
#include <memory>

#include "../utils/annotations.hpp"
struct pw_metadata;
namespace pipewire
{
class registry;
class metadata
class metadata final : public proxy
{
struct impl;
using properties_t = std::map<const std::string, const metadata_property>;

private:
std::unique_ptr<impl> m_impl;

public:
~metadata();
~metadata() final;

public:
metadata(metadata &&) noexcept;
metadata(registry &, std::uint32_t);
metadata(proxy &&, std::map<const std::string, const metadata_property>);

public:
metadata &operator=(metadata &&) noexcept;

public:
[[nodiscard]] properties_t properties() const;
static [[needs_update]] lazy_expected<metadata> bind(pw_metadata *);

public:
[[nodiscard]] std::map<const std::string, const metadata_property> properties() const;

public:
[[nodiscard]] pw_metadata *get() const;
Expand All @@ -36,4 +36,5 @@ namespace pipewire
static const std::string type;
static const std::uint32_t version;
};
} // namespace pipewire
} // namespace pipewire
#include "../utils/annotations.hpp"
13 changes: 4 additions & 9 deletions include/rohrkabel/node/node.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#pragma once
#include "info.hpp"
#include "../proxy.hpp"
#include "../global.hpp"
#include "../spa/pod/pod.hpp"

#include <map>
#include <future>
#include <memory>
#include <cstdint>

#include "../utils/annotations.hpp"
struct pw_node;
namespace pipewire
{
class registry;
class node final : public proxy
{
struct impl;
Expand All @@ -25,13 +18,15 @@ namespace pipewire
~node() final;

public:
node(pw_node *);
node(node &&) noexcept;
node(registry &, std::uint32_t);
node(proxy &&, node_info);

public:
node &operator=(node &&) noexcept;

public:
static [[needs_update]] lazy_expected<node> bind(pw_node *);

public:
[[needs_update]] void set_param(std::uint32_t id, const spa::pod &pod);

Expand Down
12 changes: 4 additions & 8 deletions include/rohrkabel/port/port.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#pragma once
#include "info.hpp"
#include "../proxy.hpp"
#include "../global.hpp"
#include "../spa/pod/pod.hpp"

#include <map>
#include <future>
#include <memory>

#include "../utils/annotations.hpp"
struct pw_port;
namespace pipewire
{
class registry;
class port final : public proxy
{
struct impl;
Expand All @@ -25,13 +19,15 @@ namespace pipewire
~port() final;

public:
port(pw_port *);
port(port &&) noexcept;
port(registry &, std::uint32_t);
port(proxy &&, port_info);

public:
port &operator=(port &&) noexcept;

public:
static [[needs_update]] lazy_expected<port> bind(pw_port *);

public:
[[nodiscard]] port_info info() const;
[[nodiscard]] [[needs_update]] params_t params() const;
Expand Down
8 changes: 7 additions & 1 deletion include/rohrkabel/proxy.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once
#include "error.hpp"
#include "properties.hpp"

#include <memory>
#include <string>
#include <cstdint>

#include "utils/annotations.hpp"
struct pw_proxy;
namespace pipewire
{
Expand All @@ -25,11 +27,15 @@ namespace pipewire
public:
proxy &operator=(proxy &&) noexcept;

public:
static [[needs_update]] lazy_expected<proxy> bind(pw_proxy *);

public:
[[nodiscard]] std::uint32_t id() const;

public:
[[nodiscard]] pw_proxy *get() const;
[[nodiscard]] std::uint32_t release();
};
} // namespace pipewire
} // namespace pipewire
#include "utils/annotations.hpp"
12 changes: 6 additions & 6 deletions include/rohrkabel/registry/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace pipewire

public:
template <class EventListener> [[needs_update]] [[nodiscard]] EventListener listen() = delete;
template <class Interface> [[needs_update]] [[nodiscard]] Interface bind(std::uint32_t id, update_strategy strategy = update_strategy::sync) = delete;
template <class T> [[needs_update]] [[nodiscard]] lazy_expected<T> bind(std::uint32_t id, update_strategy strategy = update_strategy::sync) = delete;

public:
[[nodiscard]] core &get_core();
Expand All @@ -37,10 +37,10 @@ namespace pipewire

template <> registry_listener registry::listen();

template <> node registry::bind(std::uint32_t, update_strategy);
template <> port registry::bind(std::uint32_t, update_strategy);
template <> client registry::bind(std::uint32_t, update_strategy);
template <> device registry::bind(std::uint32_t, update_strategy);
template <> metadata registry::bind(std::uint32_t, update_strategy);
template <> lazy_expected<node> registry::bind(std::uint32_t, update_strategy);
template <> lazy_expected<port> registry::bind(std::uint32_t, update_strategy);
template <> lazy_expected<client> registry::bind(std::uint32_t, update_strategy);
template <> lazy_expected<device> registry::bind(std::uint32_t, update_strategy);
template <> lazy_expected<metadata> registry::bind(std::uint32_t, update_strategy);
} // namespace pipewire
#include "../utils/annotations.hpp"

0 comments on commit f531d2c

Please sign in to comment.