contur2
Loading...
Searching...
No Matches
device_manager.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <functional>
11#include <memory>
12#include <optional>
13#include <vector>
14
15#include "contur/core/error.h"
16#include "contur/core/types.h"
17
18#include "contur/io/i_device.h"
19
20namespace contur {
21
27 {
28 public:
31
32 // Non-copyable, movable
33 DeviceManager(const DeviceManager &) = delete;
36 DeviceManager &operator=(DeviceManager &&) noexcept;
37
41 [[nodiscard]] Result<void> registerDevice(std::unique_ptr<IDevice> device);
42
45 [[nodiscard]] Result<void> unregisterDevice(DeviceId id);
46
48 [[nodiscard]] std::optional<std::reference_wrapper<IDevice>> getDevice(DeviceId id) noexcept;
49
51 [[nodiscard]] std::optional<std::reference_wrapper<const IDevice>> getDevice(DeviceId id) const noexcept;
52
55 [[nodiscard]] Result<void> write(DeviceId id, RegisterValue value);
56
59 [[nodiscard]] Result<RegisterValue> read(DeviceId id);
60
62 [[nodiscard]] std::size_t deviceCount() const noexcept;
63
65 [[nodiscard]] bool hasDevice(DeviceId id) const noexcept;
66
67 private:
68 struct Impl;
69 std::unique_ptr<Impl> impl_;
70 };
71
72} // namespace contur
std::size_t deviceCount() const noexcept
Returns the number of registered devices.
DeviceManager(const DeviceManager &)=delete
Result< RegisterValue > read(DeviceId id)
Reads a value from the device with the given ID.
Result< void > write(DeviceId id, RegisterValue value)
Writes a value to the device with the given ID.
std::optional< std::reference_wrapper< IDevice > > getDevice(DeviceId id) noexcept
Returns a non-owning reference to the device with the given ID, if present.
std::unique_ptr< Impl > impl_
DeviceManager & operator=(const DeviceManager &)=delete
Result< void > registerDevice(std::unique_ptr< IDevice > device)
Registers a device. Takes ownership.
DeviceManager(DeviceManager &&) noexcept
Result< void > unregisterDevice(DeviceId id)
Removes and destroys a device by ID.
bool hasDevice(DeviceId id) const noexcept
Returns true if a device with the given ID is registered.
Abstract interface for a simulated I/O device.
Definition i_device.h:22
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Error codes and Result<T> type for fallible operations.
IDevice — abstract interface for I/O devices.
Definition block.h:15
std::int32_t RegisterValue
Value stored in a CPU register.
Definition types.h:21
std::uint16_t DeviceId
Unique identifier for an I/O device.
Definition types.h:24
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...