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.hpp"
13#include "../../genapi/_decl/decl_node_map.hpp"
24 class NodeMap :
public std::enable_shared_from_this<NodeMap>
27 explicit NodeMap(
const ServerPtr &server) noexcept
38 void *Handle() const noexcept
40 auto srv = server_.lock();
54 auto srv = server_.lock();
66 std::map<String, NodePtr> Nodes()
const;
75 void AddNode(
const String &key,
const NodePtr &value)
78 throw std::runtime_error(
"key must not be empty");
80 throw std::runtime_error(
"node must not be null");
81 if (value->NodeMap() !=
nullptr)
82 if (!nodes_[key].owner_before(value) && !value.owner_before(nodes_[key]))
84 auto name = value->NameOnly();
86 throw std::runtime_error(
"key and value->NameOnly() must be equal");
88 NativeCall([&]() {
return CVB_CALL_CAPI(GSAddNode(Handle(), value->Handle())); });
91 value->SetNodeMap(std::const_pointer_cast<NodeMap>(shared_from_this()));
104 void AddNode(
const String &key,
const NodePtr &value,
const NodeList &kind);
114 void AddNode(
const NodePtr &value)
117 throw std::runtime_error(
"node must not be null");
119 AddNode(value->NameOnly(), value);
130 bool RemoveNode(
const Node &node)
132 return RemoveNode(node.NameOnly());
144 bool RemoveNode(
const String &key)
146 auto node = TryGetNode(key);
150 throw std::runtime_error(
"node to remove must not be null");
151 if (node->NodeMap() != shared_from_this())
154 auto it = nodes_.find(node->NameOnly());
155 if (it != nodes_.end())
158 NativeCall([&]() {
return CVB_CALL_CAPI(GSRemoveNode(Handle(), node->Handle())); });
173 bool IsReadOnly()
const
175 auto srv = server_.lock();
177 return srv->State() != GevServer::State::Configuration;
179 throw std::runtime_error(
"this node map is not attached to a server");
187 auto modelName = Node(CVB_LIT(
"DeviceModelName"));
188 return modelName !=
nullptr ? modelName->DisplayName() : CVB_LIT(
"CVGevServer");
197 String ModuleName() const noexcept
199 return CVB_LIT(
"Device");
208 String TransportLayerNamespace() const noexcept
210 return CVB_LIT(
"GEV");
222 String VendorName() const noexcept
224 auto vendorName = Node(CVB_LIT(
"DeviceVendorName"));
225 return vendorName !=
nullptr ? vendorName->DisplayName() : CVB_LIT(
"STEMMERIMAGING");
233 GenApi::NodeMap::GenApiVersion XmlFileSchemaVersion() const noexcept
235 return GenApi::NodeMap::GenApiVersion(1, 0, 1);
254 GenApi::NodeMap::GenApiVersion XmlFileVersion() const noexcept
256 return GenApi::NodeMap::GenApiVersion(
static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionMajor)),
257 static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionMinor)),
258 static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionSubMinor)));
277 void SetXmlFileVersion(
const GenApi::NodeMap::GenApiVersion &genApiVersion)
const
279 SetInfoAsInt(Info::XMLVersionMajor, genApiVersion.Major());
280 SetInfoAsInt(Info::XMLVersionMinor, genApiVersion.Minor());
281 SetInfoAsInt(Info::XMLVersionSubMinor, genApiVersion.SubMinor());
294 std::shared_ptr<T> Node(
const String &name)
const
296 static_assert(std::is_base_of<Cvb::GevServer::Node, T>::value,
"requested node type must be derived from Node");
297 return std::dynamic_pointer_cast<T>(Node(name));
321 NodePtr Node(
const String &name)
const
323 auto nameOnly = GevServer::Node::ParseName(name);
324 if (nodes_.find(nameOnly) == nodes_.end())
325 throw std::out_of_range(
"no node for name");
327 auto node = nodes_[nameOnly];
330 node = Node::FromName(std::const_pointer_cast<NodeMap>(shared_from_this()), nameOnly);
331 nodes_[nameOnly] = node;
367 std::shared_ptr<T> TryGetNode(
const String &name)
const
369 static_assert(std::is_base_of<Cvb::GevServer::Node, T>::value,
"requested node type must be derived from Node");
370 return std::dynamic_pointer_cast<T>(TryGetNode(name));
400 NodePtr TryGetNode(
const String &name)
const noexcept
416 std::string GetLastGSErrorMessage() const noexcept
418 std::size_t messageSize = 0;
419 auto res = CVB_CALL_CAPI(GSGetLastErrorString(
nullptr, messageSize));
420 if (!res || messageSize < 2)
422 std::vector<char> message(messageSize);
423 if (CVB_CALL_CAPI(GSGetLastErrorString(message.data(), messageSize)))
425 return std::string(message.data());
428 void NativeCall(std::function<CExports::cvbres_t()> fn)
const
433 auto message = GetLastGSErrorMessage();
437 std::stringstream stream;
438 stream <<
"NodeMap: " << message;
439 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
444 T NativeCall(std::function<CExports::cvbres_t(T &value)> fn)
const
447 auto result = fn(value);
450 auto message = Utilities::SystemInfo::GetLastErrorMessage();
454 std::stringstream stream;
455 stream <<
"NodeMap: " << message;
456 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
461 std::int64_t GetInfoAsInt(Info command)
const
463 return static_cast<std::int64_t
>(NativeCall<CExports::cvbint64_t>([&](CExports::cvbint64_t &value) {
464 return CVB_CALL_CAPI(GSGetInfoAsInteger(Handle(),
static_cast<CExports::TGSInfo
>(command), value));
468 void SetInfoAsInt(Info command, CExports::cvbint64_t value)
const
471 return CVB_CALL_CAPI(GSSetInfoAsInteger(Handle(),
static_cast<CExports::TGSInfo
>(command), value));
475 std::weak_ptr<class Server> server_;
476 mutable std::map<String, std::shared_ptr<class Node>> nodes_;
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition genapi.hpp:66
Describes a GenICam Pixel Format Naming Convention (PFNC) compatible image memory buffer with possibl...
Definition decl_int_swiss_knife_node.hpp:11
std::shared_ptr< Server > ServerPtr
Convenience shared pointer for GevServer.
Definition gevserver.hpp:28
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49