/**
 * \file    Mimic_NodeMap.hpp
 * \author  Silvan Murer
 * \date    13 October 2022
 *
 * \brief   Class get access to the feature tree
 */

#include "Mimic_NodeMap.hpp"
#include "M_Port.hpp"
#include "H_NodeMap.hpp"

#include "features/Mimic_Boolean.hpp"
#include "features/Mimic_Category.hpp"
#include "features/Mimic_Command.hpp"
#include "features/Mimic_Enumeration.hpp"
#include "features/Mimic_Float.hpp"
#include "features/Mimic_Integer.hpp"
#include "features/Mimic_String.hpp"

#define GENICAM_NO_AUTO_IMPLIB
#include "GenICam.h"

#include "spdlog/spdlog.h"
#ifdef _WIN32
#include "spdlog/sinks/msvc_sink.h"
#else
#include "spdlog/sinks/stdout_color_sinks.h"
#endif

using namespace GenApi;

namespace mimic {

Mimic_NodeMap::Mimic_NodeMap(std::shared_ptr<genSDK::GTL_Producer> gtl_producer, GenTL::PORT_HANDLE portH, std::string portName, std::string xmlContent)
 : gtl_producer(gtl_producer)
{
	port = std::shared_ptr<M_Port>(new M_Port(gtl_producer, portH));
	nodeMap = std::shared_ptr<GenApi::INodeMap>(
		CNodeMapFactory(xmlContent.c_str(), CacheUsage_Ignore, false).CreateNodeMap(), 
		[](GenApi::INodeMap* ptr) { dynamic_cast<IDestroy*>(ptr)->Destroy(); }
	);
	nodeMap->Connect(dynamic_cast<IPort*>(port.get()), portName.c_str());
}

GenApi_3_4::INodeMap* Mimic_NodeMap::getRawINodeMap()
{
	return nodeMap.get();
}

std::shared_ptr<Mimic_Node> Mimic_NodeMap::getNode(std::string name)
{
	return H_NodeMap::createGFNodePtr(nodeMap, name);
}

} /* namespace genSDK */
