| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- /*
- * Channel.h
- *
- * Created on: 2016年11月10日
- * Author: Mr_zhu
- * Content:
- */
-
- #ifndef SERVICEMODEL_CHANNEL_H_
- #define SERVICEMODEL_CHANNEL_H_
-
- #include <pthread.h>
- #include <iostream>
- #include <map>
- #include <string>
- #include <utility>
- #include <vector>
-
- #include "../common/Type.h"
- #include "../externservice/HardwareI.h"
- #include "../service/CallBackHandleI.h"
- #include "../service/impl/MThreadedJobQImpl.h"
- #include "Base.h"
- #include "Device.h"
-
- struct DAControlerI;
-
- struct CallBackHandleI;
- class MThreadedJobQImpl;
- class Device;
-
- class Channel
- {
-
- public:
- enum STATE
- {
- R = 0, S
- };
-
- public:
- Channel() :
- m_phw(NULL), m_DATimeout(1000), m_BaseDATime(100), m_FaultTime(10000), m_ReadRetryCount(0), m_WriteRetryCount(3), m_FaultRetryCount(3), m_pCB(NULL), isHDInitOK(
- false), m_state(S), m_preadJobThread(NULL)
- {
- xLock = PTHREAD_MUTEX_INITIALIZER;
- }
- virtual ~Channel()
- {
- if(m_phw!=NULL)
- {
- delete m_phw;
- m_phw = NULL;
- }
- if(m_pCB!=NULL)
- {
- delete m_pCB;
- m_pCB = NULL;
- }
- if(m_preadJobThread!=NULL)
- {
- delete m_preadJobThread;
- m_preadJobThread = NULL;
- }
- }
-
- Base& getBase()
- {
- return m_base;
- }
-
- void setBase(const Base& base)
- {
- this->m_base = base;
- }
-
- bool isIsHdInitOk() const
- {
- return isHDInitOK;
- }
-
- void setIsHdInitOk(bool isHdInitOk)
- {
- isHDInitOK = isHdInitOk;
- }
-
- unsigned int getBaseDaTime() const
- {
- return m_BaseDATime;
- }
-
- void setBaseDaTime(unsigned int baseDaTime)
- {
- m_BaseDATime = baseDaTime;
- }
-
- const CLSID& getClsidOfHw() const
- {
- return m_hwguid;
- }
-
- void setClsidOfHw(const CLSID& clsidOfHw)
- {
- m_hwguid = clsidOfHw;
- }
-
- unsigned int getDaTimeout() const
- {
- return m_DATimeout;
- }
-
- void setDaTimeout(unsigned int daTimeout)
- {
- m_DATimeout = daTimeout;
- }
-
- CallBackHandleI* getPCb()
- {
- return m_pCB;
- }
-
- void setPCb(CallBackHandleI* pCb)
- {
- m_pCB = pCb;
- }
-
- HardwareI* getPHd()
- {
- return m_phw;
- }
-
- void setPHd(HardwareI* pHd)
- {
- m_phw = pHd;
- }
-
- const std::vector<BYTE>& getReadBuf() const
- {
- return m_vReadBuf;
- }
-
- void setReadBuf(const std::vector<BYTE>& readBuf)
- {
- m_vReadBuf = readBuf;
- }
-
- unsigned int getReadRetryCount() const
- {
- return m_ReadRetryCount;
- }
-
- void setReadRetryCount(unsigned int readRetryCount)
- {
- m_ReadRetryCount = readRetryCount;
- }
-
- std::vector<Device* >& getVDevice()
- {
- return m_vDevice;
- }
-
- void setVDevice(const std::vector<Device* >& vDevice)
- {
- m_vDevice = vDevice;
- }
-
- const std::vector<BYTE>& getWriteBuf() const
- {
- return m_vWriteBuf;
- }
-
- void setWriteBuf(const std::vector<BYTE>& writeBuf)
- {
- m_vWriteBuf = writeBuf;
- }
-
- unsigned int getWriteRetryCount() const
- {
- return m_WriteRetryCount;
- }
-
- void setWriteRetryCount(unsigned int writeRetryCount)
- {
- m_WriteRetryCount = writeRetryCount;
- }
-
- HRESULT addDevice(Device* device)
- {
- // bool isexist = false;
- //
- // for (Device& d : m_vDevice) {
- // if (d.isEqual(device)) {
- // isexist = true;
- // break;
- // }
- // }
- // if (!isexist) {
- // m_vDevice.push_back(device);
- // return S_OK;
- // }
- // return S_FALSE;
- m_vDevice.push_back(device);
- return S_OK;
- }
-
- ULONG getDeviceCount()
- {
- return m_vDevice.size();
- }
-
- unsigned int getFaultRetryCount() const
- {
- return m_FaultRetryCount;
- }
-
- void setFaultRetryCount(unsigned int faultRetryCount)
- {
- m_FaultRetryCount = faultRetryCount;
- }
-
- unsigned int getFaultTime() const
- {
- return m_FaultTime;
- }
-
- void setFaultTime(unsigned int faultTime)
- {
- m_FaultTime = faultTime;
- }
-
- CLSID& getHwguid()
- {
- return m_hwguid;
- }
-
- void setHwguid(const CLSID& hwguid)
- {
- m_hwguid = hwguid;
- }
-
- HardwareI* getPhw()
- {
- return m_phw;
- }
-
- void setPhw(HardwareI* phw)
- {
- this->m_phw = phw;
- }
-
- STATE getState() const
- {
- return m_state;
- }
-
- void setState(STATE state)
- {
- (void) pthread_mutex_lock(&xLock);
- this->m_state = state;
- (void) pthread_mutex_unlock(&xLock);
- }
-
- MThreadedJobQImpl* getReadJobThread()
- {
- return m_preadJobThread;
- }
-
- void setReadJobThread(MThreadedJobQImpl* readJobThread)
- {
- m_preadJobThread = readJobThread;
- }
-
- void outInfo()
- {
-
- std::cout << "通道ID: " << m_base.getObjid().toString() << std::endl;
- std::cout << "通道名称: " << m_base.getName() << std::endl;
- std::cout << "通道参数: " << std::endl;
- for(std::pair<const std::string,std::string>& s : m_base.getParams())
- {
- std::cout << s.first << " : " << s.second << std::endl;
- }
- std::cout << "通道读写状态: " << m_base.getRwstate() << std::endl;
- std::cout << "通道优先级状态: " << m_base.getPriority() << std::endl;
- std::cout << "硬件组件ID: " << m_hwguid.toString() << std::endl;
- std::cout << "硬件组件句柄: " << m_phw << std::endl;
- std::cout << "采集超时时间: " << m_phw << std::endl;
- std::cout << "基础采集周期: " << m_phw << std::endl;
- std::cout << "采集故障时间: " << m_phw << std::endl;
- std::cout << "读重试次数: " << m_phw << std::endl;
- std::cout << "写重试次数: " << m_phw << std::endl;
- std::cout << "故障重试次数: " << m_phw << std::endl;
- std::cout << "设备数: " << m_vDevice.size() << std::endl;
- for(Device* & d : m_vDevice)
- {
- d->outInfo();
- }
- }
-
- DAControlerI*& getDa()
- {
- return pDa;
- }
-
- void setDa(DAControlerI* da)
- {
- pDa = da;
- }
-
- private:
- CLSID m_hwguid; //----通道组件标识符
- HardwareI* m_phw;//----通道组件句柄
- unsigned int m_DATimeout;
- unsigned int m_BaseDATime;
- unsigned int m_FaultTime;
- unsigned int m_ReadRetryCount;
- unsigned int m_WriteRetryCount;
- unsigned int m_FaultRetryCount;
- std::vector<Device* > m_vDevice;
- std::vector<BYTE> m_vReadBuf;
- std::vector<BYTE> m_vWriteBuf;
- CallBackHandleI* m_pCB;
- bool isHDInitOK;
-
- STATE m_state;//---通道处于数据发送或者接受状态
-
- MThreadedJobQImpl* m_preadJobThread;//----读任务线程
-
- Base m_base;
-
- pthread_mutex_t xLock;
-
- DAControlerI* pDa;
- };
-
- #endif /* SERVICEMODEL_CHANNEL_H_ */
|