12#include <peak/dll_interface/peak_dll_interface_util.hpp>
17#include <unordered_map>
59 ,
public std::enable_shared_from_this<NodeMap>
63 using NodeFilterFunction = std::function<bool(
const std::shared_ptr<const nodes::Node>& nodeToFilter)>;
92 friend ClassCreator<ScopedNodeMapLock>;
94 explicit ScopedNodeMapLock(
const std::shared_ptr<NodeMap>& nodeMap, std::adopt_lock_t t);
95 std::shared_ptr<NodeMap> m_nodeMap;
131 template <class NodeType, typename std::enable_if<std::is_base_of<nodes::Node, NodeType>::value,
int>::type = 0>
134 InitializeIfNecessary();
142 return std::dynamic_pointer_cast<NodeType>(m_nodesByName.at(name)) !=
nullptr;
174 template <class NodeType, typename std::enable_if<std::is_base_of<nodes::Node, NodeType>::value,
int>::type = 0>
177 auto castedNode = std::dynamic_pointer_cast<NodeType>(
FindNode(name));
211 template <class NodeType, typename std::enable_if<std::is_base_of<nodes::Node, NodeType>::value,
int>::type = 0>
220 auto castedNode = std::dynamic_pointer_cast<NodeType>(node);
340 void StoreToFile(
const std::string& filePath)
const;
411 return m_backendHandle;
415 std::shared_ptr<nodes::Node> NodeFromHandle(
PEAK_NODE_HANDLE nodeHandle)
const;
417 friend ClassCreator<NodeMap>;
421 void Initialize()
const override;
422 mutable std::vector<std::shared_ptr<nodes::Node>> m_nodes;
423 mutable std::unordered_map<std::string, std::shared_ptr<nodes::Node>> m_nodesByName;
448 : m_backendHandle(nodeMapHandle)
455 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* hasNode) {
462 InitializeIfNecessary();
464 (void)QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* nodeHandle) {
466 m_backendHandle, name.c_str(), name.size() + 1, nodeHandle);
469 return m_nodesByName.at(name);
474 InitializeIfNecessary();
476 const auto cNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
479 m_backendHandle, name.c_str(), name.size() + 1, nodeHandle);
482 if (cNodeHandle ==
nullptr)
487 return m_nodesByName.at(name);
492 CallAndCheckCInterfaceFunction(
498 CallAndCheckCInterfaceFunction(
504 InitializeIfNecessary();
511 if (event ==
nullptr)
516 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* hasSupportedData) {
518 m_backendHandle, event->m_backendHandle, hasSupportedData);
524 if (event ==
nullptr)
529 CallAndCheckCInterfaceFunction(
535 CallAndCheckCInterfaceFunction([&] {
542 InitializeIfNecessary();
544 CallAndCheckCInterfaceFunction([&] {
546 m_backendHandle, filePath.c_str(), filePath.size() + 1);
553 CallAndCheckCInterfaceFunction(
563 CallAndCheckCInterfaceFunction(
569 return std::make_unique<ClassCreator<ScopedNodeMapLock>>(shared_from_this());
575 CallAndCheckCInterfaceFunction(
583 return std::make_unique<ClassCreator<ScopedNodeMapLock>>(shared_from_this(), std::adopt_lock);
586inline std::shared_ptr<nodes::Node> NodeMap::NodeFromHandle(
PEAK_NODE_HANDLE nodeHandle)
const
588 auto nodeType = QueryNumericFromCInterfaceFunction<PEAK_NODE_TYPE>(
594 auto integerNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_INTEGER_NODE_HANDLE>(
599 return std::make_shared<ClassCreator<nodes::IntegerNode>>(
600 integerNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
603 auto booleanNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_BOOLEAN_NODE_HANDLE>(
608 return std::make_shared<ClassCreator<nodes::BooleanNode>>(
609 booleanNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
612 auto commandNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_COMMAND_NODE_HANDLE>(
617 return std::make_shared<ClassCreator<nodes::CommandNode>>(
618 commandNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
621 auto floatNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_FLOAT_NODE_HANDLE>(
626 return std::make_shared<ClassCreator<nodes::FloatNode>>(
627 floatNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
630 auto stringNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_STRING_NODE_HANDLE>(
635 return std::make_shared<ClassCreator<nodes::StringNode>>(
636 stringNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
639 auto registerNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_REGISTER_NODE_HANDLE>(
644 return std::make_shared<ClassCreator<nodes::RegisterNode>>(
645 registerNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
648 auto categoryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_CATEGORY_NODE_HANDLE>(
653 return std::make_shared<ClassCreator<nodes::CategoryNode>>(
654 categoryNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
657 auto enumerationNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_NODE_HANDLE>(
662 return std::make_shared<ClassCreator<nodes::EnumerationNode>>(
663 enumerationNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
666 auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
669 nodeHandle, _enumerationEntryNodeHandle);
672 return std::make_shared<ClassCreator<nodes::EnumerationEntryNode>>(
673 enumerationEntryNodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
676 return std::make_shared<ClassCreator<nodes::Node>>(
677 nodeHandle, std::const_pointer_cast<core::NodeMap>(shared_from_this()));
682inline void NodeMap::Initialize()
const
684 auto numNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numNodes) {
688 for (
size_t x = 0; x < numNodes; ++x)
690 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
695 auto node = NodeFromHandle(nodeHandle);
697 m_nodes.emplace_back(node);
698 m_nodesByName.emplace(node->Name(), node);
Represents a GenTL buffer module.
Definition peak_buffer.hpp:85
The exception thrown for passing an invalid argument to a function.
Definition peak_exception.hpp:118
The exception thrown for trying to apply an invalid cast.
Definition peak_exception.hpp:146
ScopedNodeMapLock(ScopedNodeMapLock &&other)=delete
ScopedNodeMapLock & operator=(ScopedNodeMapLock &&other)=delete
ScopedNodeMapLock()=delete
ScopedNodeMapLock & operator=(const ScopedNodeMapLock &other)=delete
ScopedNodeMapLock(const ScopedNodeMapLock &other)=delete
~ScopedNodeMapLock()
Definition peak_node_map.hpp:561
PEAK_COMMON_NO_DISCARD std::shared_ptr< nodes::Node > FindNode(const std::string &name)
Find a node with the given name.
Definition peak_node_map.hpp:460
PEAK_COMMON_NO_DISCARD bool HasNode(const std::string &name) const
Checks whether the node map contains a node with the given name.
Definition peak_node_map.hpp:453
PEAK_COMMON_NO_DISCARD bool HasEventSupportedData(const std::unique_ptr< Event > &event) const
Checks if the Event contains data corresponding to the NodeMap.
Definition peak_node_map.hpp:509
void StoreToFile(const std::string &filePath) const
Stores the values of streamable nodes to the file at the given file path.
Definition peak_node_map.hpp:533
NodeMap & operator=(const NodeMap &other)=delete
PEAK_COMMON_NO_DISCARD std::unique_ptr< ScopedNodeMapLock > Lock()
Acquires the NodeMap lock. Use this function to synchronize sequences of dependent NodeMap operations...
Definition peak_node_map.hpp:567
PEAK_COMMON_NO_DISCARD std::shared_ptr< NodeType > TryFindNode(const std::string &name)
Tries to find a node with the given name and type.
Definition peak_node_map.hpp:212
NodeMap(const NodeMap &other)=delete
void PollNodes(int64_t elapsedTime_ms)
Polls all nodes having a polling time.
Definition peak_node_map.hpp:496
PEAK_COMMON_NO_DISCARD std::vector< std::shared_ptr< nodes::Node > > Nodes() const
Returns the nodes.
Definition peak_node_map.hpp:502
std::function< bool(const std::shared_ptr< const nodes::Node > &nodeToFilter)> NodeFilterFunction
Definition peak_node_map.hpp:63
void UpdateChunkNodes(const std::shared_ptr< Buffer > &buffer)
Updates chunk information in the NodeMap.
Definition peak_buffer.hpp:1059
void InvalidateNodes()
Invalidates all nodes.
Definition peak_node_map.hpp:490
PEAK_COMMON_NO_DISCARD PEAK_NODE_MAP_HANDLE Handle() const
Get the backend handle.
Definition peak_node_map.hpp:409
NodeMap(NodeMap &&other)=delete
PEAK_COMMON_NO_DISCARD bool HasNode(const std::string &name)
Checks whether the node map contains a node with the given name and type.
Definition peak_node_map.hpp:132
void LoadFromFile(const std::string &filePath)
Loads the values of streamable nodes from the file at the given file path.
Definition peak_node_map.hpp:540
PEAK_COMMON_NO_DISCARD bool HasBufferSupportedChunks(const std::shared_ptr< Buffer > &buffer) const
Checks if the Buffer contains chunks corresponding to the NodeMap.
Definition peak_buffer.hpp:1046
PEAK_COMMON_NO_DISCARD std::unique_ptr< ScopedNodeMapLock > TryLock()
Attempts to acquire the NodeMap lock without blocking. Use this function to synchronize sequences of ...
Definition peak_node_map.hpp:572
PEAK_COMMON_NO_DISCARD std::shared_ptr< NodeType > FindNode(const std::string &name)
Find a node with the given name and type.
Definition peak_node_map.hpp:175
NodeMap & operator=(NodeMap &&other)=delete
void UpdateEventNodes(const std::unique_ptr< Event > &event)
Updates event information in the NodeMap.
Definition peak_node_map.hpp:522
PEAK_COMMON_NO_DISCARD std::shared_ptr< nodes::Node > TryFindNode(const std::string &name)
Tries to find a node with the given name.
Definition peak_node_map.hpp:472
Represents a GenAPI boolean node.
Definition peak_boolean_node.hpp:31
Represents a GenAPI category node.
Definition peak_category_node.hpp:34
Represents a GenAPI command node.
Definition peak_command_node.hpp:31
Represents a GenAPI enumeration entry node.
Definition peak_enumeration_entry_node.hpp:34
Represents a GenAPI enumeration node.
Definition peak_enumeration_node.hpp:37
Represents a GenAPI float node.
Definition peak_float_node.hpp:48
Represents a GenAPI integer node.
Definition peak_integer_node.hpp:38
Represents a GenAPI node.
Definition peak_node.hpp:125
Represents a GenAPI register node.
Definition peak_register_node.hpp:36
Represents a GenAPI string node.
Definition peak_string_node.hpp:33
The "nodes" namespace contains all GenAPI node types.
Definition peak_utils.hpp:31
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
PEAK_C_API PEAK_Node_ToEnumerationEntryNode(PEAK_NODE_HANDLE nodeHandle, PEAK_ENUMERATION_ENTRY_NODE_HANDLE *enumerationEntryNodeHandle)
Casts the given node to an enumeration entry node.
@ PEAK_NODE_TYPE_BOOLEAN
Definition peak_backend.h:285
@ PEAK_NODE_TYPE_FLOAT
Definition peak_backend.h:287
@ PEAK_NODE_TYPE_COMMAND
Definition peak_backend.h:286
@ PEAK_NODE_TYPE_CATEGORY
Definition peak_backend.h:290
@ PEAK_NODE_TYPE_ENUMERATION_ENTRY
Definition peak_backend.h:292
@ PEAK_NODE_TYPE_ENUMERATION
Definition peak_backend.h:291
@ PEAK_NODE_TYPE_STRING
Definition peak_backend.h:288
@ PEAK_NODE_TYPE_INTEGER
Definition peak_backend.h:284
@ PEAK_NODE_TYPE_REGISTER
Definition peak_backend.h:289
PEAK_C_API PEAK_NodeMap_GetNode(PEAK_NODE_MAP_HANDLE nodeMapHandle, size_t index, PEAK_NODE_HANDLE *nodeHandle)
Asks the given node map for the node with the given index.
PEAK_C_API PEAK_Node_ToRegisterNode(PEAK_NODE_HANDLE nodeHandle, PEAK_REGISTER_NODE_HANDLE *registerNodeHandle)
Casts the given node to a register node.
PEAK_C_API PEAK_NodeMap_UpdateEventNodes(PEAK_NODE_MAP_HANDLE nodeMapHandle, PEAK_EVENT_HANDLE eventHandle)
Updates event information in the node map.
PEAK_C_API PEAK_NodeMap_Lock(PEAK_NODE_MAP_HANDLE nodeMapHandle)
Locks a recursive mutex on the NodeMap.
struct PEAK_ENUMERATION_NODE * PEAK_ENUMERATION_NODE_HANDLE
Definition peak_backend.h:459
PEAK_C_API PEAK_NodeMap_GetHasEventSupportedData(PEAK_NODE_MAP_HANDLE nodeMapHandle, PEAK_EVENT_HANDLE eventHandle, PEAK_BOOL8 *hasSupportedData)
Checks if the event contains data corresponding to the node map.
struct PEAK_COMMAND_NODE * PEAK_COMMAND_NODE_HANDLE
Definition peak_backend.h:439
struct PEAK_STRING_NODE * PEAK_STRING_NODE_HANDLE
Definition peak_backend.h:447
PEAK_C_API PEAK_Node_ToBooleanNode(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOLEAN_NODE_HANDLE *booleanNodeHandle)
Casts the given node to a boolean node.
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition peak_backend.h:427
PEAK_C_API PEAK_NodeMap_TryLock(PEAK_NODE_MAP_HANDLE nodeMapHandle, PEAK_BOOL8 *locked)
Tries to Lock a recursive mutex on the NodeMap. Use this to synchronize NodeMap access from multiple ...
PEAK_C_API PEAK_Node_GetType(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_TYPE *type)
Asks the given node for its type.
int32_t PEAK_NODE_TYPE
Definition peak_backend.h:294
PEAK_C_API PEAK_Node_ToFloatNode(PEAK_NODE_HANDLE nodeHandle, PEAK_FLOAT_NODE_HANDLE *floatNodeHandle)
Casts the given node to a float node.
PEAK_C_API PEAK_NodeMap_GetHasNode(PEAK_NODE_MAP_HANDLE nodeMapHandle, const char *nodeName, size_t nodeNameSize, PEAK_BOOL8 *hasNode)
Checks whether the given node map contains a node with the given name.
PEAK_C_API PEAK_Node_ToIntegerNode(PEAK_NODE_HANDLE nodeHandle, PEAK_INTEGER_NODE_HANDLE *integerNodeHandle)
Casts the given node to an integer node.
PEAK_C_API PEAK_NodeMap_PollNodes(PEAK_NODE_MAP_HANDLE nodeMapHandle, int64_t elapsedTime_ms)
Tells the given node map to poll its nodes.
PEAK_C_API PEAK_NodeMap_StoreToFile(PEAK_NODE_MAP_HANDLE nodeMapHandle, const char *filePath, size_t filePathSize)
Tells the given node map to store the values of its streamable nodes to a file at the given file path...
struct PEAK_FLOAT_NODE * PEAK_FLOAT_NODE_HANDLE
Definition peak_backend.h:443
PEAK_C_API PEAK_Node_ToEnumerationNode(PEAK_NODE_HANDLE nodeHandle, PEAK_ENUMERATION_NODE_HANDLE *enumerationNodeHandle)
Casts the given node to an enumeration node.
PEAK_C_API PEAK_NodeMap_GetNumNodes(PEAK_NODE_MAP_HANDLE nodeMapHandle, size_t *numNodes)
Asks the given node map for its number of nodes.
PEAK_C_API PEAK_NodeMap_FindNode(PEAK_NODE_MAP_HANDLE nodeMapHandle, const char *nodeName, size_t nodeNameSize, PEAK_NODE_HANDLE *nodeHandle)
Tells the given node map to find a node with the given name.
PEAK_C_API PEAK_Node_ToCategoryNode(PEAK_NODE_HANDLE nodeHandle, PEAK_CATEGORY_NODE_HANDLE *categoryNodeHandle)
Casts the given node to a category node.
int8_t PEAK_BOOL8
Definition peak_backend.h:41
struct PEAK_NODE_MAP * PEAK_NODE_MAP_HANDLE
Definition peak_backend.h:423
struct PEAK_ENUMERATION_ENTRY_NODE * PEAK_ENUMERATION_ENTRY_NODE_HANDLE
Definition peak_backend.h:463
struct PEAK_CATEGORY_NODE * PEAK_CATEGORY_NODE_HANDLE
Definition peak_backend.h:455
struct PEAK_REGISTER_NODE * PEAK_REGISTER_NODE_HANDLE
Definition peak_backend.h:451
PEAK_C_API PEAK_Node_ToStringNode(PEAK_NODE_HANDLE nodeHandle, PEAK_STRING_NODE_HANDLE *stringNodeHandle)
Casts the given node to a string node.
PEAK_C_API PEAK_Node_ToCommandNode(PEAK_NODE_HANDLE nodeHandle, PEAK_COMMAND_NODE_HANDLE *commandNodeHandle)
Casts the given node to a command node.
@ PEAK_RETURN_CODE_SUCCESS
Definition peak_backend.h:332
PEAK_C_API PEAK_NodeMap_Unlock(PEAK_NODE_MAP_HANDLE nodeMapHandle)
Unlocks the recursive mutex on the NodeMap.
PEAK_C_API PEAK_NodeMap_InvalidateNodes(PEAK_NODE_MAP_HANDLE nodeMapHandle)
Tells the given node map to invalidate its nodes.
struct PEAK_BOOLEAN_NODE * PEAK_BOOLEAN_NODE_HANDLE
Definition peak_backend.h:435
struct PEAK_INTEGER_NODE * PEAK_INTEGER_NODE_HANDLE
Definition peak_backend.h:431
PEAK_C_API PEAK_NodeMap_LoadFromFile(PEAK_NODE_MAP_HANDLE nodeMapHandle, const char *filePath, size_t filePathSize)
Tells the given node map to load the values of its streamable nodes from a file at the given file pat...
PEAK_C_API PEAK_NodeMap_TryFindNode(PEAK_NODE_MAP_HANDLE nodeMapHandle, const char *nodeName, size_t nodeNameSize, PEAK_NODE_HANDLE *nodeHandle)
Tells the given node map to try to find a node with the given name.
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:13