15 #include <peak/dll_interface/peak_dll_interface_util.hpp> 19 #include <type_traits> 20 #include <unordered_map> 41 class EnumerationNode;
42 class EnumerationEntryNode;
61 ,
public std::enable_shared_from_this<NodeMap>
65 using NodeFilterFunction = std::function<bool(const std::shared_ptr<const nodes::Node>& nodeToFilter)>;
84 friend ClassCreator<ScopedNodeMapLock>;
86 std::shared_ptr<NodeMap> m_nodeMap;
105 bool HasNode(
const std::string& name)
const;
115 template <class NodeType, typename std::enable_if<std::is_base_of<nodes::Node, NodeType>::value,
int>::type = 0>
125 return std::dynamic_pointer_cast<
NodeType>(FindNode(name)) !=
nullptr;
140 std::shared_ptr<nodes::Node> FindNode(
const std::string& name);
155 template <class NodeType, typename std::enable_if<std::is_base_of<nodes::Node, NodeType>::value,
int>::type = 0>
156 std::shared_ptr<NodeType>
FindNode(
const std::string& name)
158 auto castedNode = std::dynamic_pointer_cast<
NodeType>(FindNode(name));
173 void InvalidateNodes();
183 void PollNodes(int64_t elapsedTime_ms);
193 std::vector<std::shared_ptr<nodes::Node>> Nodes()
const;
203 bool HasBufferSupportedChunks(
const std::shared_ptr<Buffer>& buffer)
const;
216 void UpdateChunkNodes(
const std::shared_ptr<Buffer>& buffer);
226 bool HasEventSupportedData(
const std::unique_ptr<Event>& event)
const;
240 void UpdateEventNodes(
const std::unique_ptr<Event>& event);
254 void StoreToFile(
const std::string& filePath)
const;
268 void LoadFromFile(
const std::string& filePath);
288 std::unique_ptr<ScopedNodeMapLock> Lock();
291 std::shared_ptr<nodes::Node> NodeFromHandle(
PEAK_NODE_HANDLE nodeHandle)
const;
293 friend ClassCreator<NodeMap>;
297 void Initialize()
const override;
298 mutable std::vector<std::shared_ptr<nodes::Node>> m_nodes;
299 mutable std::unordered_map<std::string, std::shared_ptr<nodes::Node>> m_nodesByName;
324 : m_backendHandle(nodeMapHandle)
331 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* hasNode) {
338 InitializeIfNecessary();
340 (void)QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* nodeHandle) {
342 m_backendHandle, name.c_str(), name.size() + 1, nodeHandle);
345 return m_nodesByName.at(name);
350 CallAndCheckCInterfaceFunction(
356 CallAndCheckCInterfaceFunction(
362 InitializeIfNecessary();
369 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* hasSupportedData) {
371 m_backendHandle, event->m_backendHandle, hasSupportedData);
377 CallAndCheckCInterfaceFunction(
383 CallAndCheckCInterfaceFunction([&] {
390 InitializeIfNecessary();
392 CallAndCheckCInterfaceFunction([&] {
394 m_backendHandle, filePath.c_str(), filePath.size() + 1);
401 CallAndCheckCInterfaceFunction(
406 CallAndCheckCInterfaceFunction(
412 return std::make_unique<ClassCreator<ScopedNodeMapLock>>(shared_from_this());
415 inline std::shared_ptr<nodes::Node> NodeMap::NodeFromHandle(
PEAK_NODE_HANDLE nodeHandle)
const 417 auto nodeType = QueryNumericFromCInterfaceFunction<PEAK_NODE_TYPE>(
423 auto integerNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_INTEGER_NODE_HANDLE>(
428 return std::make_shared<ClassCreator<nodes::IntegerNode>>(
429 integerNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
432 auto booleanNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_BOOLEAN_NODE_HANDLE>(
437 return std::make_shared<ClassCreator<nodes::BooleanNode>>(
438 booleanNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
441 auto commandNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_COMMAND_NODE_HANDLE>(
446 return std::make_shared<ClassCreator<nodes::CommandNode>>(
447 commandNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
450 auto floatNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_FLOAT_NODE_HANDLE>(
455 return std::make_shared<ClassCreator<nodes::FloatNode>>(
456 floatNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
459 auto stringNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_STRING_NODE_HANDLE>(
464 return std::make_shared<ClassCreator<nodes::StringNode>>(
465 stringNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
468 auto registerNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_REGISTER_NODE_HANDLE>(
473 return std::make_shared<ClassCreator<nodes::RegisterNode>>(
474 registerNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
477 auto categoryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_CATEGORY_NODE_HANDLE>(
482 return std::make_shared<ClassCreator<nodes::CategoryNode>>(
483 categoryNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
486 auto enumerationNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_NODE_HANDLE>(
491 return std::make_shared<ClassCreator<nodes::EnumerationNode>>(
492 enumerationNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
495 auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
498 nodeHandle, _enumerationEntryNodeHandle);
501 return std::make_shared<ClassCreator<nodes::EnumerationEntryNode>>(
502 enumerationEntryNodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
505 return std::make_shared<ClassCreator<nodes::Node>>(
506 nodeHandle, std::const_pointer_cast<
core::NodeMap>(shared_from_this()));
511 inline void NodeMap::Initialize()
const 513 auto numNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numNodes) {
517 for (
size_t x = 0; x < numNodes; ++x)
519 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
524 auto node = NodeFromHandle(nodeHandle);
526 m_nodes.emplace_back(node);
527 m_nodesByName.emplace(node->Name(), node);
Represents a GenAPI node map.
Definition: peak_node_map.hpp:59
Definition: peak_backend.h:272
bool HasEventSupportedData(const std::unique_ptr< Event > &event) const
Checks if the Event contains data corresponding to the NodeMap.
Definition: peak_node_map.hpp:367
std::vector< std::shared_ptr< nodes::Node > > Nodes() const
Returns the nodes.
Definition: peak_node_map.hpp:360
int8_t PEAK_BOOL8
Definition: peak_backend.h:26
std::unique_ptr< ScopedNodeMapLock > Lock()
Locks a recursive mutex on the NodeMap.
Definition: peak_node_map.hpp:410
Definition: peak_backend.h:277
Holds a recursive lock on the NodeMap.
Definition: peak_node_map.hpp:72
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.
int32_t PEAK_NODE_TYPE
Definition: peak_backend.h:279
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
Definition: peak_backend.h:270
The exception thrown for trying to apply an invalid cast.
Definition: peak_exception.hpp:81
struct PEAK_INTEGER_NODE * PEAK_INTEGER_NODE_HANDLE
Definition: peak_backend.h:413
void InvalidateNodes()
Invalidates all nodes.
Definition: peak_node_map.hpp:348
struct PEAK_CATEGORY_NODE * PEAK_CATEGORY_NODE_HANDLE
Definition: peak_backend.h:437
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_Node_ToRegisterNode(PEAK_NODE_HANDLE nodeHandle, PEAK_REGISTER_NODE_HANDLE *registerNodeHandle)
Casts the given node to a register node.
~ScopedNodeMapLock()
Definition: peak_node_map.hpp:404
PEAK_C_API PEAK_Node_ToCommandNode(PEAK_NODE_HANDLE nodeHandle, PEAK_COMMAND_NODE_HANDLE *commandNodeHandle)
Casts the given node to a command 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.
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition: peak_backend.h:409
PEAK_C_API PEAK_NodeMap_UpdateEventNodes(PEAK_NODE_MAP_HANDLE nodeMapHandle, PEAK_EVENT_HANDLE eventHandle)
Updates event information in the node map.
void PollNodes(int64_t elapsedTime_ms)
Polls all nodes having a polling time.
Definition: peak_node_map.hpp:354
ScopedNodeMapLock()=delete
PEAK_C_API PEAK_Node_ToEnumerationNode(PEAK_NODE_HANDLE nodeHandle, PEAK_ENUMERATION_NODE_HANDLE *enumerationNodeHandle)
Casts the given node to an enumeration node.
struct PEAK_NODE_MAP * PEAK_NODE_MAP_HANDLE
Definition: peak_backend.h:405
std::shared_ptr< NodeType > FindNode(const std::string &name)
Tries to find a node with the given name and type.
Definition: peak_node_map.hpp:156
struct PEAK_ENUMERATION_ENTRY_NODE * PEAK_ENUMERATION_ENTRY_NODE_HANDLE
Definition: peak_backend.h:445
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...
Definition: peak_backend.h:274
PEAK_C_API PEAK_Node_ToIntegerNode(PEAK_NODE_HANDLE nodeHandle, PEAK_INTEGER_NODE_HANDLE *integerNodeHandle)
Casts the given node to an integer node.
struct PEAK_ENUMERATION_NODE * PEAK_ENUMERATION_NODE_HANDLE
Definition: peak_backend.h:441
Definition: peak_backend.h:275
PEAK_C_API PEAK_NodeMap_Lock(PEAK_NODE_MAP_HANDLE nodeMapHandle)
Locks a recursive mutex on the NodeMap.
Definition: peak_backend.h:271
struct PEAK_BOOLEAN_NODE * PEAK_BOOLEAN_NODE_HANDLE
Definition: peak_backend.h:417
PEAK_C_API PEAK_Node_GetType(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_TYPE *type)
Asks the given node for its type.
Definition: peak_backend.h:317
struct PEAK_STRING_NODE * PEAK_STRING_NODE_HANDLE
Definition: peak_backend.h:429
bool HasNode(const std::string &name) const
Checks whether the node map contains a node with the given name.
Definition: peak_node_map.hpp:329
Definition: peak_backend.h:269
Definition: peak_backend.h:273
NodeType
Definition: peak_node.hpp:86
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_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.
struct PEAK_FLOAT_NODE * PEAK_FLOAT_NODE_HANDLE
Definition: peak_backend.h:425
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:116
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
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...
std::shared_ptr< nodes::Node > FindNode(const std::string &name)
Tries to find a node with the given name.
Definition: peak_node_map.hpp:336
PEAK_C_API PEAK_NodeMap_Unlock(PEAK_NODE_MAP_HANDLE nodeMapHandle)
Unlocks the recursive mutex on the NodeMap.
Definition: peak_backend.h:276
PEAK_C_API PEAK_Node_ToFloatNode(PEAK_NODE_HANDLE nodeHandle, PEAK_FLOAT_NODE_HANDLE *floatNodeHandle)
Casts the given node to a float node.
std::function< bool(const std::shared_ptr< const nodes::Node > &nodeToFilter)> NodeFilterFunction
Definition: peak_node_map.hpp:65
PEAK_C_API PEAK_Node_ToBooleanNode(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOLEAN_NODE_HANDLE *booleanNodeHandle)
Casts the given node to a boolean node.
PEAK_C_API PEAK_NodeMap_InvalidateNodes(PEAK_NODE_MAP_HANDLE nodeMapHandle)
Tells the given node map to invalidate its nodes.
void UpdateEventNodes(const std::unique_ptr< Event > &event)
Updates event information in the NodeMap.
Definition: peak_node_map.hpp:375
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:381
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.
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:388
struct PEAK_COMMAND_NODE * PEAK_COMMAND_NODE_HANDLE
Definition: peak_backend.h:421
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.
struct PEAK_REGISTER_NODE * PEAK_REGISTER_NODE_HANDLE
Definition: peak_backend.h:433
PEAK_C_API PEAK_Node_ToStringNode(PEAK_NODE_HANDLE nodeHandle, PEAK_STRING_NODE_HANDLE *stringNodeHandle)
Casts the given node to a string node.