7#include "../../global.hpp"
8#include "../../genapi/node_map.hpp"
9#include "../gevserver.hpp"
11#include "../_decl/decl_node.hpp"
12#include "../_decl/decl_server_base.hpp"
13#include "../../genapi/_decl/decl_node_map.hpp"
24 class NodeMap :
public std::enable_shared_from_this<NodeMap>
27 explicit NodeMap(ServerBasePtr server)
noexcept;
34 void *Handle() const noexcept
36 auto srv = server_.get();
48 std::map<String, NodePtr> Nodes()
const;
57 void AddNode(
const String &key,
const NodePtr &value)
60 throw std::runtime_error(
"key must not be empty");
62 throw std::runtime_error(
"node must not be null");
63 if (value->NodeMap() !=
nullptr)
64 if (!nodes_[key].owner_before(value) && !value.owner_before(nodes_[key]))
66 auto name = value->NameOnly();
68 throw std::runtime_error(
"key and value->NameOnly() must be equal");
70 NativeCall([&]() {
return CVB_CALL_CAPI(GSAddNode(Handle(), value->Handle())); });
73 value->SetNodeMap(std::const_pointer_cast<NodeMap>(shared_from_this()));
86 void AddNode(
const String &key,
const NodePtr &value,
const NodeList &kind);
96 void AddNode(
const NodePtr &value)
99 throw std::runtime_error(
"node must not be null");
101 AddNode(value->NameOnly(), value);
112 bool RemoveNode(
const Node &node)
114 return RemoveNode(node.NameOnly());
126 bool RemoveNode(
const String &key)
128 auto node = TryGetNode(key);
132 throw std::runtime_error(
"node to remove must not be null");
133 if (node->NodeMap() != shared_from_this())
136 auto it = nodes_.find(node->NameOnly());
137 if (it != nodes_.end())
140 NativeCall([&]() {
return CVB_CALL_CAPI(GSRemoveNode(Handle(), node->Handle())); });
155 bool IsReadOnly()
const
158 return server_->State() != GevServer::State::Configuration;
160 throw std::runtime_error(
"this node map is not attached to a server");
168 auto modelName = Node(CVB_LIT(
"DeviceModelName"));
169 return modelName !=
nullptr ? modelName->DisplayName() : CVB_LIT(
"CVGevServer");
178 String ModuleName() const noexcept
180 return CVB_LIT(
"Device");
189 String TransportLayerNamespace() const noexcept
191 return CVB_LIT(
"GEV");
203 String VendorName() const noexcept
205 auto vendorName = Node(CVB_LIT(
"DeviceVendorName"));
206 return vendorName !=
nullptr ? vendorName->DisplayName() : CVB_LIT(
"STEMMERIMAGING");
214 GenApi::NodeMap::GenApiVersion XmlFileSchemaVersion() const noexcept
216 return GenApi::NodeMap::GenApiVersion(1, 0, 1);
235 GenApi::NodeMap::GenApiVersion XmlFileVersion() const noexcept
237 return GenApi::NodeMap::GenApiVersion(
static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionMajor)),
238 static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionMinor)),
239 static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionSubMinor)));
258 void SetXmlFileVersion(
const GenApi::NodeMap::GenApiVersion &genApiVersion)
const
260 SetInfoAsInt(Info::XMLVersionMajor, genApiVersion.Major());
261 SetInfoAsInt(Info::XMLVersionMinor, genApiVersion.Minor());
262 SetInfoAsInt(Info::XMLVersionSubMinor, genApiVersion.SubMinor());
275 std::shared_ptr<T> Node(
const String &name)
const
277 static_assert(std::is_base_of<Cvb::GevServer::Node, T>::value,
"requested node type must be derived from Node");
278 return std::dynamic_pointer_cast<T>(Node(name));
302 NodePtr Node(
const String &name)
const
304 auto nameOnly = GevServer::Node::ParseName(name);
305 if (nodes_.find(nameOnly) == nodes_.end())
306 throw std::out_of_range(
"no node for name");
308 auto node = nodes_[nameOnly];
311 node = Node::FromName(std::const_pointer_cast<NodeMap>(shared_from_this()), nameOnly);
312 nodes_[nameOnly] = node;
348 std::shared_ptr<T> TryGetNode(
const String &name)
const
350 static_assert(std::is_base_of<Cvb::GevServer::Node, T>::value,
"requested node type must be derived from Node");
351 return std::dynamic_pointer_cast<T>(TryGetNode(name));
381 NodePtr TryGetNode(
const String &name)
const noexcept
397 std::string GetLastGSErrorMessage() const noexcept
399 std::size_t messageSize = 0;
400 auto res = CVB_CALL_CAPI(GSGetLastErrorString(
nullptr, messageSize));
401 if (!res || messageSize < 2)
403 std::vector<char> message(messageSize);
404 if (CVB_CALL_CAPI(GSGetLastErrorString(message.data(), messageSize)))
406 return std::string(message.data());
409 void NativeCall(std::function<CExports::cvbres_t()> fn)
const
414 auto message = GetLastGSErrorMessage();
418 std::stringstream stream;
419 stream <<
"NodeMap: " << message;
420 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
425 T NativeCall(std::function<CExports::cvbres_t(T &value)> fn)
const
428 auto result = fn(value);
431 auto message = Utilities::SystemInfo::GetLastErrorMessage();
435 std::stringstream stream;
436 stream <<
"NodeMap: " << message;
437 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
442 std::int64_t GetInfoAsInt(Info command)
const
444 return static_cast<std::int64_t
>(NativeCall<CExports::cvbint64_t>([&](CExports::cvbint64_t &value) {
445 return CVB_CALL_CAPI(GSGetInfoAsInteger(Handle(),
static_cast<CExports::TGSInfo
>(command), value));
449 void SetInfoAsInt(Info command, CExports::cvbint64_t value)
const
452 return CVB_CALL_CAPI(GSSetInfoAsInteger(Handle(),
static_cast<CExports::TGSInfo
>(command), value));
456 std::shared_ptr<ServerBase> server_;
457 mutable std::map<String, std::shared_ptr<class Node>> nodes_;
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition genapi.hpp:71
Namespace for GevServer based device configuration.
Definition decl_int_swiss_knife_node.hpp:11
Root namespace for the Image Manager interface.
Definition version.hpp:11
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49