15 #include <peak/dll_interface/peak_dll_interface_util.hpp> 16 #include <peak/generic/peak_t_callback_manager.hpp> 18 #include <type_traits> 111 struct NodeChangedCallbackContainer;
121 class Node :
public std::enable_shared_from_this<Node>
125 using ChangedCallback = std::function<void(const std::shared_ptr<Node>& changedNode)>;
132 Node& operator=(
const Node& other) =
delete;
134 Node& operator=(
Node&& other) =
delete;
145 std::string Name()
const;
196 bool IsCacheable()
const;
207 bool IsAccessStatusCacheable()
const;
218 bool IsStreamable()
const;
229 bool IsDeprecated()
const;
241 bool IsFeature()
const;
261 int64_t PollingTime()
const;
271 std::string ToolTip()
const;
281 std::string Description()
const;
304 std::shared_ptr<NodeMap> ParentNodeMap()
const;
319 std::shared_ptr<Node> FindInvalidatedNode(
const std::string& name)
const;
334 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
337 auto castedNode = std::dynamic_pointer_cast<
NodeType>(FindInvalidatedNode(name));
354 std::vector<std::shared_ptr<Node>> InvalidatedNodes()
const;
368 std::shared_ptr<Node> FindInvalidatingNode(
const std::string& name)
const;
383 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
386 auto castedNode = std::dynamic_pointer_cast<
NodeType>(FindInvalidatingNode(name));
403 std::vector<std::shared_ptr<Node>> InvalidatingNodes()
const;
417 std::shared_ptr<Node> FindSelectedNode(
const std::string& name)
const;
432 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
435 auto castedNode = std::dynamic_pointer_cast<
NodeType>(FindSelectedNode(name));
452 std::vector<std::shared_ptr<Node>> SelectedNodes()
const;
466 std::shared_ptr<Node> FindSelectingNode(
const std::string& name)
const;
481 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
484 auto castedNode = std::dynamic_pointer_cast<
NodeType>(FindSelectingNode(name));
501 std::vector<std::shared_ptr<Node>> SelectingNodes()
const;
536 struct NodeChangedCallbackContainer
538 std::shared_ptr<Node> _Node;
543 friend ClassCreator<Node>;
546 std::weak_ptr<NodeMap> m_parentNodeMap;
548 std::unique_ptr<TCallbackManager<PEAK_NODE_CHANGED_CALLBACK_HANDLE, NodeChangedCallbackContainer>>
549 m_changedCallbackManager;
554 return QueryStringFromCInterfaceFunction([&](
char* nodeName,
size_t* nodeNameSize) {
575 std::string entryString;
579 entryString =
"NotImplemented";
583 entryString =
"NotAvailable";
587 entryString =
"WriteOnly";
591 entryString =
"ReadOnly";
595 entryString =
"ReadWrite";
603 std::string entryString;
607 entryString =
"NoCache";
611 entryString =
"WriteThrough";
615 entryString =
"WriteAround";
623 std::string entryString;
627 entryString =
"Custom";
631 entryString =
"Standard";
639 std::string entryString;
643 entryString =
"Integer";
647 entryString =
"Boolean";
651 entryString =
"Command";
655 entryString =
"Float";
659 entryString =
"String";
663 entryString =
"Register";
667 entryString =
"Category";
671 entryString =
"Enumeration";
675 entryString =
"EnumerationEntry";
683 std::string entryString;
687 entryString =
"Beginner";
691 entryString =
"Expert";
695 entryString =
"Guru";
699 entryString =
"Invisible";
707 : m_backendHandle(nodeHandle)
708 , m_parentNodeMap(parentNodeMap)
709 , m_changedCallbackManager()
711 m_changedCallbackManager =
712 std::make_unique<TCallbackManager<PEAK_NODE_CHANGED_CALLBACK_HANDLE, NodeChangedCallbackContainer>>(
713 [&](
void* callbackContext) {
714 return QueryNumericFromCInterfaceFunction<PEAK_NODE_CHANGED_CALLBACK_HANDLE>(
717 m_backendHandle, ChangedCallbackCWrapper, callbackContext, nodeChangedCallbackHandle);
721 CallAndCheckCInterfaceFunction([&] {
730 m_changedCallbackManager->UnregisterAllCallbacks();
740 return QueryStringFromCInterfaceFunction([&](
char* displayName,
size_t* displayNameSize) {
748 QueryNumericFromCInterfaceFunction<PEAK_NODE_NAMESPACE>([&](
PEAK_NODE_NAMESPACE* _namespace) {
756 QueryNumericFromCInterfaceFunction<PEAK_NODE_VISIBILITY>([&](
PEAK_NODE_VISIBILITY* visibility) {
771 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isCacheable) {
778 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isAccessStatusCacheable) {
785 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isStreamable) {
792 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isDeprecated) {
799 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isFeature) {
814 return QueryNumericFromCInterfaceFunction<int64_t>([&](int64_t* pollingTime_ms) {
821 return QueryStringFromCInterfaceFunction([&](
char* toolTip,
size_t* toolTipSize) {
828 return QueryStringFromCInterfaceFunction([&](
char* description,
size_t* descriptionSize) {
835 return static_cast<NodeType>(QueryNumericFromCInterfaceFunction<PEAK_NODE_TYPE>(
841 return LockOrThrow(m_parentNodeMap);
846 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
848 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
853 return ParentNodeMap()->FindNode(name);
858 auto numInvalidatedNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numInvalidatedNodes) {
862 std::vector<std::shared_ptr<Node>> invalidatedNodes;
863 for (
size_t x = 0; x < numInvalidatedNodes; ++x)
865 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
872 invalidatedNodes.emplace_back(ParentNodeMap()->FindNode(nodeName));
875 return invalidatedNodes;
880 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
882 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
887 return ParentNodeMap()->FindNode(name);
892 auto numInvalidatingNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numInvalidatedNodes) {
896 std::vector<std::shared_ptr<Node>> invalidatingNodes;
897 for (
size_t x = 0; x < numInvalidatingNodes; ++x)
899 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
906 invalidatingNodes.emplace_back(ParentNodeMap()->FindNode(nodeName));
909 return invalidatingNodes;
914 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
916 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
921 return ParentNodeMap()->FindNode(name);
926 auto numSelectedNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numSelectedNodes) {
930 std::vector<std::shared_ptr<Node>> selectedNodes;
931 for (
size_t x = 0; x < numSelectedNodes; ++x)
933 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
940 selectedNodes.emplace_back(ParentNodeMap()->FindNode(nodeName));
943 return selectedNodes;
948 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
950 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
955 return ParentNodeMap()->FindNode(name);
960 auto numSelectingNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numSelectingNodes) {
964 std::vector<std::shared_ptr<Node>> selectingNodes;
965 for (
size_t x = 0; x < numSelectingNodes; ++x)
967 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
974 selectingNodes.emplace_back(ParentNodeMap()->FindNode(nodeName));
977 return selectingNodes;
983 m_changedCallbackManager->RegisterCallback(NodeChangedCallbackContainer{ shared_from_this(), callback }));
988 m_changedCallbackManager->UnregisterCallback(
989 reinterpret_cast<PEAK_NODE_CHANGED_CALLBACK_HANDLE>(callbackHandle));
994 auto callbackContainer =
static_cast<NodeChangedCallbackContainer*
>(context);
996 callbackContainer->Callback(callbackContainer->_Node);
PEAK_C_API PEAK_Node_GetNumSelectedNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numSelectedNodes)
Asks the given node for its number of selected nodes.
std::shared_ptr< Node > FindSelectingNode(const std::string &name) const
Tries to find a selecting node with the given name.
Definition: peak_node.hpp:946
std::vector< std::shared_ptr< Node > > InvalidatingNodes() const
Returns the invalidating nodes.
Definition: peak_node.hpp:890
ChangedCallback * ChangedCallbackHandle
Definition: peak_node.hpp:127
int32_t PEAK_NODE_CACHING_MODE
Definition: peak_backend.h:217
PEAK_C_API PEAK_Node_FindInvalidatingNode(PEAK_NODE_HANDLE nodeHandle, const char *name, size_t nameSize, PEAK_NODE_HANDLE *invalidatingNodeHandle)
Tells the given node to find an invalidating node with the given name.
bool IsDeprecated() const
Checks whether the node is deprecated.
Definition: peak_node.hpp:790
PEAK_C_API PEAK_Node_GetCachingMode(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_CACHING_MODE *cachingMode)
Asks the given node for its caching mode.
PEAK_C_API PEAK_Node_GetIsDeprecated(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isDeprecated)
Asks the given node whether it is deprecated.
bool IsCacheable() const
Checks whether the node is cacheable.
Definition: peak_node.hpp:769
PEAK_C_API PEAK_Node_FindSelectingNode(PEAK_NODE_HANDLE nodeHandle, const char *name, size_t nameSize, PEAK_NODE_HANDLE *selectingNodeHandle)
Tells the given node to find a selecting node with the given name.
NodeNamespace Namespace() const
Returns the namespace the node belongs to.
Definition: peak_node.hpp:745
int8_t PEAK_BOOL8
Definition: peak_backend.h:26
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
PEAK_C_API PEAK_Node_GetIsFeature(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isFeature)
Asks the given node whether it is a feature, i.e. it can be reached via category nodes from a categor...
The exception thrown for trying to apply an invalid cast.
Definition: peak_exception.hpp:81
std::string Description() const
Returns the description.
Definition: peak_node.hpp:826
std::string DisplayName() const
Returns the display name.
Definition: peak_node.hpp:738
PEAK_C_API PEAK_Node_GetIsStreamable(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isStreamable)
Asks the given node whether it is streamable.
std::shared_ptr< Node > FindInvalidatingNode(const std::string &name) const
Tries to find an invalidating node with the given name.
Definition: peak_node.hpp:878
PEAK_C_API PEAK_Node_GetPollingTime(PEAK_NODE_HANDLE nodeHandle, int64_t *pollingTime_ms)
Asks the given node for its polling time.
virtual ~Node()
Definition: peak_node.hpp:728
int32_t PEAK_NODE_VISIBILITY
Definition: peak_backend.h:289
PEAK_C_API PEAK_Node_FindInvalidatedNode(PEAK_NODE_HANDLE nodeHandle, const char *name, size_t nameSize, PEAK_NODE_HANDLE *invalidatedNodeHandle)
Tells the given node to find an invalidated node with the given name.
std::shared_ptr< NodeType > FindSelectedNode(const std::string &name) const
Tries to find a selected node with the given name and type.
Definition: peak_node.hpp:433
PEAK_C_API PEAK_Node_GetNumSelectingNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numSelectingNodes)
Asks the given node for its number of selecting nodes.
std::vector< std::shared_ptr< Node > > InvalidatedNodes() const
Returns the invalidated nodes.
Definition: peak_node.hpp:856
std::function< void(const std::shared_ptr< Node > &changedNode)> ChangedCallback
Definition: peak_node.hpp:125
NodeVisibility
Definition: peak_node.hpp:102
std::shared_ptr< NodeType > FindInvalidatedNode(const std::string &name) const
Tries to find an invalidated node with the given name and type.
Definition: peak_node.hpp:335
std::string ToolTip() const
Returns the tool tip.
Definition: peak_node.hpp:819
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition: peak_backend.h:409
PEAK_C_API PEAK_Node_FindSelectedNode(PEAK_NODE_HANDLE nodeHandle, const char *name, size_t nameSize, PEAK_NODE_HANDLE *selectedNodeHandle)
Tells the given node to find a selected node with the given name.
PEAK_C_API PEAK_Node_RegisterChangedCallback(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_CHANGED_CALLBACK callback, void *callbackContext, PEAK_NODE_CHANGED_CALLBACK_HANDLE *callbackHandle)
Registers a callback signaling a change at the given node.
std::string ToString(NodeCacheUsePolicy entry)
Definition: peak_common_node_enums.hpp:54
PEAK_C_API PEAK_Node_GetSelectingNode(PEAK_NODE_HANDLE nodeHandle, size_t index, PEAK_NODE_HANDLE *selectingNodeHandle)
Asks the given node for the selecting node with the given index.
int32_t PEAK_NODE_NAMESPACE
Definition: peak_backend.h:251
PEAK_C_API PEAK_Node_GetNumInvalidatedNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numInvalidatedNodes)
Asks the given node for its number of invalidated nodes.
std::string Name() const
Returns the name.
Definition: peak_node.hpp:733
PEAK_C_API PEAK_Node_GetNamespace(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_NAMESPACE *_namespace)
Asks the given node for its namespace.
PEAK_C_API PEAK_Node_GetDisplayName(PEAK_NODE_HANDLE nodeHandle, char *displayName, size_t *displayNameSize)
Asks the given node for its display name.
PEAK_C_API PEAK_Node_GetNumInvalidatingNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numInvalidatingNodes)
Asks the given node for its number of invalidating nodes.
void UnregisterChangedCallback(ChangedCallbackHandle callbackHandle)
Unregisters a changed callback.
Definition: peak_node.hpp:986
std::shared_ptr< NodeType > FindSelectingNode(const std::string &name) const
Tries to find a selecting node with the given name and type.
Definition: peak_node.hpp:482
std::vector< std::shared_ptr< Node > > SelectingNodes() const
Returns the selecting nodes.
Definition: peak_node.hpp:958
std::shared_ptr< NodeType > FindInvalidatingNode(const std::string &name) const
Tries to find an invalidating node with the given name and type.
Definition: peak_node.hpp:384
PEAK_C_API PEAK_Node_GetType(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_TYPE *type)
Asks the given node for its type.
NodeCachingMode
Definition: peak_node.hpp:57
int64_t PollingTime() const
Returns the polling time.
Definition: peak_node.hpp:812
int32_t PEAK_NODE_ACCESS_STATUS
Definition: peak_backend.h:208
NodeAccessStatus AccessStatus() const
Returns the access status.
Definition: peak_node.hpp:761
std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition: peak_node.hpp:839
PEAK_NODE_CHANGED_CALLBACK * PEAK_NODE_CHANGED_CALLBACK_HANDLE
Definition: peak_backend.h:508
NodeType
Definition: peak_node.hpp:86
PEAK_C_API PEAK_Node_GetVisibility(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_VISIBILITY *visibility)
Asks the given node for its visibility.
PEAK_C_API PEAK_Node_GetAccessStatus(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_ACCESS_STATUS *accessStatus)
Asks the given node for its access status.
NodeCachingMode CachingMode() const
Returns the caching mode.
Definition: peak_node.hpp:804
PEAK_C_API PEAK_Node_GetInvalidatingNode(PEAK_NODE_HANDLE nodeHandle, size_t index, PEAK_NODE_HANDLE *invalidatingNodeHandle)
Asks the given node for the invalidating node with the given index.
PEAK_C_API PEAK_Node_GetName(PEAK_NODE_HANDLE nodeHandle, char *name, size_t *nameSize)
Asks the given node for its name.
std::vector< std::shared_ptr< Node > > SelectedNodes() const
Returns the selected nodes.
Definition: peak_node.hpp:924
#define PEAK_CALL_CONV
Definition: peak_dynamic_loader.h:29
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
NodeNamespace
Definition: peak_node.hpp:77
std::shared_ptr< Node > FindInvalidatedNode(const std::string &name) const
Tries to find an invalidated node with the given name.
Definition: peak_node.hpp:844
std::shared_ptr< Node > FindSelectedNode(const std::string &name) const
Tries to find a selected node with the given name.
Definition: peak_node.hpp:912
ChangedCallbackHandle RegisterChangedCallback(const ChangedCallback &callback)
Registers a callback for signaling a change to the node.
Definition: peak_node.hpp:980
NodeType Type() const
Returns the type.
Definition: peak_node.hpp:833
bool IsStreamable() const
Checks whether the node is streamable.
Definition: peak_node.hpp:783
PEAK_C_API PEAK_Node_GetSelectedNode(PEAK_NODE_HANDLE nodeHandle, size_t index, PEAK_NODE_HANDLE *selectedNodeHandle)
Asks the given node for the selected node with the given index.
PEAK_C_API PEAK_Node_GetDescription(PEAK_NODE_HANDLE nodeHandle, char *description, size_t *descriptionSize)
Asks the given node for its description.
PEAK_C_API PEAK_Node_GetToolTip(PEAK_NODE_HANDLE nodeHandle, char *toolTip, size_t *toolTipSize)
Asks the given node for its tooltip.
PEAK_C_API PEAK_Node_GetIsAccessStatusCacheable(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isAccessStatusCacheable)
Asks the given node whether its access status is cacheable.
Represents a GenAPI node.
Definition: peak_node.hpp:121
std::string GetNodeName(PEAK_NODE_HANDLE nodeHandle)
Definition: peak_node.hpp:552
bool IsAccessStatusCacheable() const
Checks whether the node's access status is cacheable.
Definition: peak_node.hpp:776
PEAK_C_API PEAK_Node_UnregisterChangedCallback(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_CHANGED_CALLBACK_HANDLE callbackHandle)
Unregisters the changed callback with the given handle from the given node.
bool IsFeature() const
Checks whether the node is a feature, i.e. it can be reached via category nodes from a category node ...
Definition: peak_node.hpp:797
PEAK_C_API PEAK_Node_GetInvalidatedNode(PEAK_NODE_HANDLE nodeHandle, size_t index, PEAK_NODE_HANDLE *invalidatedNodeHandle)
Asks the given node for the invalidated node with the given index.
PEAK_C_API PEAK_Node_GetIsCacheable(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isCacheable)
Asks the given node whether it is cacheable.
NodeVisibility Visibility() const
Returns the visibility.
Definition: peak_node.hpp:753
NodeAccessStatus
Definition: peak_node.hpp:44