Ejemplo n.º 1
0
inline void MFramework::run()
{
    MiningRet ret;
    while (m_bExit != TRUE)
    {
        //VDC_DEBUG("MFramework runing\n");
        if (m_RetQueue.size() > 0)
        {
            ret = m_RetQueue.pop();
            //send the ret va data to factory for showing
            continue;
        } else
        {
            ve_sleep(1000);
        }
    }
    return;
}
Ejemplo n.º 2
0
inline void StorFactory::run()
{
	while(1)
	{
		ve_sleep(1000 * 90);
	}
#if 0

	CameraParamMap paramMap;
	/* Create the thread to update the Disk status */
	while (1)
	{
		paramMap.clear();
		{
			/* Got all the camera param */
			Lock();
			CameraMap::iterator it = m_CameraMap.begin(); 
			for(; it!=m_CameraMap.end(); ++it)
			{	
				s32 nIndex = (*it).first;
				CameraParam pParam;
				Camera *pCamera = m_CameraMap[nIndex];
				if (pCamera == NULL)
				{
					continue;//TODO
				}
				pCamera->GetCameraParam(pParam);
				paramMap[nIndex] = pParam;
			}
			UnLock();
		}
		{
			/* Loop all the cameraparam */
			CameraParamMap::iterator it = paramMap.begin(); 
			for(; it!=paramMap.end(); ++it)
			{	
				/* Loop to check the camera 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 cameraparam result and set to camera */
			CameraParamMap::iterator it = paramMap.begin(); 
			for(; it!=paramMap.end(); ++it)
			{	
				/* Loop to check the camera and update the url */
				s32 nIndex = (*it).first;
				Lock();
				CameraMap::iterator it1 = m_CameraMap.find(nIndex), 
							ite1 = m_CameraMap.end();

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

				CameraStatus bCheck = m_CameraMap[nIndex]->CheckCamera(
					(*it).second.m_strUrl, (*it).second.m_strUrlSubStream, 
					(*it).second.m_bHasSubStream, 
					(*it).second.m_wipOnline, (*it).second.m_wipOnlineUrl);
				
				StorFactoryCameraChangeData change;
				change.id = nIndex;
				switch (bCheck)
				{
					case DEV_OFF2ON:
					{
						change.type = STOR_FACTORY_CAMERA_ONLINE;
						m_CameraOnlineMap[nIndex] = 1;
						UnLock(); 
						CallCameraChange(change);
						Lock();
						break;
					}
					case DEV_ON2OFF:
					{
						change.type = STOR_FACTORY_CAMERA_OFFLINE;
						m_CameraOnlineMap[nIndex] = 0;
						UnLock(); 
						CallCameraChange(change);
						Lock();
						break;
					}
					default:
					{

						break;
					}
				}
				UnLock();
			}
		}
		ve_sleep(1000 * 90);
	}
#endif
	
}
Ejemplo n.º 3
0
inline void StorClient::run()
{
	OAPIHeader header;
	int frameCnt =0;
	char *pRecv = NULL;
	int nRecvLen = 0;
	s32 nRet = 0;
	ck_string ckPort = m_stor.strport();

	u16 Port = ckPort.to_uint16(10);
	XGuard guard(m_cMutex);
	guard.Release();

	while(m_Quit != true)
	{
		ve_sleep(500);
		guard.Acquire();
		m_bOnline = false;
		
		try
		{
			XSDK::XString host = m_stor.strip();
			
			m_pSocket->Connect(host, Port);
			
			oapi::OAPICameraListRsp list;
			OAPIClient pClient(m_pSocket);
			
			pClient.Setup(m_stor.struser(), m_stor.strpasswd(), "Nonce");
			
	
			m_pSocket->SetRecvTimeout(1 * 300);
			while(m_Quit != true)
			{
				nRet = m_pSocket->Recv((void *)&header, sizeof(header));
				if (nRet != sizeof(header))
				{
					if (m_pSocket->Valid() == true)
					{
						/* Have not recevice any data */
						guard.Release();
						ve_sleep(200);
						guard.Acquire();
						continue;
					}else
					{
						m_pSocket->Close();
						break;
					}
				}
				//printf("%s---%d\n", __FILE__, __LINE__);

				header.version = ntohl(header.version);
				header.cmd = ntohl(header.cmd);
				header.length = ntohl(header.length);
				if (header.length > nRecvLen)
				{
					if (pRecv)
					{
						delete [] pRecv;
						pRecv = NULL;
					}
					pRecv = new char[header.length + 1];
					nRecvLen = header.length + 1;
				}
				
				s32 nRetBody = m_pSocket->Recv((void *)pRecv, header.length);
				if (nRetBody == header.length)
				{
					
					switch(header.cmd)
					{
						case OAPI_CMD_DEVICE_LIST_RSP:
						{
							oapi::OAPICameraListRsp list;
							pClient.ParseDeviceList(pRecv, header.length, list);
							UpdateVidCameraList(list);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_STOR_ONLINE;
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							m_bOnline = true;
							break;
						}
						case OAPI_CMD_LOGIN_RSP:
						{
							oapi::LoginRsp rsp;
							pClient.ParseLogin(pRecv, header.length, rsp);
							if (rsp.bRetNonce == true)
							{
								pClient.Setup(m_stor.struser(), 
										m_stor.strpasswd(), rsp.Nonce);
							}
							if (rsp.bRet == true)
							{
								/* login ok, send device list */
								pClient.SendDeviceListRequest();
							}
							break;
						}
						case OAPI_CMD_FRAME_PUSH:
						{
							//printf("Go a new frame %d\n", frameCnt++);
							break;
						}
						case OAPI_NOTIFY_DEVICE_ADD:
						{
							oapi::OAPICamAddNotify cam;
							pClient.ParseDevice(pRecv, header.length, cam);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_CAMERA_ADD;
							OAPIConverter::Converter(cam.cam, data.cCam);
							data.cId.set_strcameraid(data.cCam.strid());
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							//pClient.SendDeviceListRequest();
							m_bOnline = true;
							break;
						}
						case OAPI_NOTIFY_DEVICE_DEL:
						{
							astring strId;
							pClient.ParseDeviceStrId(pRecv, header.length, strId);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_CAMERA_DEL;
							data.cId.set_strcameraid(strId);
							
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							//pClient.SendDeviceListRequest();
							break;
						}
							break;
						case OAPI_NOTIFY_DEVICE_ONLINE:
						{
							astring strId;
							pClient.ParseDeviceStrId(pRecv, header.length, strId);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_CAMERA_ONLINE;
							data.cId.set_strcameraid(strId);
							
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							//pClient.SendDeviceListRequest();
							break;
						}
						case OAPI_NOTIFY_DEVICE_OFFLINE:
						{
							astring strId;
							pClient.ParseDeviceStrId(pRecv, header.length, strId);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_CAMERA_OFFLINE;
							data.cId.set_strcameraid(strId);
							
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							//pClient.SendDeviceListRequest();
							break;
						}
						case OAPI_NOTIFY_DEVICE_REC_ON:
						{
							astring strId;
							pClient.ParseDeviceStrId(pRecv, header.length, strId);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_CAMERA_REC_ON;
							data.cId.set_strcameraid(strId);
							
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							//pClient.SendDeviceListRequest();
							break;
						}
						case OAPI_NOTIFY_DEVICE_REC_OFF:
						{
							astring strId;
							pClient.ParseDeviceStrId(pRecv, header.length, strId);
							StorFactoryChangeData data;
							data.cId.set_strstorid(m_stor.strid());
							data.type = STOR_FACTORY_CAMERA_REC_OFF;
							data.cId.set_strcameraid(strId);
							
							guard.Release();
							m_pNotify.CallChange(data);
							guard.Acquire();
							//pClient.SendDeviceListRequest();
							break;
						}
						default:
							break;		
					}

					guard.Acquire();
				}

			}

		}
		catch( XSDK::XException& ex )
		{
			
		}

		guard.Release();

	}

}
Ejemplo n.º 4
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;
				m_DeviceMap[nIndex]->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();
				}
			}
		}
		{
			/* 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;
						UnLock(); 
						CallDeviceChange(change);
						Lock();
						break;
					}
					case DEV_ON2OFF:
					{
						change.type = FACTORY_DEVICE_OFFLINE;
						UnLock(); 
						CallDeviceChange(change);
						Lock();
						break;
					}
					default:
					{

						break;
					}
				}
				UnLock();
			}
		}
		ve_sleep(1000 * 20);
	}
	
}
Ejemplo n.º 5
0
inline void VEventServerDbTask::UpdateDBSession(bool bIsFirst)
{
	std::time_t pTime = time(NULL);

	/* Get the Event Server Conf */
	VidEventDBConf cDBConf;
	m_Factory.GetEventDBConf(cDBConf);

	Poco::Timestamp pTimeStamp = Poco::Timestamp::fromEpochTime(pTime);

	/* Use next sec to check  */
	Poco::DateTime pTimeTime(pTimeStamp);

	int nYear = pTimeTime.year();
	int nMonth = pTimeTime.month();
	int nHour = pTimeTime.hour();

	if (bIsFirst != true)
	{

		/* Every day check if need new database */
		if (pTime%3600 != 0 || nHour != 0)
		{
			return;
		}

		if (nYear == m_nYear && nMonth == m_nMonth)
		{
			return;
		}
	}

	m_nYear = nYear;
	m_nMonth = nMonth;

	char strPlus[1024];
	sprintf(strPlus, "%d_%d", m_nYear, nMonth);
	
	if (cDBConf.ntype() == VID_DB_SQLITE)
	{
		if (m_pSqlSession != NULL)
		{
			delete m_pSqlSession;
			m_pSqlSession = NULL;
		}
		try
		{	
			Poco::Path path(cDBConf.strdbpath());
			Poco::File file(path);
			file.createDirectories();
			SQLite::Connector::registerConnector();
			VDC_DEBUG("Create the Event DB path %s\n", path.toString().c_str());
			
			Poco::Path filePath("eventdb.db");
			path.append(filePath);
			path.makeFile();
			VDC_DEBUG("Create the Event DB file %s\n", path.toString().c_str());

			m_pSqlSession = new Poco::Data::Session("SQLite", path.toString());
			*m_pSqlSession << "CREATE TABLE IF NOT EXISTS events "
				"(id INTEGER PRIMARY KEY, strId TEXT, strDevice TEXT, "
				"strDeviceName TEXT, strType TEXT, nTime INTEGER, strEvttime DATE, strDesc TEXT)", now;
		}
		catch (exception const &e)		
		{			
			VDC_DEBUG("%s Create SQLITE session failed \n", __FUNCTION__);
		}

	}else
	{
		VDC_DEBUG( "%s Do not support the DB TYPE \n",__FUNCTION__);
		ve_sleep(1000);
	}	
}