3#include "../../_cexports/c_gen_api.h"
5#include "../../global.hpp"
6#include "../../exception.hpp"
8#include "../_decl/decl_node.hpp"
9#include "../_decl/decl_node_map.hpp"
10#include "../boolean_node.hpp"
11#include "../category_node.hpp"
12#include "../command_node.hpp"
13#include "../enumeration_node.hpp"
14#include "../enum_entry_node.hpp"
15#include "../float_reg_node.hpp"
16#include "../float_node.hpp"
17#include "../int_reg_node.hpp"
18#include "../integer_node.hpp"
19#include "../string_reg_node.hpp"
20#include "../string_node.hpp"
21#include "../port_node.hpp"
22#include "../register_node.hpp"
35 CExports::NODEMAP handle =
nullptr;
36 auto resultGet = CExports::NMGetNodeTyped(nodeMap->Handle(), name.c_str(), handle);
38 std::rethrow_exception(CvbException::FromCvbResult(resultGet,
"failed to get node"));
40 HandleGuard<Node> guard(handle);
41 return FromHandle(nodeMap, std::move(guard));
44 inline NodePtr Node::FromHandle(
const NodeMapPtr &nodeMap, HandleGuard<Node> &&guard)
46 auto handle = guard.Handle();
48 CExports::TNodeType nodeType = CExports::TNodeType::NT_Invalid;
49 auto resultType = CExports::NType(handle, nodeType);
51 std::rethrow_exception(CvbException::FromCvbResult(resultType,
"failed to get node type"));
53 CExports::cvbint64_t value = 0;
55 CExports::NInfoAsInteger(guard.Handle(),
static_cast<CExports::TNodeInfo
>(NodeInfo::RegisterLength), value)
63 case CExports::TNodeType::NT_Invalid:
64 case CExports::TNodeType::NT_Unknown:
65 throw std::runtime_error(
"invalid node type");
67 case CExports::TNodeType::NT_Boolean:
68 node = std::make_shared<BooleanNode>(std::move(guard));
71 case CExports::TNodeType::NT_Category:
72 node = std::make_shared<CategoryNode>(std::move(guard));
75 case CExports::TNodeType::NT_Command:
76 node = std::make_shared<CommandNode>(std::move(guard));
79 case CExports::TNodeType::NT_Enumeration:
80 node = std::make_shared<EnumerationNode>(std::move(guard));
83 case CExports::TNodeType::NT_EnumEntry:
84 node = std::make_shared<EnumEntryNode>(std::move(guard));
87 case CExports::TNodeType::NT_Float:
89 node = std::make_shared<FloatRegNode>(std::move(guard));
91 node = std::make_shared<FloatNode>(std::move(guard));
94 case CExports::TNodeType::NT_Integer:
96 node = std::make_shared<IntRegNode>(std::move(guard));
98 node = std::make_shared<IntegerNode>(std::move(guard));
101 case CExports::TNodeType::NT_String:
103 node = std::make_shared<StringRegNode>(std::move(guard));
105 node = std::make_shared<StringNode>(std::move(guard));
108 case CExports::TNodeType::NT_Port:
109 node = std::make_shared<PortNode>(std::move(guard));
114 node = std::make_shared<RegisterNode>(std::move(guard));
116 node = std::shared_ptr<Node>(
new Node(std::move(guard)));
120 node->nodeMap_ = nodeMap;
126 auto aliasName = GetInfoAsString(NodeInfo::AliasName);
127 if (aliasName.empty())
130 return nodeMap_->Node(aliasName);
135 auto holder = Internal::CbCarrier<void(Node &)>::Create(handler);
136 auto eventCookie = updatedCarrierContainer_.Register(holder);
139 if (nativeUpdateRegistered_)
142 const auto result = CExports::NRegisterUpdate(
Handle(), UpdatedCallback,
this, cbID_);
145 updatedCarrierContainer_.Unregister(eventCookie);
149 nativeUpdateRegistered_ =
true;
155 updatedCarrierContainer_.Unregister(eventCookie);
161 int numNodes = GetDependentNodeCount(type);
164 for (
int i = 0; i < numNodes; ++i)
166 auto nodeName = NativeCall<String>([&](
String &value) {
168 auto bufferSizeResult = CExports::NListTyped(
Handle(),
static_cast<CExports::TNodeList
>(type), i,
169 reinterpret_cast<Char *
>(0), bufferSize);
170 if (bufferSizeResult < 0)
171 return bufferSizeResult;
175 CExports::NListTyped(
Handle(),
static_cast<CExports::TNodeList
>(type), i, buffer.data(), bufferSize);
176 if (bufferResult < 0)
179 value =
String(buffer.data());
182 dependentNodes[i] = nodeMap_->Node<T>(nodeName);
184 return dependentNodes;
Cookie used to unregister event handlers.
Definition global.hpp:591
EventCookie RegisterEventUpdated(std::function< void(Node &)> handler)
Register a listener to node updated event.
Definition detail_node.hpp:133
void UnregisterEventUpdated(EventCookie eventCookie) noexcept
Manually unregister a listener to the node updated event.
Definition detail_node.hpp:153
NodePtr AliasNode() const
Gets the node, that is an alias value for this node.
Definition detail_node.hpp:124
void * Handle() const noexcept
Classic API node handle.
Definition decl_node.hpp:73
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
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 rethrow_exception(T... args)