12#include <peak/dll_interface/peak_dll_interface_util.hpp>
13#include <peak/generic/peak_t_callback_manager.hpp>
113struct NodeChangedCallbackContainer;
124class Node :
public std::enable_shared_from_this<Node>
128 using ChangedCallback = std::function<void(
const std::shared_ptr<Node>& changedNode)>;
410 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
475 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
532 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
535 auto castedNode = std::dynamic_pointer_cast<NodeType>(
FindSelectedNode(name));
584 template <class NodeType, typename std::enable_if<std::is_base_of<Node, NodeType>::value,
int>::type = 0>
641 struct NodeChangedCallbackContainer
643 std::shared_ptr<Node> _Node;
646 static void PEAK_CALL_CONV ChangedCallbackCWrapper(
PEAK_NODE_HANDLE,
void* context);
648 friend ClassCreator<Node>;
651 std::weak_ptr<NodeMap> m_parentNodeMap;
653 std::unique_ptr<TCallbackManager<PEAK_NODE_CHANGED_CALLBACK_HANDLE, NodeChangedCallbackContainer>>
654 m_changedCallbackManager;
659 return QueryStringFromCInterfaceFunction([&](
char* nodeName,
size_t* nodeNameSize) {
680 std::string entryString;
684 entryString =
"NotImplemented";
688 entryString =
"NotAvailable";
692 entryString =
"WriteOnly";
696 entryString =
"ReadOnly";
700 entryString =
"ReadWrite";
708 std::string entryString;
712 entryString =
"NoCache";
716 entryString =
"WriteThrough";
720 entryString =
"WriteAround";
728 std::string entryString;
732 entryString =
"Custom";
736 entryString =
"Standard";
744 std::string entryString;
748 entryString =
"Integer";
752 entryString =
"Boolean";
756 entryString =
"Command";
760 entryString =
"Float";
764 entryString =
"String";
768 entryString =
"Register";
772 entryString =
"Category";
776 entryString =
"Enumeration";
780 entryString =
"EnumerationEntry";
788 std::string entryString;
792 entryString =
"Beginner";
796 entryString =
"Expert";
800 entryString =
"Guru";
804 entryString =
"Invisible";
812 : m_backendHandle(nodeHandle)
813 , m_parentNodeMap(parentNodeMap)
814 , m_changedCallbackManager()
816 m_changedCallbackManager =
817 std::make_unique<TCallbackManager<PEAK_NODE_CHANGED_CALLBACK_HANDLE, NodeChangedCallbackContainer>>(
818 [&](
void* callbackContext) {
819 return QueryNumericFromCInterfaceFunction<PEAK_NODE_CHANGED_CALLBACK_HANDLE>(
822 m_backendHandle, ChangedCallbackCWrapper, callbackContext, nodeChangedCallbackHandle);
826 CallAndCheckCInterfaceFunction([&] {
835 m_changedCallbackManager->UnregisterAllCallbacks();
845 return QueryStringFromCInterfaceFunction([&](
char* displayName,
size_t* displayNameSize) {
853 QueryNumericFromCInterfaceFunction<PEAK_NODE_NAMESPACE>([&](
PEAK_NODE_NAMESPACE* _namespace) {
861 QueryNumericFromCInterfaceFunction<PEAK_NODE_VISIBILITY>([&](
PEAK_NODE_VISIBILITY* visibility) {
901 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isCacheable) {
908 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isAccessStatusCacheable) {
915 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isStreamable) {
922 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isDeprecated) {
929 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isFeature) {
944 return QueryNumericFromCInterfaceFunction<int64_t>([&](int64_t* pollingTime_ms) {
951 return QueryStringFromCInterfaceFunction([&](
char* toolTip,
size_t* toolTipSize) {
958 return QueryStringFromCInterfaceFunction([&](
char* description,
size_t* descriptionSize) {
965 return static_cast<NodeType>(QueryNumericFromCInterfaceFunction<PEAK_NODE_TYPE>(
971 return LockOrThrow(m_parentNodeMap);
976 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
978 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
988 auto numInvalidatedNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numInvalidatedNodes) {
992 std::vector<std::shared_ptr<Node>> invalidatedNodes;
993 for (
size_t x = 0; x < numInvalidatedNodes; ++x)
995 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
1002 invalidatedNodes.emplace_back(
ParentNodeMap()->FindNode(nodeName));
1005 return invalidatedNodes;
1010 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
1012 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
1022 auto numInvalidatingNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numInvalidatedNodes) {
1026 std::vector<std::shared_ptr<Node>> invalidatingNodes;
1027 for (
size_t x = 0; x < numInvalidatingNodes; ++x)
1029 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
1036 invalidatingNodes.emplace_back(
ParentNodeMap()->FindNode(nodeName));
1039 return invalidatingNodes;
1044 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
1046 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
1056 auto numSelectedNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numSelectedNodes) {
1060 std::vector<std::shared_ptr<Node>> selectedNodes;
1061 for (
size_t x = 0; x < numSelectedNodes; ++x)
1063 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
1070 selectedNodes.emplace_back(
ParentNodeMap()->FindNode(nodeName));
1073 return selectedNodes;
1078 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](
PEAK_NODE_HANDLE* _nodeHandle) {
1080 m_backendHandle, name.c_str(), name.size() + 1, _nodeHandle);
1090 auto numSelectingNodes = QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* _numSelectingNodes) {
1094 std::vector<std::shared_ptr<Node>> selectingNodes;
1095 for (
size_t x = 0; x < numSelectingNodes; ++x)
1097 auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
1104 selectingNodes.emplace_back(
ParentNodeMap()->FindNode(nodeName));
1107 return selectingNodes;
1113 m_changedCallbackManager->RegisterCallback(NodeChangedCallbackContainer{ shared_from_this(), callback }));
1118 m_changedCallbackManager->UnregisterCallback(
1122inline void PEAK_CALL_CONV Node::ChangedCallbackCWrapper(
PEAK_NODE_HANDLE,
void* context)
1124 auto callbackContainer =
static_cast<NodeChangedCallbackContainer*
>(context);
1126 callbackContainer->Callback(callbackContainer->_Node);
The exception thrown for trying to apply an invalid cast.
Definition peak_exception.hpp:146
Represents a GenAPI node map.
Definition peak_node_map.hpp:60
PEAK_COMMON_NO_DISCARD NodeType Type() const
Returns the type.
Definition peak_node.hpp:963
PEAK_COMMON_NO_DISCARD ChangedCallbackHandle RegisterChangedCallback(const ChangedCallback &callback)
Registers a callback for signaling a change to the node.
Definition peak_node.hpp:1110
std::function< void(const std::shared_ptr< Node > &changedNode)> ChangedCallback
Definition peak_node.hpp:128
PEAK_COMMON_NO_DISCARD 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:927
PEAK_COMMON_NO_DISCARD 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:533
PEAK_COMMON_NO_DISCARD bool IsDeprecated() const
Checks whether the node is deprecated.
Definition peak_node.hpp:920
PEAK_COMMON_NO_DISCARD std::string ToolTip() const
Returns the tool tip.
Definition peak_node.hpp:949
PEAK_COMMON_NO_DISCARD std::vector< std::shared_ptr< Node > > SelectedNodes() const
Returns the selected nodes.
Definition peak_node.hpp:1054
PEAK_COMMON_NO_DISCARD std::string DisplayName() const
Returns the display name.
Definition peak_node.hpp:843
Node & operator=(const Node &other)=delete
PEAK_COMMON_NO_DISCARD NodeNamespace Namespace() const
Returns the namespace the node belongs to.
Definition peak_node.hpp:850
Node & operator=(Node &&other)=delete
PEAK_COMMON_NO_DISCARD bool IsWriteable() const
Returns whether the node is currently writeable.
Definition peak_node.hpp:880
PEAK_COMMON_NO_DISCARD std::shared_ptr< Node > FindSelectingNode(const std::string &name) const
Tries to find a selecting node with the given name.
Definition peak_node.hpp:1076
PEAK_COMMON_NO_DISCARD std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition peak_node.hpp:969
PEAK_COMMON_NO_DISCARD std::string Name() const
Returns the name.
Definition peak_node.hpp:838
PEAK_COMMON_NO_DISCARD 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:476
PEAK_COMMON_NO_DISCARD int64_t PollingTime() const
Returns the polling time.
Definition peak_node.hpp:942
PEAK_COMMON_NO_DISCARD std::shared_ptr< Node > FindInvalidatingNode(const std::string &name) const
Tries to find an invalidating node with the given name.
Definition peak_node.hpp:1008
PEAK_COMMON_NO_DISCARD std::vector< std::shared_ptr< Node > > InvalidatingNodes() const
Returns the invalidating nodes.
Definition peak_node.hpp:1020
virtual ~Node()
Definition peak_node.hpp:833
PEAK_COMMON_NO_DISCARD NodeVisibility Visibility() const
Returns the visibility.
Definition peak_node.hpp:858
PEAK_COMMON_NO_DISCARD bool IsAccessStatusCacheable() const
Checks whether the node's access status is cacheable.
Definition peak_node.hpp:906
PEAK_COMMON_NO_DISCARD bool IsReadable() const
Returns whether the node is currently readable.
Definition peak_node.hpp:874
PEAK_COMMON_NO_DISCARD std::shared_ptr< Node > FindSelectedNode(const std::string &name) const
Tries to find a selected node with the given name.
Definition peak_node.hpp:1042
PEAK_COMMON_NO_DISCARD std::vector< std::shared_ptr< Node > > InvalidatedNodes() const
Returns the invalidated nodes.
Definition peak_node.hpp:986
PEAK_COMMON_NO_DISCARD std::vector< std::shared_ptr< Node > > SelectingNodes() const
Returns the selecting nodes.
Definition peak_node.hpp:1088
PEAK_COMMON_NO_DISCARD 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:411
PEAK_COMMON_NO_DISCARD bool IsCacheable() const
Checks whether the node is cacheable.
Definition peak_node.hpp:899
PEAK_COMMON_NO_DISCARD 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:585
PEAK_COMMON_NO_DISCARD std::string Description() const
Returns the description.
Definition peak_node.hpp:956
PEAK_COMMON_NO_DISCARD bool IsStreamable() const
Checks whether the node is streamable.
Definition peak_node.hpp:913
Node(Node &&other)=delete
PEAK_COMMON_NO_DISCARD bool IsImplemented() const
Returns whether the node is implemented.
Definition peak_node.hpp:892
PEAK_COMMON_NO_DISCARD bool IsAvailable() const
Returns whether the node is currently either readable or writeable.
Definition peak_node.hpp:886
PEAK_COMMON_NO_DISCARD NodeCachingMode CachingMode() const
Returns the caching mode.
Definition peak_node.hpp:934
PEAK_COMMON_NO_DISCARD std::shared_ptr< Node > FindInvalidatedNode(const std::string &name) const
Tries to find an invalidated node with the given name.
Definition peak_node.hpp:974
ChangedCallback * ChangedCallbackHandle
Definition peak_node.hpp:130
PEAK_COMMON_NO_DISCARD NodeAccessStatus AccessStatus() const
Returns the access status.
Definition peak_node.hpp:866
void UnregisterChangedCallback(ChangedCallbackHandle callbackHandle)
Unregisters a changed callback.
Definition peak_node.hpp:1116
Node(const Node &other)=delete
@ AccessStatus
Definition peak_device_descriptor.hpp:58
NodeVisibility
Definition peak_node.hpp:105
NodeType
Definition peak_node.hpp:88
NodeNamespace
Definition peak_node.hpp:78
NodeCachingMode
Definition peak_node.hpp:57
NodeAccessStatus
Definition peak_node.hpp:43
@ Expert
Definition peak_node.hpp:107
@ Beginner
Definition peak_node.hpp:106
@ Guru
Definition peak_node.hpp:108
@ Invisible
Definition peak_node.hpp:109
@ Register
Definition peak_node.hpp:94
@ Float
Definition peak_node.hpp:92
@ String
Definition peak_node.hpp:93
@ Boolean
Definition peak_node.hpp:90
@ Enumeration
Definition peak_node.hpp:96
@ Category
Definition peak_node.hpp:95
@ Integer
Definition peak_node.hpp:89
@ EnumerationEntry
Definition peak_node.hpp:97
@ Command
Definition peak_node.hpp:91
@ Custom
Definition peak_node.hpp:79
@ Standard
Definition peak_node.hpp:80
@ NoCache
Definition peak_node.hpp:61
@ WriteAround
Definition peak_node.hpp:69
@ WriteThrough
Definition peak_node.hpp:65
@ ReadOnly
Definition peak_node.hpp:47
@ NotAvailable
Definition peak_node.hpp:45
@ WriteOnly
Definition peak_node.hpp:46
@ ReadWrite
Definition peak_node.hpp:48
@ NotImplemented
Definition peak_node.hpp:44
@ Boolean
Definition peak_common_node_enums.hpp:62
The "nodes" namespace contains all GenAPI node types.
Definition peak_utils.hpp:31
PEAK_COMMON_NO_DISCARD std::string ToString(NodeCacheUsePolicy entry)
Definition peak_common_node_enums.hpp:69
std::string GetNodeName(PEAK_NODE_HANDLE nodeHandle)
Definition peak_node.hpp:657
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_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...
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_GetToolTip(PEAK_NODE_HANDLE nodeHandle, char *toolTip, size_t *toolTipSize)
Asks the given node for its tooltip.
PEAK_C_API PEAK_Node_GetCachingMode(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_CACHING_MODE *cachingMode)
Asks the given node for its caching mode.
PEAK_NODE_CHANGED_CALLBACK * PEAK_NODE_CHANGED_CALLBACK_HANDLE
Definition peak_backend.h:580
PEAK_C_API PEAK_Node_GetNumSelectedNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numSelectedNodes)
Asks the given node for its number of selected nodes.
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.
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition peak_backend.h:427
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_GetNumSelectingNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numSelectingNodes)
Asks the given node for its number of selecting nodes.
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.
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_ACCESS_STATUS
Definition peak_backend.h:223
int32_t PEAK_NODE_TYPE
Definition peak_backend.h:294
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.
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.
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_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.
PEAK_C_API PEAK_Node_GetName(PEAK_NODE_HANDLE nodeHandle, char *name, size_t *nameSize)
Asks the given node for its name.
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_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_GetNumInvalidatingNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numInvalidatingNodes)
Asks the given node for its number of invalidating nodes.
int8_t PEAK_BOOL8
Definition peak_backend.h:41
int32_t PEAK_NODE_CACHING_MODE
Definition peak_backend.h:232
PEAK_C_API PEAK_Node_GetNumInvalidatedNodes(PEAK_NODE_HANDLE nodeHandle, size_t *numInvalidatedNodes)
Asks the given node for its number of invalidated nodes.
PEAK_C_API PEAK_Node_GetIsDeprecated(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isDeprecated)
Asks the given node whether it is deprecated.
PEAK_C_API PEAK_Node_GetIsStreamable(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isStreamable)
Asks the given node whether it is streamable.
PEAK_C_API PEAK_Node_GetAccessStatus(PEAK_NODE_HANDLE nodeHandle, PEAK_NODE_ACCESS_STATUS *accessStatus)
Asks the given node for its access status.
PEAK_C_API PEAK_Node_GetIsCacheable(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isCacheable)
Asks the given node whether it is cacheable.
int32_t PEAK_NODE_NAMESPACE
Definition peak_backend.h:266
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_GetPollingTime(PEAK_NODE_HANDLE nodeHandle, int64_t *pollingTime_ms)
Asks the given node for its polling time.
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_GetIsAccessStatusCacheable(PEAK_NODE_HANDLE nodeHandle, PEAK_BOOL8 *isAccessStatusCacheable)
Asks the given node whether its access status is cacheable.
int32_t PEAK_NODE_VISIBILITY
Definition peak_backend.h:304
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.
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:13