#pragma once
#include <modbus/modbus.h>
#include <string>

namespace myapp::modbus {

class context
{
public:
	context(std::string const& connection_string);
	~context();
	
	context(context const&) = delete;
	context& operator=(context const&) = delete;

	friend void swap(context&, context&) noexcept;
	context(context &&) noexcept;
	context& operator=(context &&) noexcept;

	std::string const& description() const noexcept { return desc_; }
	operator ::modbus_t*() noexcept { return ctx_; }

private:
	void create_rtu(std::string const& connection_string);
	void create_tcp_pi(std::string const& connection_string);
	
private:
	::modbus_t* ctx_{ nullptr };
	std::string desc_{ "Uninitialized modbus context" };
};

} /* namespace myapp::modbus */
