コード例 #1
0
wxThread::ExitCode PFMMonitorThread::Entry()
{
	const int timeoutMSecs = 50;
	long long startChangeInstance = 0, nextChangeInstance = 0;
	PfmApi *pfmApi = PFMProxy::getInstance().getPfmApi();

	// Get the main frame window
	EncFSMPMainFrame *pMainFrame = NULL;
	wxWindow *pTopWindow = wxTheApp->GetTopWindow();
	if(pTopWindow != NULL)
	{
		pMainFrame = dynamic_cast<EncFSMPMainFrame *>(pTopWindow);
	}

	while(!TestDestroy())
	{
		int retVal = pfmMonitor_->Wait(nextChangeInstance, timeoutMSecs);
		bool sendEvents = true;
		{
			wxMutexLocker lock(mutex_);
			sendEvents = sendEvents_;
		}

		if(sendEvents)
		{
			PfmIterator *iter = NULL;
			pfmApi->MountIterate(startChangeInstance, &nextChangeInstance, &iter);

			long long curChangeInstance = 0;
			int mountId = iter->Next(&curChangeInstance);
			while(mountId > 0)
			{
				if(curChangeInstance >= startChangeInstance)
				{
					PfmMount *curMount = NULL;
					int err = pfmApi->MountIdOpen(mountId, &curMount);

					if(err == 0 && curMount != NULL)
					{
						int statusFlags = curMount->GetStatusFlags();

						std::wstring formatterName(curMount->GetFormatterName());
						std::wstring fileName(curMount->GetMountSourceName());
						wchar_t driveLetter = curMount->GetDriveLetter();
#if !defined(EFS_WIN32)
						driveLetter = L' ';
#endif
						std::wstring ownerName(curMount->GetOwnerName());
						std::wstring ownerId(curMount->GetOwnerId());
						std::wstring mountPoint(curMount->GetMountPoint());

						if(formatterName == EncFSMPStrings::formatterName_)
						{
							if((statusFlags & (pfmStatusFlagReady | pfmStatusFlagDisconnected | pfmStatusFlagClosed)) != 0)
							{
								bool isMountEvent = ((statusFlags & (pfmStatusFlagDisconnected | pfmStatusFlagClosed)) == 0);
								pMainFrame->addNewMountEvent(isMountEvent, false, fileName, driveLetter, mountPoint);
							}
						}

						curMount->Release();
					}
				}
				mountId = iter->Next(&curChangeInstance);
			}

			iter->Release();
			startChangeInstance = nextChangeInstance;
		}
	}

	return 0;
}