Exemple #1
0
void BBWinCentralHandler::run() {
	DWORD 		dwWait;
	std::list<BBWinHandler *>::iterator		itr;
	
	clientLocalCfgPath = m_data.setting["tmppath"] + (string)"\\clientlocal.cfg";
	for (;;) {
		std::ofstream	report(reportPath.c_str(), std::ios_base::trunc | ios_base::binary);
		bool		created = false;

		if (report) {
			report << "client " << m_data.setting["hostname"] << ".bbwin " << m_data.setting["configclass"] << "\n";
			report.close();
			created = true;
			GetClock();
			string		osversion;
			uname(osversion);
			bbwinClientData_callback("osversion", osversion);
		} else {
			string mess, err;

			mess = (string)"failed to create the report file " + reportPath;
			GetLastErrorString(err);
			LPCTSTR		args[] = {mess.c_str(), err.c_str(), NULL};
			m_log->reportErrorEvent(BBWIN_SERVICE, EVENT_HOBBIT_FAILED_CLIENTDATA, 2, args);
		}

		for (itr = m_agents.begin(); itr != m_agents.end(); ++itr) {
			(*itr)->Run();
			dwWait = WaitForMultipleObjects(m_hCount, m_hEvents , FALSE, 0);
			if (( dwWait >= WAIT_OBJECT_0 && dwWait <= (WAIT_OBJECT_0 + m_hCount - 1) ) || (dwWait >= WAIT_ABANDONED_0 && dwWait <= (WAIT_ABANDONED_0 + m_hCount - 1) )) {
				DeleteFile(reportPath.c_str());
				return ;
			}
		}
		if (created) {
			bbdisplay_t::iterator			itr;
			
			string		result;

			for (itr = m_bbdisplay.begin(); itr != m_bbdisplay.end(); ++itr) {
				BBWinNet	hobNet;
				hobNet.SetBBDisplay((*itr));
				try {
					hobNet.ClientData(reportPath, clientLocalCfgPath);
				} catch (BBWinNetException ex) {
					string mess, err;

					GetLastErrorString(err);
					mess = ex.getMessage();
					LPCTSTR		args[] = {mess.c_str(), err.c_str(), NULL};
					m_log->reportErrorEvent(BBWIN_SERVICE, EVENT_HOBBIT_FAILED_CLIENTDATA, 2, args);
				}
			}
			DeleteFile(reportSavePath.c_str());
			MoveFile(reportPath.c_str(), reportSavePath.c_str());
			DeleteFile(reportPath.c_str());
		}
		dwWait = WaitForMultipleObjects(m_hCount, m_hEvents , FALSE, m_timer * 1000 );
		if ( dwWait >= WAIT_OBJECT_0 && dwWait <= (WAIT_OBJECT_0 + m_hCount - 1) ) {    
			break ;
		} else if (dwWait >= WAIT_ABANDONED_0 && dwWait <= (WAIT_ABANDONED_0 + m_hCount - 1) ) {
			break ;
		}
	}
}