Пример #1
0
inline s32 Factory::AddDevice(DeviceParam & pParam)
{
	s32 nId = GetDeviceID();
	FactoryDeviceChangeData change;
	Device *pDevice = NULL;
	DeviceParam pParam2;

	Lock();
	pParam.m_Conf.data.conf.nId = nId;
	if (pParam.m_Conf.data.conf.nType == VSC_DEVICE_CAM)
	{
		m_DeviceMap[nId] = new Device(*m_pVdb, *m_pVHdfsdb, pParam);
		pDevice = m_DeviceMap[nId]; 
	}else
	{
		m_DeviceMap[nId] = NULL;
		return -1;
	}
	m_DeviceParamMap[nId] = pParam;
	m_DeviceOnlineMap[nId] = 0;
	m_Conf.AddDevice(pParam.m_Conf, nId);

	UnLock();
	change.id = nId;
	change.type = FACTORY_DEVICE_ADD;
	CallDeviceChange(change);

	/* Try to online the device and lock */
	Lock();
	pDevice->GetDeviceParam(pParam2);
	UnLock();

	pParam2.m_wipOnline = pParam2.CheckOnline();
	if (pParam2.m_OnlineUrl == FALSE)
	{
		pParam2.m_wipOnlineUrl = pParam2.UpdateUrl();
	}

	/* Try to make the device online */
	Lock();
	DeviceStatus bCheck = pDevice->CheckDevice(pParam2.m_strUrl, 
			pParam2.m_strUrlSubStream, pParam2.m_bHasSubStream, 
			pParam2.m_wipOnline, pParam2.m_wipOnlineUrl);

	FactoryDeviceChangeData change2;
	change2.id = nId;
	
	if (bCheck == DEV_OFF2ON)
	{
		change.type = FACTORY_DEVICE_ONLINE;
		m_DeviceOnlineMap[nId] = 1;
		UnLock(); 
		CallDeviceChange(change);
		Lock();
	}
	UnLock();
	
    	return nId;
}
Пример #2
0
inline void Factory::run()
{
    DeviceParamMap paramMap;
    /* Create the thread to update the Disk status */
    while (1)
    {
        paramMap.clear();
        {
            /* Got all the device param */
            Lock();
            DeviceMap::iterator it = m_DeviceMap.begin();
            for(; it!=m_DeviceMap.end(); ++it)
            {
                s32 nIndex = (*it).first;
                DeviceParam pParam;
                Device *pDevice = m_DeviceMap[nIndex];
                if (pDevice == NULL)
                {
                    continue;//TODO
                }
                pDevice->GetDeviceParam(pParam);
                paramMap[nIndex] = pParam;
            }
            UnLock();
        }
        {
            /* Loop all the deviceparam */
            DeviceParamMap::iterator it = paramMap.begin();
            for(; it!=paramMap.end(); ++it)
            {
                /* Loop to check the device and update the url */
                s32 nIndex = (*it).first;
                (*it).second.m_wipOnline = (*it).second.CheckOnline();
                if ((*it).second.m_OnlineUrl == FALSE)
                {
                    (*it).second.m_wipOnlineUrl = (*it).second.UpdateUrl();

                    if ((*it).second.m_wipOnlineUrl == FALSE)
                    {
                        (*it).second.m_wipOnline = FALSE;
                    }

                }
            }
        }
        {
            /* Loop all the deviceparam result and set to device */
            DeviceParamMap::iterator it = paramMap.begin();
            for(; it!=paramMap.end(); ++it)
            {
                /* Loop to check the device and update the url */
                s32 nIndex = (*it).first;
                Lock();
                DeviceMap::iterator it1 = m_DeviceMap.find(nIndex),
                                    ite1 = m_DeviceMap.end();

                if (it1 == ite1)
                {
                    /* the id may be delete */
                    UnLock();
                    continue;
                }

                DeviceStatus bCheck = m_DeviceMap[nIndex]->CheckDevice(
                                          (*it).second.m_strUrl, (*it).second.m_strUrlSubStream,
                                          (*it).second.m_bHasSubStream,
                                          (*it).second.m_wipOnline, (*it).second.m_wipOnlineUrl);

                FactoryDeviceChangeData change;
                change.id = nIndex;
                switch (bCheck)
                {
                case DEV_OFF2ON:
                {
                    change.type = FACTORY_DEVICE_ONLINE;
                    m_DeviceOnlineMap[nIndex] = 1;
                    UnLock();
                    CallDeviceChange(change);
                    Lock();
                    break;
                }
                case DEV_ON2OFF:
                {
                    change.type = FACTORY_DEVICE_OFFLINE;
                    m_DeviceOnlineMap[nIndex] = 0;
                    UnLock();
                    CallDeviceChange(change);
                    Lock();
                    break;
                }
                default:
                {

                    break;
                }
                }
                UnLock();
            }
        }
        ve_sleep(1000 * 3);
    }

}