IDS peak genericC++  v1.4.0
peak_command_node.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
16 #include <peak/dll_interface/peak_dll_interface_util.hpp>
19 
20 
21 namespace peak
22 {
23 namespace core
24 {
25 namespace nodes
26 {
27 
32 class CommandNode : public Node
33 {
34 public:
35  CommandNode() = delete;
36  ~CommandNode() override = default;
37  CommandNode(const CommandNode& other) = delete;
38  CommandNode& operator=(const CommandNode& other) = delete;
39  CommandNode(CommandNode&& other) = delete;
40  CommandNode& operator=(CommandNode&& other) = delete;
41 
52  bool IsDone() const;
53 
61  void Execute();
62 
73  void WaitUntilDone(Timeout waitTimeout_ms = 500);
74 
75 
76 private:
77  friend ClassCreator<CommandNode>;
78  CommandNode(PEAK_COMMAND_NODE_HANDLE commandNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
79  PEAK_COMMAND_NODE_HANDLE m_backendHandle;
80 };
81 
82 } /* namespace nodes */
83 } /* namespace core */
84 } /* namespace peak */
85 
86 /* Implementation */
87 namespace peak
88 {
89 namespace core
90 {
91 namespace nodes
92 {
93 
95  PEAK_COMMAND_NODE_HANDLE commandNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
96  : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
97  return PEAK_C_ABI_PREFIX PEAK_CommandNode_ToNode(commandNodeHandle, nodeHandle);
98  }),
99  parentNodeMap)
100  , m_backendHandle(commandNodeHandle)
101 {}
102 
103 inline bool CommandNode::IsDone() const
104 {
105  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isDone) {
106  return PEAK_C_ABI_PREFIX PEAK_CommandNode_GetIsDone(m_backendHandle, isDone);
107  }) > 0;
108 }
109 inline void CommandNode::Execute()
110 {
111  CallAndCheckCInterfaceFunction([&] { return PEAK_C_ABI_PREFIX PEAK_CommandNode_Execute(m_backendHandle); });
112 }
113 
114 inline void CommandNode::WaitUntilDone(Timeout waitTimeout_ms /*= 500*/)
115 {
116  CallAndCheckCInterfaceFunction(
117  [&] { return PEAK_C_ABI_PREFIX PEAK_CommandNode_WaitUntilDone(m_backendHandle, waitTimeout_ms); });
118 }
119 
120 } /* namespace nodes */
121 } /* namespace core */
122 } /* namespace peak */
CommandNode & operator=(const CommandNode &other)=delete
int8_t PEAK_BOOL8
Definition: peak_backend.h:26
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
PEAK_C_API PEAK_CommandNode_WaitUntilDone(PEAK_COMMAND_NODE_HANDLE commandNodeHandle, uint64_t waitTimeout_ms)
Waits (blocking) until the previously executed command is finished, i.e. PEAK_CommandNode_GetIsDone()...
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition: peak_backend.h:409
void WaitUntilDone(Timeout waitTimeout_ms=500)
(Blocking) Wait for the executed command to be finished, i.e. until IsDone() is true.
Definition: peak_command_node.hpp:114
void Execute()
Executes the command associated with this node.
Definition: peak_command_node.hpp:109
~CommandNode() override=default
Represents a timeout value in milliseconds.
Definition: peak_timeout.hpp:30
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
bool IsDone() const
Checks whether the command is done.
Definition: peak_command_node.hpp:103
Represents a GenAPI command node.
Definition: peak_command_node.hpp:32
PEAK_C_API PEAK_CommandNode_GetIsDone(PEAK_COMMAND_NODE_HANDLE commandNodeHandle, PEAK_BOOL8 *isDone)
Asks the given command node whether its associated command is done.
struct PEAK_COMMAND_NODE * PEAK_COMMAND_NODE_HANDLE
Definition: peak_backend.h:421
Represents a GenAPI node.
Definition: peak_node.hpp:121
PEAK_C_API PEAK_CommandNode_Execute(PEAK_COMMAND_NODE_HANDLE commandNodeHandle)
Tells the given command node to execute its associated command.
PEAK_C_API PEAK_CommandNode_ToNode(PEAK_COMMAND_NODE_HANDLE commandNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given command node to a node.