aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/devices/device.cpp
blob: 2628e4f4685449c802cab137d4f6bddb35307068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <kapi/devices/device.hpp>

#include <kapi/devices.hpp>
#include <kapi/devices/bus.hpp>

#include <kstd/memory.hpp>
#include <kstd/string.hpp>

namespace kapi::devices
{
  device::device(kstd::string const & name)
      : m_name(name)
  {}

  auto device::facet(kapi::capabilities::facet_id facet) noexcept -> void *
  {
    return query_facet(facet);
  }

  auto device::facet(kapi::capabilities::facet_id facet) const noexcept -> void const *
  {
    return const_cast<device *>(this)->query_facet(facet);
  }

  auto device::has_facet(kapi::capabilities::facet_id facet) const noexcept -> bool
  {
    return const_cast<device *>(this)->query_facet(facet) != nullptr;
  }

  auto device::name() const -> kstd::string const &
  {
    return m_name;
  }

  auto device::parent() const -> kstd::shared_ptr<bus>
  {
    return m_parent.lock();
  }

  auto device::state() const noexcept -> enum state
  {
    return m_state;
  }

  auto device::set_state(enum state state) -> void
  {
    m_state = state;
  }

  auto device::bound_driver() const noexcept -> driver *
  {
    return m_driver.lock().get();
  }

  auto device::bind_driver(kstd::weak_ptr<struct driver> driver) -> void
  {
    m_driver = driver;
  }

  auto device::driver_data() const -> kstd::shared_ptr<void> const &
  {
    return m_driver_data;
  }

  auto device::set_driver_data(kstd::shared_ptr<void> data) -> void
  {
    m_driver_data = data;
  }

  auto device::query_facet(kapi::capabilities::facet_id) -> void *
  {
    return nullptr;
  }

  auto device::set_parent(kstd::weak_ptr<bus> parent) -> void
  {
    m_parent = parent;
  }

}  // namespace kapi::devices