#pragma once
#include <memory>
#include <string>

#include "Utility.h"

#ifdef  BUILD_COMMDLL
#define     COMMDLL_DLLCLASS    __declspec(dllexport)
#else
#define     COMMDLL_DLLCLASS    __declspec(dllimport)
#endif

class CScanner;
typedef std::shared_ptr<CScanner> CommPtr;

class IRfId
{
public:
    virtual ~IRfId()
    {
    }

    virtual bool    WriteID(const std::string &strID) = 0;
    virtual bool    ReadID(std::string *pResult)      = 0;
    virtual bool    TestComm()                    = 0;
    virtual std::string GetErrorMessage() const   = 0;
};

class COMMDLL_DLLCLASS RfIdBase : public IRfId
{
private:
    CIniFile m_hardwareIni;
    CommPtr  m_pCommPort;
public:
    explicit RfIdBase(int index);
    virtual ~RfIdBase();
    long         GetBaudRate();
    long         GetByteSize();
    double       GetStopBits();
    std::string  GetParity();
    std::string  GetCommPort();
    int          GetHead();
    int          GetUnit();
    bool         Connect();
    bool         Disconnect();
    bool         IsConnected();
    bool         Send(const std::string &data);
    virtual void OnReceiveComm(const char *cpcBuffer, int nSize) = 0;
};

#pragma warning( push )
#pragma warning( disable : 4251 )
class COMMDLL_DLLCLASS RfId
{
private:
    std::unique_ptr<IRfId> m_base;
public:
    explicit RfId(int index);
    virtual ~RfId(void);
    bool    WriteID(const std::string &strID);
    bool    ReadID(std::string *pResult);
    bool    TestComm();
    std::string GetErrorMessage() const;
};
#pragma warning( pop)

