Пример #1
0
void CPanasonic::ReloadNodes()
{
	UnloadNodes();

	//m_ios.reset();	// in case this is not the first time in

	std::vector<std::vector<std::string> > result;
	result = m_sql.safe_query("SELECT ID,Name,MacAddress,Timeout FROM WOLNodes WHERE (HardwareID==%d)", m_HwdID);
	if (result.size() > 0)
	{
		boost::lock_guard<boost::mutex> l(m_mutex);

		// create a vector to hold the nodes
		for (std::vector<std::vector<std::string> >::const_iterator itt = result.begin(); itt != result.end(); ++itt)
		{
			std::vector<std::string> sd = *itt;
			boost::shared_ptr<CPanasonicNode>	pNode = (boost::shared_ptr<CPanasonicNode>) new CPanasonicNode(m_HwdID, m_iPollInterval, m_iPingTimeoutms, sd[0], sd[1], sd[2], sd[3]);
			m_pNodes.push_back(pNode);
		}
		// start the threads to control each Panasonic TV
		for (std::vector<boost::shared_ptr<CPanasonicNode> >::iterator itt = m_pNodes.begin(); itt != m_pNodes.end(); ++itt)
		{
			_log.Log(LOG_NORM, "Panasonic Plugin: (%s) Starting thread.", (*itt)->m_Name.c_str());
			boost::thread* tAsync = new boost::thread(&CPanasonicNode::Do_Work, (*itt));
		}
		sleep_milliseconds(100);
		//_log.Log(LOG_NORM, "Panasonic Plugin: Starting I/O service thread.");
		//boost::thread bt(boost::bind(&boost::asio::io_service::run, &m_ios));
	}
}
Пример #2
0
void CPanasonic::Do_Work()
{
	int scounter = 0;

	ReloadNodes();

	while (!m_stoprequested)
	{
		if (scounter++ >= (m_iPollInterval * 2))
		{
			boost::lock_guard<boost::mutex> l(m_mutex);

			scounter = 0;
			bool bWorkToDo = false;
			std::vector<boost::shared_ptr<CPanasonicNode> >::iterator itt;
			for (itt = m_pNodes.begin(); itt != m_pNodes.end(); ++itt)
			{
				if (!(*itt)->IsBusy())
				{
					_log.Log(LOG_NORM, "Panasonic Plugin: (%s) - Restarting thread.", (*itt)->m_Name.c_str());
					(*itt)->StartThread();
				}
				if ((*itt)->IsOn()) bWorkToDo = true;
			}
		}
		sleep_milliseconds(500);
	}
	UnloadNodes();
	_log.Log(LOG_STATUS, "Panasonic Plugin: Worker stopped...");
}
Пример #3
0
void CPanasonic::Do_Work()
{
	int scounter = 0;

	ReloadNodes();

	while (!m_stoprequested)
	{
		if (scounter++ >= (m_iPollInterval * 2))
		{
			boost::lock_guard<boost::mutex> l(m_mutex);

			scounter = 0;
			bool bWorkToDo = false;
			std::vector<boost::shared_ptr<CPanasonicNode> >::iterator itt;
			for (itt = m_pNodes.begin(); itt != m_pNodes.end(); ++itt)
			{
				if (!(*itt)->IsBusy())
				{
					_log.Log(LOG_NORM, "Panasonic Plugin: (%s) - Restarting thread.", (*itt)->m_Name.c_str());
					boost::thread* tAsync = new boost::thread(&CPanasonicNode::Do_Work, (*itt));
					//m_ios.stop();
				}
				if ((*itt)->IsOn()) bWorkToDo = true;
			}

			//if (bWorkToDo && m_ios.stopped())  // make sure that there is a boost thread to service i/o operations
			//{
			//	m_ios.reset();
			//	// Note that this is the only thread that handles async i/o so we don't
			//	// need to worry about locking or concurrency issues when processing messages
			//	_log.Log(LOG_NORM, "Panasonic Plugin: Restarting I/O service thread.");
			//	boost::thread bt(boost::bind(&boost::asio::io_service::run, &m_ios));
			//}
		}
		sleep_milliseconds(500);
	}

	UnloadNodes();

	_log.Log(LOG_STATUS, "Panasonic Plugin: Worker stopped...");
}
Пример #4
0
void BleBox::ReloadNodes()
{
	UnloadNodes();
	LoadNodes();
}
Пример #5
0
void BleBox::RemoveAllNodes()
{
	m_sql.safe_query("DELETE FROM DeviceStatus WHERE (HardwareID==%d)", m_HwdID);

	UnloadNodes();
}