78 lines
1.7 KiB
C++
78 lines
1.7 KiB
C++
#include "NetworkDevicesMgr.h"
|
|
#include "232NetworkCommIF.h"
|
|
#include "485NetworkCommIF.h"
|
|
#include "EthernetNetworkCommIF.h"
|
|
|
|
|
|
|
|
CNetworkDevicesMgr::CNetworkDevicesMgr()
|
|
{
|
|
|
|
}
|
|
|
|
CNetworkDevicesMgr::~CNetworkDevicesMgr()
|
|
{
|
|
for(int i = 0; i < mNetworkDevicesList.size(); i++)
|
|
{
|
|
delete mNetworkDevicesList.at(i);
|
|
}
|
|
mNetworkDevicesList.clear();
|
|
}
|
|
|
|
int CNetworkDevicesMgr::InitNetworkDevices()
|
|
{
|
|
|
|
C232NetworkCommIF *NetworkInterface = new C232NetworkCommIF();
|
|
CDeadboltDevice *DeadboltDevice = new CDeadboltDevice(1,(CAbstractNetworkCommIF*)NetworkInterface);
|
|
mNetworkDevicesList.append(DeadboltDevice);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CNetworkDevicesMgr::CreateNewSMSDevice(int Address, CAbstractNetworkCommIF *NetworkIF)
|
|
{
|
|
CSMSDevice *SMSDevice = new CSMSDevice(Address,NetworkIF);
|
|
|
|
mNetworkDevicesList.append(SMSDevice);
|
|
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void CNetworkDevicesMgr::EthernetNetworkDeviceDisconnected(CNetworkDevice *Device)
|
|
{
|
|
int index = FindDeviceByPtr(Device);
|
|
if(index != -1)
|
|
{
|
|
delete mNetworkDevicesList.at(index);
|
|
mNetworkDevicesList.removeAt(index);
|
|
}
|
|
}
|
|
|
|
int CNetworkDevicesMgr::FindDeviceByPtr(CNetworkDevice *Device)
|
|
{
|
|
for(int i = 0; i < mNetworkDevicesList.size(); i++)
|
|
{
|
|
if(mNetworkDevicesList.at(i) == Device)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
CNetworkDevice* CNetworkDevicesMgr::GetDevice(int DeviceID, int Address)
|
|
{
|
|
for(int i = 0; i < mNetworkDevicesList.size(); i++)
|
|
{
|
|
if(mNetworkDevicesList.at(i)->GetDeviceID() == DeviceID &&
|
|
mNetworkDevicesList.at(i)->GetDeviceAddress() == Address)
|
|
{
|
|
return mNetworkDevicesList.at(i);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|