#ifndef TDE_MODBUS_SERVER_H
#define TDE_MODBUS_SERVER_H

#include "common.h"
#include "engine.h"

#include <modbus/modbus.h>

// -- TDE NAMESPACE ---------------------------------------------------

namespace TDE {


class DataStore;

typedef SHARED_PTR<DataStore> DataStorePtr;

// -- DataStoreModbusServer -------------------------------------------

class DataStoreModbusServer
{
public:
	DataStoreModbusServer(DataStore* dsp, std::string host = "0.0.0.0", int port = 1502, bool debug = false);
	~DataStoreModbusServer();

	bool initialize();
	void cleanup();
	void run();

private:
	DataStore*                m_dsP;
	modbus_t*                 m_mb_ctx;
	modbus_mapping_dynamic_t* m_mb_mapping;
	int                       m_server_socket;

	std::string               m_host;
	int                       m_port;
	bool                      m_debug;
};


} /* end of namespace TDE */

#endif /* TDE_MODBUS_SERVER_H */
