123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #include "stdafx.h"
- #include <atlbase.h>
- #include "DevicesManager.h"
- #pragma warning(push)
- #pragma warning(disable:4995)
- #pragma warning(pop)
- //------------------- CDevicesManager ------------------------
- CDevicesManager::CDevicesManager()
- {
- }
- CDevicesManager::~CDevicesManager()
- {
- ClearUp();
- }
- void CDevicesManager::ClearUp()
- {
- for (int i = 0; i < m_Devices.GetSize(); i++)
- {
- for(int j = 0; j < m_Devices[i]->m_Vars.GetSize(); j++ )
- {
- MTVERIFY(delete m_Devices[i]->m_Vars[j]);
- }
- m_Devices[i]->m_Vars.RemoveAll();
- MTVERIFY(delete m_Devices[i]);
- }
- m_Devices.RemoveAll();
- }
- BOOL CDevicesManager::FindDev(CString strName, int &nDeviceIndex)
- {
- BOOL bResult = FALSE;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- if( m_Devices[i]->m_strDeviceName == strName )
- {
- bResult = TRUE;
- nDeviceIndex = i;
- break;
- }
- }
- return bResult;
- }
- BOOL CDevicesManager::FindDevByUid(CString strUid, int &nDeviceIndex)
- {
- BOOL bResult = FALSE;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- if( m_Devices[i]->m_strUid.Compare(strUid) == 0 )
- {
- bResult = TRUE;
- nDeviceIndex = i;
- //LOG4C((LOG_NOTICE, "nDeviceIndex = %d, devuid = %s", nDeviceIndex, m_Devices[i]->m_strUid));
- break;
- }
- }
- return bResult;
- }
- BOOL CDevicesManager::FindDev(CString strIP, int m_nPort, int &nDeviceIndex)
- {
- BOOL bResult = FALSE;
- for( int i = 0; i < m_Devices.GetSize(); i++ )
- {
- if( m_Devices[i]->m_strIp == strIP &&
- m_Devices[i]->m_iIpport == m_nPort )
- {
- bResult = TRUE;
- nDeviceIndex = i;
- break;
- }
- }
- return bResult;
- }
- BOOL CDevicesManager::FindVar(int nDeviceIndex, int nVarID, int &nVarIndex)
- {
- BOOL bResult = FALSE;
- CDevice* pDevice = m_Devices[nDeviceIndex];
- for( int i = 0; i < pDevice->m_Vars.GetSize(); i++ )
- {
- CBaseVar *pBaseVar = pDevice->m_Vars[i];
- if( pBaseVar->m_nVarID == nVarID )
- {
- bResult = TRUE;
- nVarIndex = i;
- break;
- }
- }
- return bResult;
- }
|