7#include "../../_cexports/c_gen_api.h"
8#include "../../_cexports/c_driver.h"
10#include "../../global.hpp"
12#include "../_decl/decl_node.hpp"
13#include "../_decl/decl_node_map.hpp"
15#include "../../_decl/decl_device.hpp"
17#include "../value_node.hpp"
36 if (CExports::CanNodeMapHandle2(device.
Handle()))
39 nodeMap = Internal::DoResCallShareOut<NodeMap>(
40 [&](
void *&handle) {
return CVB_CALL_CAPI(NMH2GetNodeMap(device.
Handle(), cname.c_str(), handle)); }, name,
43 else if (name == CVB_LIT(
"Device"))
44 nodeMap = Internal::DoResCallShareOut<NodeMap>(
45 [&](
void *&handle) {
return CVB_CALL_CAPI(NMHGetNodeMap(device.
Handle(), handle)); }, name, device);
47 throw std::runtime_error(
"node map not found");
54 if (nodes_.find(CVB_LIT(
"Cust::FileSelector")) == nodes_.end()
55 && nodes_.find(CVB_LIT(
"Std::FileSelector")) == nodes_.end())
59 auto entries = enumerationNode->Entries();
62 for (
auto entry : entries)
64 if (entry->IsAvailable())
65 availableFiles.push_back(entry->SymbolicValue());
67 return availableFiles;
72 auto element = nodes_.find(name);
74 if (element == nodes_.end())
76 if (nodes_.find(CVB_LIT(
"Cust::") + name) != nodes_.end())
77 localName =
String(CVB_LIT(
"Cust::")) + name;
78 else if (nodes_.find(CVB_LIT(
"Std::") + name) != nodes_.end())
79 localName =
String(CVB_LIT(
"Std::")) + name;
84 auto node = nodes_[localName].lock();
88 nodes_[localName] = node;
109 for (
const auto &entry : nodes_)
110 nodes[entry.first] =
Node(entry.first);
114 inline NodeMap::NodeMap(HandleGuard<NodeMap> &&guard,
const String &name,
void *provider)
115 : handle_(std::move(guard))
117 , lastPoll_(std::chrono::system_clock::now())
119 if (CExports::CanNodeMapHandle2(provider))
120 ReadDescription(provider);
124 inline void NodeMap::ReadDescription(
void *provider)
127 size_t bufferLength = 0;
128 if (CExports::NMH2GetDescription(provider, cname.c_str(),
nullptr, bufferLength) >= 0 && bufferLength > 1)
131 auto resultDescription = CExports::NMH2GetDescription(provider, cname.c_str(), &buffer[0], bufferLength);
132 if (resultDescription < 0)
133 std::rethrow_exception(CvbException::FromCvbResult(resultDescription,
"failed to get node map description"));
134 description_ =
String(buffer.begin(), buffer.end() - 1);
138 inline void NodeMap::FillNodeKeys()
140 CExports::cvbdim_t numNodes = 0;
141 auto resultNum = CExports::NMNodeCount(
Handle(), numNodes);
143 std::rethrow_exception(CvbException::FromCvbResult(resultNum,
"failed to get node count"));
145 for (CExports::cvbdim_t i = 0; i < numNodes; ++i)
147 size_t nameLength = 0;
148 auto resultNameLength = CExports::NMListNode(
Handle(), i,
nullptr, nameLength);
149 if (resultNameLength < 0)
150 std::rethrow_exception(CvbException::FromCvbResult(resultNameLength,
"failed to get node name length"));
151 std::vector<char> buffer(
static_cast<size_t>(nameLength));
152 auto resultBuffer = CExports::NMListNode(
Handle(), i, &buffer[0], nameLength);
153 if (resultBuffer < 0)
154 std::rethrow_exception(CvbException::FromCvbResult(resultBuffer,
"failed to get node name"));
155 String keyString(buffer.begin(), buffer.end() - 1);
157 nodes_[keyString] = std::weak_ptr<class Node>();
164 CExports::NODEMAPSTREAM nodeMapStream;
165 auto res = CExports::NMCreateStream(
Handle(), CExports::TStreamType::ST_JSON, nodeMapStream);
167 Utilities::SystemInfo::ThrowLastError(res);
168 ReleaseObjectGuard guard(nodeMapStream);
170 for (
const auto &node : nodes)
172 res = CExports::NMStreamPush(nodeMapStream, node->Handle());
175 if (serializationErrorCallback)
176 serializationErrorCallback(node, Internal::CastToAscii(node->Name()) +
": "
179 Utilities::SystemInfo::ThrowLastError(res);
184 res = CExports::NMStreamDumpTyped(nodeMapStream,
reinterpret_cast<Char *
>(0), settingsSize);
186 Utilities::SystemInfo::ThrowLastError(res);
187 settingsSize +=
sizeof(
Char);
189 res = CExports::NMStreamDumpTyped(nodeMapStream, &settings[0], settingsSize);
191 Utilities::SystemInfo::ThrowLastError(res);
193 return String(&settings[0]);
Generic CVB physical device.
Definition decl_device.hpp:78
void * Handle() const noexcept
Classic API device handle.
Definition decl_device.hpp:122
std::shared_ptr< T > TryGetNode(const String &name) const noexcept
Tries to get the node with the given name from the node map.
Definition decl_node_map.hpp:641
std::shared_ptr< T > Node(const String &name) const
Get the node with the given name from the node map.
Definition decl_node_map.hpp:574
std::vector< String > AvailableFiles() const
Gets the currently available file identifiers, which can be downloaded or uploaded.
Definition detail_node_map.hpp:52
static NodeMapPtr FromHandle(HandleGuard< NodeMap > &&guard, const String &name, const Device &device)
Creates a node map from a classic API handle.
Definition detail_node_map.hpp:27
Cvb::String ToJson(std::function< void(NodePtr, const std::string &)> serializationErrorCallback=nullptr)
Serializes all nodes of this nodemap to a json string.
Definition decl_node_map.hpp:542
std::map< String, NodePtr > Nodes() const
Get a dictionary contain all nodes of this node map.
Definition detail_node_map.hpp:106
void * Handle() const noexcept
Classic API node map handle.
Definition decl_node_map.hpp:286
Namespace for GenApi based device configuration.
Definition decl_fw_updater.hpp:29
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition genapi.hpp:71
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition genapi.hpp:27
std::string GetLastErrorMessage(int &errorCode)
Returns the last error message and its code.
Definition system_info.hpp:141
Root namespace for the Image Manager interface.
Definition version.hpp:11
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
T const_pointer_cast(T... args)
T rethrow_exception(T... args)