/* * Device.h * * Created on: 2016年11月10日 * Author: Mr_zhu * Content: */ #ifndef SERVICEMODEL_DEVICE_H_ #define SERVICEMODEL_DEVICE_H_ #include #include #include "../common/Type.h" #include "../externservice/HardwareI.h" #include "../externservice/ParaAnalysisI.h" #include "../externservice/ProtocolI.h" #include "../externservice/SubContractI.h" #include "Base.h" #include "Item.h" #include "Packet.h" struct HardwareI; struct ParaAnalysisI; struct ProtocolI; struct SubContractI; struct IHardware; struct IParaAnalysis; struct IProtocol; class Channel; class Device { public: Device() : m_pptcl(NULL), m_hwtype(-1), m_hwnumber(-1), m_phw(NULL), m_ppara( NULL), m_psubctact( NULL), m_enable(1), m_datimer(100), m_datimeout(1000), m_dafaulttime( 3000), m_readretrycount(0), m_writeretrycount(3), m_faultcount( 3), m_parent(NULL) { } virtual ~Device() { // if (m_pptcl != NULL) { // delete m_pptcl; // m_pptcl = NULL; // } // if (m_phw != NULL) { // delete m_phw; // m_phw = NULL; // } // if (m_ppara != NULL) { // delete m_ppara; // m_ppara = NULL; // } // if (m_psubctact != NULL) { // delete m_psubctact; // m_psubctact = NULL; // } } Base& getBase() { return m_base; } void setBase(const Base& base) { this->m_base = base; } int getEnable() const { return m_enable; } void setEnable(int enable) { m_enable = enable; } CLSID& getHwguid() { return m_hwguid; } void setHwguid(const CLSID& hwguid) { m_hwguid = hwguid; } std::string& getHwname() { return m_hwname; } void setHwname(const std::string& hwname) { if (!hwname.empty()) { m_hwname = hwname; } } int getHwnumber() const { return m_hwnumber; } void setHwnumber(int hwnumber) { m_hwnumber = hwnumber; } int getHwtype() const { return m_hwtype; } void setHwtype(int hwtype) { m_hwtype = hwtype; } std::string& getItemtable() { return m_itemtable; } void setItemtable(const std::string& itemtable) { if (!itemtable.empty()) { m_itemtable = itemtable; } } CLSID& getParaanalysisguid() { return m_paraanalysisguid; } void setParaanalysisguid(const CLSID& paraanalysisguid) { m_paraanalysisguid = paraanalysisguid; } CLSID& getProtocolguid() { return m_protocolguid; } void setProtocolguid(const CLSID& protocolguid) { m_protocolguid = protocolguid; } const std::string& getProtocolname() const { return m_protocolname; } void setProtocolname(const std::string& protocolname) { if (!protocolname.empty()) { m_protocolname = protocolname; } } CLSID& getSubcontractguid() { return m_subcontractguid; } void setSubcontractguid(const CLSID& subcontractguid) { m_subcontractguid = subcontractguid; } Channel* getParent() { return m_parent; } void setParent(Channel* parent) { this->m_parent = parent; } HardwareI* getPhw() { return m_phw; } void setPhw(HardwareI* phw) { this->m_phw = phw; } ParaAnalysisI* getPpara() const { return m_ppara; } void setPpara(ParaAnalysisI* ppara) { this->m_ppara = ppara; } ProtocolI* getPptcl() { return m_pptcl; } void setPptcl(ProtocolI* pptcl) { this->m_pptcl = pptcl; } SubContractI* getPsubctact() const { return m_psubctact; } void setPsubctact(SubContractI* psubctact) { this->m_psubctact = psubctact; } std::vector& getVpacket() { return m_vpacket; } void setVpacket(const std::vector& vpacket) { this->m_vpacket = vpacket; } std::vector& getVitem() { return m_vitem; } void setVitem(const std::vector& vitem) { this->m_vitem = vitem; } HRESULT addItem(Item* item) { bool isexist = false; for (Item*& i : m_vitem) { if (i->isEqual(*item)) { isexist = true; break; } } if (!isexist) { m_vitem.push_back(item); return S_OK; } return S_FALSE; } HRESULT addPacket(Packet* packet) { bool isexist = false; for (Packet* & p : m_vpacket) { if (p->isEqual(*packet)) { isexist = true; break; } } if (!isexist) { m_vpacket.push_back(packet); return S_OK; } return S_FALSE; } ULONG getItemCount() { return m_vitem.size(); } ULONG getPacketCount() { return m_vpacket.size(); } public: bool isEqual(Device& device) { if ((isGUIDEqual(this->m_hwguid,((device.getHwguid())))) && (this->m_hwname == ((device.getHwname()))) && (this->m_hwnumber == device.getHwnumber()) && (this->m_hwtype == device.getHwtype())) { return true; } return false; } int getDafaulttime() const { return m_dafaulttime; } void setDafaulttime(int dafaulttime) { m_dafaulttime = dafaulttime; } int getDatimeout() const { return m_datimeout; } void setDatimeout(int datimeout) { m_datimeout = datimeout; } int getDatimer() const { return m_datimer; } void setDatimer(int datimer) { m_datimer = datimer; } int getFaultcount() const { return m_faultcount; } void setFaultcount(int faultcount) { m_faultcount = faultcount; } int getReadretrycount() const { return m_readretrycount; } void setReadretrycount(int readretrycount) { m_readretrycount = readretrycount; } int getWriteretrycount() const { return m_writeretrycount; } void setWriteretrycount(int writeretrycount) { m_writeretrycount = writeretrycount; } void outInfo() { } private: std::string m_protocolname; //----设备通信协议名称 CLSID m_protocolguid; //----设备通信协议组件标识符 ProtocolI* m_pptcl; //----设备通信协议组件句柄 std::string m_hwname; //----设备硬件通道名称 int m_hwtype; //----设备硬件通道类型 int m_hwnumber; //----设备硬件通道号 CLSID m_hwguid; //----设备硬件通道组件标识符 HardwareI* m_phw; //----设备硬件通道组件句柄 CLSID m_paraanalysisguid; //----设备参数解析组件标识符 ParaAnalysisI* m_ppara; //----设备参数分析组件句柄 CLSID m_subcontractguid; //----设备分包参数组件标识符 SubContractI* m_psubctact; //----设备分包组件句柄 std::string m_itemtable; //----设备点表名称 int m_enable; //----设备使能控制 int m_datimer; //----采集周期 int m_datimeout; //----采集超时时间 int m_dafaulttime; //----采集故障恢复时间 int m_readretrycount; //----读重试次数 int m_writeretrycount; //----写重试次数 int m_faultcount; //----采集故障次数 Base m_base; //----公共参数 std::vector m_vpacket; //----设备中的采集包集合 std::vector m_vitem; //----设备中采集点集合 Channel* m_parent; //----父句柄 }; #endif /* SERVICEMODEL_DEVICE_H_ */