IDS peak genericC++  v1.5.0
peak_register_node.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
15 #include <peak/dll_interface/peak_dll_interface_util.hpp>
16 #include <peak/error_handling/peak_error_handling.hpp>
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <vector>
23 
24 
25 namespace peak
26 {
27 namespace core
28 {
29 namespace nodes
30 {
31 
36 class RegisterNode : public Node
37 {
38 public:
39  RegisterNode() = delete;
40  ~RegisterNode() override = default;
41  RegisterNode(const RegisterNode& other) = delete;
42  RegisterNode& operator=(const RegisterNode& other) = delete;
43  RegisterNode(RegisterNode&& other) = delete;
44  RegisterNode& operator=(RegisterNode&& other) = delete;
45 
55  uint64_t Address() const;
65  size_t Length() const;
66 
79  std::vector<uint8_t> Read(size_t numBytes, NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
89  void Write(const std::vector<uint8_t>& bytes);
90 
91 private:
92  friend ClassCreator<RegisterNode>;
93  RegisterNode(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
94  PEAK_REGISTER_NODE_HANDLE m_backendHandle;
95 };
96 
97 } /* namespace nodes */
98 } /* namespace core */
99 } /* namespace peak */
100 
101 /* Implementation */
102 namespace peak
103 {
104 namespace core
105 {
106 namespace nodes
107 {
108 
110  PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
111  : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
112  return PEAK_C_ABI_PREFIX PEAK_RegisterNode_ToNode(registerNodeHandle, nodeHandle);
113  }),
114  parentNodeMap)
115  , m_backendHandle(registerNodeHandle)
116 {}
117 
118 inline uint64_t RegisterNode::Address() const
119 {
120  return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* address) {
121  return PEAK_C_ABI_PREFIX PEAK_RegisterNode_GetAddress(m_backendHandle, address);
122  });
123 }
124 
125 inline size_t RegisterNode::Length() const
126 {
127  return QueryNumericFromCInterfaceFunction<size_t>(
128  [&](size_t* length) { return PEAK_C_ABI_PREFIX PEAK_RegisterNode_GetLength(m_backendHandle, length); });
129 }
130 
131 inline std::vector<uint8_t> RegisterNode::Read(
132  size_t numBytes, NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
133 {
134  std::vector<uint8_t> bytes(numBytes);
135  ExecuteAndMapReturnCodes([&] {
137  m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), bytes.data(), bytes.size());
138  });
139 
140  return bytes;
141 }
142 
143 inline void RegisterNode::Write(const std::vector<uint8_t>& bytes)
144 {
145  ExecuteAndMapReturnCodes(
146  [&] { return PEAK_C_ABI_PREFIX PEAK_RegisterNode_Write(m_backendHandle, bytes.data(), bytes.size()); });
147 }
148 
149 } /* namespace nodes */
150 } /* namespace core */
151 } /* namespace peak */
uint64_t Address() const
Returns the address.
Definition: peak_register_node.hpp:118
size_t Length() const
Returns the length.
Definition: peak_register_node.hpp:125
PEAK_C_API PEAK_RegisterNode_ToNode(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given register node to a node.
~RegisterNode() override=default
PEAK_C_API PEAK_RegisterNode_Write(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const uint8_t *bytesToWrite, size_t bytesToWriteSize)
Tells the given register node to write the given bytes.
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
NodeCacheUsePolicy
Definition: peak_common_node_enums.hpp:24
std::vector< uint8_t > Read(size_t numBytes, NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Reads a given amount of bytes.
Definition: peak_register_node.hpp:131
PEAK_C_API PEAK_RegisterNode_GetLength(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, size_t *length)
Asks the given register node for its length.
void Write(const std::vector< uint8_t > &bytes)
Writes a given amount of bytes.
Definition: peak_register_node.hpp:143
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition: peak_backend.h:409
RegisterNode & operator=(const RegisterNode &other)=delete
PEAK_C_API PEAK_RegisterNode_Read(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, PEAK_NODE_CACHE_USE_POLICY cacheUsePolicy, uint8_t *bytesToRead, size_t bytesToReadSize)
Tells the given register node to read the given amount of bytes.
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
PEAK_C_API PEAK_RegisterNode_GetAddress(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, uint64_t *address)
Asks the given register node for its address.
Represents a GenAPI node.
Definition: peak_node.hpp:121
struct PEAK_REGISTER_NODE * PEAK_REGISTER_NODE_HANDLE
Definition: peak_backend.h:433
Represents a GenAPI register node.
Definition: peak_register_node.hpp:36