CVB++ 15.0
command_node.hpp
1#pragma once
2
3#include <cctype>
4
5#include "../global.hpp"
6
7#include "integer_base_node.hpp"
8#include "value_node.hpp"
9
11#include "_detail/iconfigurable_command_node.hpp"
12#include "_detail/ihas_value_config.hpp"
13#include "_detail/iconfigurable_register_node.hpp"
15
16namespace Cvb
17{
18 CVB_BEGIN_INLINE_NS
19 namespace GevServer
20 {
22
24 class CommandNode
25 : public ValueNode
27 , public Private::IConfigurableCommandNode
28 , public Private::IHasValueConfig<IntegerBaseNodePtr>
30 {
31 public:
32 explicit CommandNode(HandleGuard<Node> &&guard)
33 : ValueNode(std::move(guard))
34 {
35 }
36
47 static CommandNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
48 {
49 String okName = EnsureNodeNameOnly(name);
51 HandleGuard<Node>(CreateGSCommandNodeTyped(okName.data(), static_cast<CExports::TGSNamespace>(nameSpace))));
52 }
53
67 static CommandNodePtr Create(const String &name)
68 {
69 return Create(ParseName(name), ParseNamespace(name));
70 }
71
77 {
79 this, [](Node *node) { return dynamic_cast<Private::IConfigurableRegisterNode *>(node) ? true : false; });
80 if (value == nullptr)
82 else
83 return value->AccessMode();
84 }
85
91 {
93 this, [](Node *node) { return dynamic_cast<Private::IConfigurableRegisterNode *>(node) ? true : false; });
94 if (value == nullptr)
96 else
97 return value->CacheMode();
98 }
99
103 bool IsStreamable() const override
104 {
105 return false;
106 }
107
108 [[noreturn]] void SetIsStreamable(const CExports::cvbint64_t & /*value*/) override
109 {
110 throw std::runtime_error("Command nodes cannot be streamed");
111 }
112
116 bool IsDone() const
117 {
118 return (NativeCall<CExports::cvbbool_t>(
119 [&](CExports::cvbbool_t &value) { return CVB_CALL_CAPI(GSNGetAsBoolean(Handle(), value)); }))
120 ? true
121 : false;
122 }
123
127 void Execute()
128 {
129 NativeCall([&]() { return CVB_CALL_CAPI(GSNSetAsBoolean(Handle(), true)); });
130 }
131
139 template <class Rep, class Period>
141 {
142 auto timespan = GetInfoAsInt(NodeInfo::PollingTime);
143 if (timespan > 0)
144 return std::chrono::duration<Rep, Period>(timespan);
145 else
147 }
148
156 template <class Rep, class Period>
158 {
160 SetInfoAsInt(NodeInfo::PollingTime, -1);
161 else
163 }
164
174 template <class T>
176 {
177 throw std::runtime_error(
178 "requested command config type must be derived from IntegerBaseNode or "
179 "of integral type");
180 }
181
195 template <class T>
196 void SetCommandConfig(const T & /*value*/)
197 {
198
199 throw std::runtime_error(
200 "requested command config type must be derived from "
201 "IntegerBaseNode or "
202 "of type std::int64_t");
203 }
204
205 IntegerBaseNodePtr ValueConfigAsNode() const override;
206
216 template <class T>
217 T ValueConfig() const
218 {
219 throw std::runtime_error(
220 "requested value config type must be derived from IntegerBaseNode or be "
221 "of type int64_t");
222 }
223
237 template <class T>
238 void SetValueConfig(const T & /*value*/)
239 {
240 throw std::runtime_error(
241 "requested value config type must be derived from "
242 "IntegerBaseNode or be of integral type");
243 }
244
249 void FromString(const String &value) override
250 {
251 if (value.empty())
252 throw std::runtime_error("String must not be empty");
253
254 std::string str(Internal::CastToAscii(value));
255 std::transform(str.begin(), str.end(), str.begin(),
256 [](char ch) { return static_cast<char>(std::tolower(ch)); });
257 std::istringstream is(str);
258 bool b = false;
259 is >> std::boolalpha >> b;
260 if (b)
261 Execute();
262 }
263
268 String ToString() const override
269 {
270 return IsDone() ? CVB_LIT("true") : CVB_LIT("false");
271 }
272 };
273
274 template <>
275 inline std::int64_t CommandNode::CommandConfig<std::int64_t>() const
276 {
277 return GetInfoAsInt(NodeInfo::OnValue);
278 }
279
280 template <>
282 {
283 return GetInfoAs<IntegerBaseNode>(NodeInfo::OnValue);
284 }
285
286 template <>
287 inline void CommandNode::SetCommandConfig<std::int64_t>(const std::int64_t &value)
288 {
289 SetInfoAsInt(NodeInfo::OnValue, value);
290 }
291
292 template <>
293 inline std::int64_t CommandNode::ValueConfig<std::int64_t>() const
294 {
295 return GetInfoAsInt(NodeInfo::Value);
296 }
297
298 template <>
299 inline void CommandNode::SetValueConfig<std::int64_t>(const std::int64_t &value)
300 {
301 SetInfoAsInt(NodeInfo::Value, value);
302 }
303
304 } // namespace GevServer
305 CVB_END_INLINE_NS
306} // namespace Cvb
T boolalpha(T... args)
void Execute()
Executes this command.
Definition command_node.hpp:127
static CommandNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new CommandNode with the given name and nameSpace .
Definition command_node.hpp:47
bool IsStreamable() const override
Commands are never streamable.
Definition command_node.hpp:103
void SetPollingTime(const std::chrono::duration< Rep, Period > &timespan)
Sets the polling time of this value.
Definition command_node.hpp:157
static CommandNodePtr Create(const String &name)
Creates a new CommandNode with the given name .
Definition command_node.hpp:67
void SetValueConfig(const T &)
Sets the value configuration of this command node.
Definition command_node.hpp:238
T CommandConfig() const
Gets and sets the command value configuration of this command node.
Definition command_node.hpp:175
bool IsDone() const
If this command is readable, the execution state can be queried.
Definition command_node.hpp:116
void FromString(const String &value) override
Executes if value is "true".
Definition command_node.hpp:249
GenApi::CacheMode CacheMode() const override
Gets the cache mode by querying all ValueConfigs for it.
Definition command_node.hpp:90
T ValueConfig() const
Gets and sets the value configuration of this command node.
Definition command_node.hpp:217
GenApi::AccessMode AccessMode() const override
Gets the access mode by querying all ValueConfigs for it.
Definition command_node.hpp:76
void SetCommandConfig(const T &)
Sets the command value configuration of this command node.
Definition command_node.hpp:196
String ToString() const override
Gets the IsDone status as a string.
Definition command_node.hpp:268
std::chrono::duration< Rep, Period > PollingTime() const
Gets the polling time of this value.
Definition command_node.hpp:140
Basic GevServer node for device feature access.
Definition decl_node.hpp:34
static GevServer::Namespace ParseNamespace(const String &name)
Gets the Namespace from the given name .
Definition decl_node.hpp:591
static String EnsureNodeNameOnly(const String &name)
Throws if the given name has a namespace prefix.
Definition decl_node.hpp:564
static String ParseName(const String &name)
Gets the name part of the given node name .
Definition decl_node.hpp:611
ValueNodePtr GetTerminalRegisterNode(const NodeT *node, std::function< bool(Node *)> f) const
Try to get terminal register node.
Definition detail_node.hpp:708
void * Handle() const noexcept
Classic API node handle.
Definition decl_node.hpp:102
T duration_cast(T... args)
T make_shared(T... args)
T move(T... args)
CacheMode
Defines how the value is cached.
Definition genapi.hpp:218
@ NoCache
No caching used.
Definition genapi.hpp:220
AccessMode
Access possibility of the node.
Definition genapi.hpp:183
@ ReadWrite
Node can be read and written to.
Definition genapi.hpp:213
Describes a GenICam Pixel Format Naming Convention (PFNC) compatible image memory buffer with possibl...
Definition decl_int_swiss_knife_node.hpp:11
Namespace
The possible name spaces a node can be in.
Definition gevserver.hpp:147
std::shared_ptr< IntegerBaseNode > IntegerBaseNodePtr
Convenience shared pointer for IntegerBaseNode.
Definition gevserver.hpp:64
std::shared_ptr< CommandNode > CommandNodePtr
Convenience shared pointer for CommandNode.
Definition gevserver.hpp:104
@ PollingTime
Gets the polling time in ms.
Definition gevserver.hpp:204
@ OnValue
Definition gevserver.hpp:211
@ Value
Accesses the value configuration.
Definition gevserver.hpp:210
@ String
Node is a string node (no reg).
Definition gevserver.hpp:168
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
T transform(T... args)