📄 devmgr.cpp
字号:
// DevMgr.cpp: implementation of the CDevMgr class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "netsdkdemo.h"
#include "DevMgr.h"
#include <algorithm>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Get CDevMgr object
//////////////////////////////////////////////////////////////////////
CDevMgr& CDevMgr::GetDevMgr(void)
{
static CDevMgr devmgr;
return devmgr;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDevMgr::CDevMgr()
{
::InitializeCriticalSection(&m_cs);
}
CDevMgr::~CDevMgr()
{
list<DeviceNode*>::iterator it = m_lstDevice.begin();
for(; it != m_lstDevice.end(); ++it)
{
if (*it)
{
delete (*it);
}
}
m_lstDevice.clear();
::DeleteCriticalSection(&m_cs);
}
void CDevMgr::For_EachDev(int (* cbForEach)(const DeviceNode& node, DWORD dwUser), DWORD dwUser)
{
::EnterCriticalSection(&m_cs);
list<DeviceNode*>::iterator it = m_lstDevice.begin();
for(; it != m_lstDevice.end(); ++it)
{
int nRet = cbForEach(**it, dwUser);
if (1 == nRet)
{
break;
}
int i = (*it)->TotalKbps;
}
::LeaveCriticalSection(&m_cs);
}
int CDevMgr::GetDev(LONG lLoginID, DeviceNode& node)
{
int nRet = -1;
::EnterCriticalSection(&m_cs);
list<DeviceNode*>::iterator it =
find_if(m_lstDevice.begin(), m_lstDevice.end(),
CDevMgr::SearchDevByHandle(lLoginID));
if (it != m_lstDevice.end())
{
memcpy(&node, *it, sizeof(DeviceNode));
nRet = 0;
}
::LeaveCriticalSection(&m_cs);
return nRet;
}
int CDevMgr::SetAlarmInfo(LONG lLoginID, LONG lCommand, char *pchDVRIP, LONG nDVRPort,
char *pBuf, DWORD dwBufLen)
{
int nRet = -1;
::EnterCriticalSection(&m_cs);
list<DeviceNode*>::iterator it =
find_if(m_lstDevice.begin(), m_lstDevice.end(),
CDevMgr::SearchDevByHandle(lLoginID));
if (it != m_lstDevice.end())
{
switch(lCommand)
{
case COMM_ALARM:
{
NET_CLIENT_STATE *State = (NET_CLIENT_STATE *)pBuf;
if(!State)
{
break;
}
//设备列表中信息刷新
(*it)->State.channelcount = State->channelcount;
(*it)->State.alarminputcount = State->alarminputcount;
memcpy((*it)->State.diskerror, State->diskerror, 32);
//录像状态
if((*it)->State.record == NULL)
{
(*it)->State.record = new BYTE[(*it)->State.channelcount];
}
memcpy((*it)->State.record, State->record, (*it)->State.channelcount );
//报警状态
if((*it)->State.alarm == NULL)
{
(*it)->State.alarm = new BYTE[(*it)->State.alarminputcount];
}
memcpy((*it)->State.alarm, State->alarm, (*it)->State.alarminputcount );
//动态检测报警
if((*it)->State.motiondection == NULL)
{
(*it)->State.motiondection = new BYTE[(*it)->State.channelcount];
}
memcpy((*it)->State.motiondection, State->motiondection, (*it)->State.channelcount );
//视频丢失报警
if((*it)->State.videolost == NULL)
{
(*it)->State.videolost = new BYTE[(*it)->State.channelcount];
}
memcpy((*it)->State.videolost, State->videolost, (*it)->State.channelcount );
nRet = 0;
break;
}
default:
break;
}
}
::LeaveCriticalSection(&m_cs);
return nRet;
}
//add node to list
int CDevMgr::PushBack(DeviceNode* node)
{
if (!node)
{
return -1;
}
int nRet = 0;
::EnterCriticalSection(&m_cs);
m_lstDevice.push_back(node);
::LeaveCriticalSection(&m_cs);
return nRet;
}
//delete node from list
int CDevMgr::DelNode(LONG lLoginID)
{
int nRet = -1;
::EnterCriticalSection(&m_cs);
list<DeviceNode*>::iterator it =
find_if(m_lstDevice.begin(), m_lstDevice.end(),
SearchDevByHandle(lLoginID));
if (it != m_lstDevice.end())
{
delete *it;
m_lstDevice.erase(it);
nRet = 0;
}
::LeaveCriticalSection(&m_cs);
return nRet;
}
BOOL CDevMgr::IsOnline(LONG lLoginID)
{
BOOL b = FALSE;
::EnterCriticalSection(&m_cs);
list<DeviceNode*>::iterator it =
find_if(m_lstDevice.begin(), m_lstDevice.end(),
CDevMgr::SearchDevByHandle(lLoginID));
if (it != m_lstDevice.end())
{
b = TRUE;
}
::LeaveCriticalSection(&m_cs);
return b;
}
BOOL CDevMgr::IsOnline(DeviceNode* node)
{
BOOL b = FALSE;
::EnterCriticalSection(&m_cs);
list<DeviceNode*>::iterator it =
find(m_lstDevice.begin(), m_lstDevice.end(), node);
if (it != m_lstDevice.end())
{
b = TRUE;
}
::LeaveCriticalSection(&m_cs);
return b;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -