aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/boot_modules/device.hpp4
-rw-r--r--kapi/kapi/devices.hpp4
-rw-r--r--kapi/kapi/devices/bus.hpp2
-rw-r--r--kapi/kapi/devices/device.hpp16
-rw-r--r--kapi/kapi/devices/driver.hpp12
-rw-r--r--kapi/kapi/devices/facet_registry.hpp30
-rw-r--r--kapi/kapi/memory/address.hpp4
7 files changed, 38 insertions, 34 deletions
diff --git a/kapi/kapi/boot_modules/device.hpp b/kapi/kapi/boot_modules/device.hpp
index 4bdd34e4..7d3e3d6e 100644
--- a/kapi/kapi/boot_modules/device.hpp
+++ b/kapi/kapi/boot_modules/device.hpp
@@ -6,6 +6,8 @@
#include <kapi/devices.hpp>
#include <kapi/memory.hpp>
+#include <kstd/memory.hpp>
+
#include <cstddef>
#include <string_view>
#include <utility>
@@ -54,7 +56,7 @@ namespace kapi::boot_modules
[[nodiscard]] auto module() const -> struct module const & override;
protected:
- auto query_facet(kapi::capabilities::facet_id facet) -> void * override;
+ auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr<void> override;
private:
struct module m_module;
diff --git a/kapi/kapi/devices.hpp b/kapi/kapi/devices.hpp
index c4bda9b9..c7de1830 100644
--- a/kapi/kapi/devices.hpp
+++ b/kapi/kapi/devices.hpp
@@ -58,8 +58,8 @@ namespace kapi::devices
//! @param name A stable name for the device.
//! @param implementation The implementation of the facet for the device.
template<typename Facet>
- [[nodiscard]] auto publish_facet(kstd::shared_ptr<device> device, kstd::string name, Facet * implementation)
- -> kstd::result<void>
+ [[nodiscard]] auto publish_facet(kstd::shared_ptr<device> device, kstd::string name,
+ kstd::observer_ptr<Facet> implementation) -> kstd::result<void>
{
return facet_registry::get().publish(device, std::move(name), implementation);
}
diff --git a/kapi/kapi/devices/bus.hpp b/kapi/kapi/devices/bus.hpp
index aaca462a..476216c7 100644
--- a/kapi/kapi/devices/bus.hpp
+++ b/kapi/kapi/devices/bus.hpp
@@ -59,7 +59,7 @@ namespace kapi::devices
protected:
//! All busses have the "bus" facet.
- auto query_facet(kapi::capabilities::facet_id facet) -> void * override;
+ auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr<void> override;
private:
auto do_remove_child(device & child) -> void;
diff --git a/kapi/kapi/devices/device.hpp b/kapi/kapi/devices/device.hpp
index 86566bff..c3a33daf 100644
--- a/kapi/kapi/devices/device.hpp
+++ b/kapi/kapi/devices/device.hpp
@@ -56,22 +56,22 @@ namespace kapi::devices
//!
//! @param id The id of the desired facet.
//! @return An opaque pointer to the facet implementation if this device supports it, nullptr otherwise.
- [[nodiscard]] auto facet(kapi::capabilities::facet_id id) noexcept -> void *;
+ [[nodiscard]] auto facet(kapi::capabilities::facet_id id) noexcept -> kstd::observer_ptr<void>;
//! Get a specific facet of this device, if it supports it.
//!
//! @param id The id of the desired facet.
//! @return A opaque pointer to the facet implementation if this device supports it, nullptr otherwise.
- [[nodiscard]] auto facet(kapi::capabilities::facet_id id) const noexcept -> void const *;
+ [[nodiscard]] auto facet(kapi::capabilities::facet_id id) const noexcept -> kstd::observer_ptr<void const>;
//! Get a specific facet of this device, if it supports it.
//!
//! @tparam FacetType The type of the desired facet.
//! @return A typed pointer to the facet implementation if this device supports it, nullptr otherwise.
template<typename FacetType>
- [[nodiscard]] auto facet() -> FacetType *
+ [[nodiscard]] auto facet() -> kstd::observer_ptr<FacetType>
{
- return static_cast<FacetType *>(facet(FacetType::id));
+ return kstd::observer_ptr{static_cast<FacetType *>(facet(FacetType::id).get())};
}
//! Get a specific facet of this device, if it supports it.
@@ -79,9 +79,9 @@ namespace kapi::devices
//! @tparam FacetType The type of the desired facet.
//! @return A typed pointer to the facet implementation if this device supports it, nullptr otherwise.
template<typename FacetType>
- [[nodiscard]] auto facet() const noexcept -> FacetType const *
+ [[nodiscard]] auto facet() const noexcept -> kstd::observer_ptr<FacetType const>
{
- return static_cast<FacetType const *>(facet(FacetType::id));
+ return kstd::observer_ptr{static_cast<FacetType const *>(facet(FacetType::id).get())};
}
//! Check if this device has a specific facet.
@@ -119,7 +119,7 @@ namespace kapi::devices
auto set_state(enum state state) -> void;
//! Get the driver, if any, currently bound to this device.
- [[nodiscard]] auto bound_driver() const noexcept -> driver *;
+ [[nodiscard]] auto bound_driver() const noexcept -> kstd::shared_ptr<driver>;
//! Bind this device to the given driver.
auto bind_driver(kstd::weak_ptr<struct driver> driver) -> void;
@@ -159,7 +159,7 @@ namespace kapi::devices
auto set_resources(kstd::vector<resource> resources) -> void;
protected:
- auto virtual query_facet(kapi::capabilities::facet_id facet) -> void *;
+ auto virtual query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr<void>;
private:
//! Busses need to be able to register themselves as a device's parent.
diff --git a/kapi/kapi/devices/driver.hpp b/kapi/kapi/devices/driver.hpp
index b46091fe..8c4d5e97 100644
--- a/kapi/kapi/devices/driver.hpp
+++ b/kapi/kapi/devices/driver.hpp
@@ -5,6 +5,7 @@
#include <kapi/capabilities/facet_id.hpp>
+#include <kstd/memory.hpp>
#include <kstd/result.hpp>
#include <cstdint>
@@ -66,9 +67,9 @@ namespace kapi::devices
//! @return A pointer to this drivers implementation of the requested facet, nullptr if this driver does not
//! support the requested facet.
template<typename FacetType>
- [[nodiscard]] auto facet() -> FacetType *
+ [[nodiscard]] auto facet() -> kstd::observer_ptr<FacetType>
{
- return static_cast<FacetType *>(query_facet(FacetType::id));
+ return kstd::observer_ptr{static_cast<FacetType *>(query_facet(FacetType::id))};
}
//! Retrieve this drivers implementation of a given capability facet.
@@ -76,9 +77,10 @@ namespace kapi::devices
//! @return A pointer to this drivers implementation of the requested facet, nullptr if this driver does not
//! support the requested facet.
template<typename FacetType>
- [[nodiscard]] auto facet() const -> FacetType const *
+ [[nodiscard]] auto facet() const -> kstd::observer_ptr<FacetType const>
{
- return static_cast<FacetType *>(const_cast<driver *>(this)->query_facet(FacetType::id));
+ return kstd::observer_ptr{
+ static_cast<FacetType const *>(const_cast<driver *>(this)->query_facet(FacetType::id).get())};
}
//! Check if this driver implements a given capability facet.
@@ -107,7 +109,7 @@ namespace kapi::devices
protected:
//! Return a pointer to the implementation of the given facet if this driver supports it.
- virtual auto query_facet(kapi::capabilities::facet_id facet) -> void *;
+ virtual auto query_facet(kapi::capabilities::facet_id facet) -> kstd::observer_ptr<void>;
};
//! @}
diff --git a/kapi/kapi/devices/facet_registry.hpp b/kapi/kapi/devices/facet_registry.hpp
index 3c405923..5e0367c1 100644
--- a/kapi/kapi/devices/facet_registry.hpp
+++ b/kapi/kapi/devices/facet_registry.hpp
@@ -51,7 +51,7 @@ namespace kapi::devices
//! @param facet The id of the implemented facet.
//! @param implementation A pointer to the actual implementation of the facet for the given device.
constexpr entry(kstd::shared_ptr<struct device> device, kstd::string name, kapi::capabilities::facet_id facet,
- void * implementation)
+ kstd::observer_ptr<void> implementation)
: m_device{device}
, m_name{name}
, m_id{facet}
@@ -86,7 +86,7 @@ namespace kapi::devices
//! Get the facet of the device-facet-implementation tuple described by this entry.
//!
//! @return An untyped pointer to the facet implementation.
- [[nodiscard]] constexpr auto untyped_facet() const noexcept -> void *
+ [[nodiscard]] constexpr auto untyped_facet() const noexcept -> kstd::observer_ptr<void>
{
return m_facet;
}
@@ -95,11 +95,11 @@ namespace kapi::devices
//!
//! @return A typed pointer to the facet if the facet id matches, nullptr otherwise.
template<typename FacetType>
- [[nodiscard]] constexpr auto facet() noexcept -> FacetType *
+ [[nodiscard]] constexpr auto facet() noexcept -> kstd::observer_ptr<FacetType>
{
if (m_id == FacetType::id)
{
- return static_cast<FacetType *>(untyped_facet());
+ return kstd::observer_ptr{static_cast<FacetType *>(untyped_facet().get())};
}
return nullptr;
}
@@ -108,11 +108,11 @@ namespace kapi::devices
//!
//! @return A typed pointer to the facet if the facet id matches, nullptr otherwise.
template<typename FacetType>
- [[nodiscard]] constexpr auto facet() const noexcept -> FacetType const *
+ [[nodiscard]] constexpr auto facet() const noexcept -> kstd::observer_ptr<FacetType const>
{
if (m_id == FacetType::id)
{
- return static_cast<FacetType const *>(untyped_facet());
+ return kstd::observer_ptr{static_cast<FacetType const *>(untyped_facet().get())};
}
return nullptr;
}
@@ -121,7 +121,7 @@ namespace kapi::devices
kstd::weak_ptr<struct device> m_device;
kstd::string m_name;
kapi::capabilities::facet_id m_id;
- void * m_facet;
+ kstd::observer_ptr<void> m_facet;
};
//! Construct an empty facet registry.
@@ -172,7 +172,7 @@ namespace kapi::devices
//! @param name A stable name for the device.
//! @param facet The implementation of the facet for the device.
template<typename FacetType>
- [[nodiscard]] auto publish(kstd::shared_ptr<device> device, kstd::string name, FacetType * facet)
+ [[nodiscard]] auto publish(kstd::shared_ptr<device> device, kstd::string name, kstd::observer_ptr<FacetType> facet)
-> kstd::result<void>
{
return do_publish(device, std::move(name), FacetType::id, facet);
@@ -198,22 +198,22 @@ namespace kapi::devices
//!
//! @param id The id of the facet to look for.
//! @param name The stable name of the device.
- [[nodiscard]] auto resolve(kapi::capabilities::facet_id id, std::string_view name) -> void *;
+ [[nodiscard]] auto resolve(kapi::capabilities::facet_id id, std::string_view name) -> kstd::observer_ptr<void>;
//! Attempt to resolve a facet for a device.
//!
//! @param id The id of the facet to look for.
//! @param device The device.
- [[nodiscard]] auto resolve(kapi::capabilities::facet_id id, device & device) -> void *;
+ [[nodiscard]] auto resolve(kapi::capabilities::facet_id id, device & device) -> kstd::observer_ptr<void>;
//! Attempt to resolve a facet for a device by name.
//!
//! @tparam FacetType The facet to look for.
//! @param name The stable name of the device.
template<typename FacetType>
- [[nodiscard]] auto resolve(std::string_view name) -> FacetType *
+ [[nodiscard]] auto resolve(std::string_view name) -> kstd::observer_ptr<FacetType>
{
- return static_cast<FacetType *>(resolve(FacetType::id, name));
+ return kstd::observer_ptr{static_cast<FacetType *>(resolve(FacetType::id, name).get())};
}
//! Attempt to resolve a facet for a device.
@@ -221,9 +221,9 @@ namespace kapi::devices
//! @tparam FacetType The facet to look for.
//! @param device The device.
template<typename FacetType>
- [[nodiscard]] auto resolve(device & device) -> FacetType *
+ [[nodiscard]] auto resolve(device & device) -> kstd::observer_ptr<FacetType>
{
- return static_cast<FacetType *>(resolve(FacetType::id, device));
+ return kstd::observer_ptr{static_cast<FacetType *>(resolve(FacetType::id, device).get())};
}
//! Subscribe to facet publish/withdraw notifications.
@@ -256,7 +256,7 @@ namespace kapi::devices
//! @param id The id of the facet to be published for the device.
//! @param facet The facet of the device.
[[nodiscard]] auto do_publish(kstd::shared_ptr<device> device, kstd::string name, kapi::capabilities::facet_id id,
- void * facet) -> kstd::result<void>;
+ kstd::observer_ptr<void> facet) -> kstd::result<void>;
//! Notify all subscribed observers about a new facet having been published for a device.
//!
diff --git a/kapi/kapi/memory/address.hpp b/kapi/kapi/memory/address.hpp
index a7f5ac92..5b84a381 100644
--- a/kapi/kapi/memory/address.hpp
+++ b/kapi/kapi/memory/address.hpp
@@ -102,7 +102,7 @@ namespace kapi::memory
//!
//! @param n The amount to subtract from this address
//! @return A nre address, @p n ahead of this one
- [[nodiscard]] constexpr auto operator-(std::ptrdiff_t n) noexcept -> address
+ [[nodiscard]] constexpr auto operator-(std::ptrdiff_t n) const noexcept -> address
{
return address{m_value - n};
}
@@ -139,7 +139,7 @@ namespace kapi::memory
//!
//! @param other The address to calculate the distance to.
//! @return The distance between this address and the given one.
- [[nodiscard]] constexpr auto operator-(address const & other) noexcept -> std::ptrdiff_t
+ [[nodiscard]] constexpr auto operator-(address const & other) const noexcept -> std::ptrdiff_t
{
return m_value - other.m_value;
}