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;
34 void *Handle() const noexcept
36 auto srv = server_.lock();
50 auto srv = server_.lock();
62 std::map<String, NodePtr> Nodes()
const;
71 void AddNode(
const String &key,
const NodePtr &value)
74 throw std::runtime_error(
"key must not be empty");
76 throw std::runtime_error(
"node must not be null");
77 if (value->NodeMap() !=
nullptr)
78 if (!nodes_[key].owner_before(value) && !value.owner_before(nodes_[key]))
80 auto name = value->NameOnly();
82 throw std::runtime_error(
"key and value->NameOnly() must be equal");
84 NativeCall([&]() {
return CVB_CALL_CAPI(GSAddNode(Handle(), value->Handle())); });
87 value->SetNodeMap(std::const_pointer_cast<NodeMap>(shared_from_this()));
100 void AddNode(
const String &key,
const NodePtr &value,
const NodeList &kind);
110 void AddNode(
const NodePtr &value)
113 throw std::runtime_error(
"node must not be null");
115 AddNode(value->NameOnly(), value);
126 bool RemoveNode(
const Node &node)
128 return RemoveNode(node.NameOnly());
140 bool RemoveNode(
const String &key)
142 auto node = TryGetNode(key);
146 throw std::runtime_error(
"node to remove must not be null");
147 if (node->NodeMap() != shared_from_this())
150 auto it = nodes_.find(node->NameOnly());
151 if (it != nodes_.end())
154 NativeCall([&]() {
return CVB_CALL_CAPI(GSRemoveNode(Handle(), node->Handle())); });
169 bool IsReadOnly()
const
171 auto srv = server_.lock();
173 return srv->State() != GevServer::State::Configuration;
175 throw std::runtime_error(
"this node map is not attached to a server");
183 auto modelName = Node(CVB_LIT(
"DeviceModelName"));
184 return modelName !=
nullptr ? modelName->DisplayName() : CVB_LIT(
"CVGevServer");
193 String ModuleName() const noexcept
195 return CVB_LIT(
"Device");
204 String TransportLayerNamespace() const noexcept
206 return CVB_LIT(
"GEV");
218 String VendorName() const noexcept
220 auto vendorName = Node(CVB_LIT(
"DeviceVendorName"));
221 return vendorName !=
nullptr ? vendorName->DisplayName() : CVB_LIT(
"STEMMERIMAGING");
229 GenApi::NodeMap::GenApiVersion XmlFileSchemaVersion() const noexcept
231 return GenApi::NodeMap::GenApiVersion(1, 0, 1);
250 GenApi::NodeMap::GenApiVersion XmlFileVersion() const noexcept
252 return GenApi::NodeMap::GenApiVersion(
static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionMajor)),
253 static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionMinor)),
254 static_cast<std::uint16_t
>(GetInfoAsInt(Info::XMLVersionSubMinor)));
273 void SetXmlFileVersion(
const GenApi::NodeMap::GenApiVersion &genApiVersion)
const
275 SetInfoAsInt(Info::XMLVersionMajor, genApiVersion.Major());
276 SetInfoAsInt(Info::XMLVersionMinor, genApiVersion.Minor());
277 SetInfoAsInt(Info::XMLVersionSubMinor, genApiVersion.SubMinor());
290 std::shared_ptr<T> Node(
const String &name)
const
292 static_assert(std::is_base_of<Cvb::GevServer::Node, T>::value,
"requested node type must be derived from Node");
293 return std::dynamic_pointer_cast<T>(Node(name));
317 NodePtr Node(
const String &name)
const
319 auto nameOnly = GevServer::Node::ParseName(name);
320 if (nodes_.find(nameOnly) == nodes_.end())
321 throw std::out_of_range(
"no node for name");
323 auto node = nodes_[nameOnly];
326 node = Node::FromName(std::const_pointer_cast<NodeMap>(shared_from_this()), nameOnly);
327 nodes_[nameOnly] = node;
363 std::shared_ptr<T> TryGetNode(
const String &name)
const
365 static_assert(std::is_base_of<Cvb::GevServer::Node, T>::value,
"requested node type must be derived from Node");
366 return std::dynamic_pointer_cast<T>(TryGetNode(name));
396 NodePtr TryGetNode(
const String &name)
const noexcept
412 std::string GetLastGSErrorMessage() const noexcept
414 std::size_t messageSize = 0;
415 auto res = CVB_CALL_CAPI(GSGetLastErrorString(
nullptr, messageSize));
416 if (!res || messageSize < 2)
418 std::vector<char> message(messageSize);
419 if (CVB_CALL_CAPI(GSGetLastErrorString(message.data(), messageSize)))
421 return std::string(message.data());
424 void NativeCall(std::function<CExports::cvbres_t()> fn)
const
429 auto message = GetLastGSErrorMessage();
433 std::stringstream stream;
434 stream <<
"NodeMap: " << message;
435 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
440 T NativeCall(std::function<CExports::cvbres_t(T &value)> fn)
const
443 auto result = fn(value);
446 auto message = Utilities::SystemInfo::GetLastErrorMessage();
450 std::stringstream stream;
451 stream <<
"NodeMap: " << message;
452 std::rethrow_exception(CvbException::FromCvbResult(result, stream.str()));
457 std::int64_t GetInfoAsInt(Info command)
const
459 return static_cast<std::int64_t
>(NativeCall<CExports::cvbint64_t>([&](CExports::cvbint64_t &value) {
460 return CVB_CALL_CAPI(GSGetInfoAsInteger(Handle(),
static_cast<CExports::TGSInfo
>(command), value));
464 void SetInfoAsInt(Info command, CExports::cvbint64_t value)
const
467 return CVB_CALL_CAPI(GSSetInfoAsInteger(Handle(),
static_cast<CExports::TGSInfo
>(command), value));
471 std::weak_ptr<class Server> server_;
472 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
std::shared_ptr< Server > ServerPtr
Convenience shared pointer for GevServer.
Definition gevserver.hpp:37
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