Ejemplo n.º 1
0
bool mitk::EventMapper::LoadStandardBehavior()
{
  // Search for StateMachine.xml, bypass relative path in mitkSourceTree for additional search

  std::string xmlFileName = mitk::StandardFileLocations::GetInstance()->FindFile("StateMachine.xml", "Core/Code/Interactions");
  if(xmlFileName != "")
    return LoadBehavior(xmlFileName);

  return false;
}
Ejemplo n.º 2
0
	void *LoadBehaviorTimeline(void* arg)
	{
		MaterialMonitorSim* materialMonitorSim = (MaterialMonitorSim*)arg;

		try
		{
			LOG_EXT(LEVEL_INFO, "Loading behavior timeline '.\\" << materialMonitorSim->GetTimelineFile() << "'...");

			XMLDocument doc;
			doc.LoadFile(materialMonitorSim->GetTimelineFile().c_str());

			XMLElement* root = doc.RootElement();
			if (root != NULL)
			{
				XMLElement* behaviorEl = root->FirstChildElement("Behavior");
				XMLElement* lastBehaviorEl = root->LastChildElement("Behavior");
				while (behaviorEl != NULL)
				{
					float interval = 0;
					behaviorEl->QueryFloatAttribute("Interval", &interval);
					LOG_EXT(LEVEL_INFO, "Waiting for behavior for " << interval << " seconds...");
					if (interval > 0)
					{
						// Wait for a specified interval by acquiring a lock;
						// if lock was acquired successfully, destructor was called - shutdown thread.
						timespec ts;
						timeb now;
						ftime(&now);
						ts.tv_sec = now.time + (int)floorf(interval);
						long nsec = now.millitm * 1000000 + (long)((interval - floorf(interval)) * 1000000000);
						ts.tv_sec += nsec / 1000000000;
						ts.tv_nsec = nsec % 1000000000;

						pthread_mutex_t simLifetimeMutex = materialMonitorSim->GetSimLifetimeMutex();
						pthread_cond_t simLifetimeCV = materialMonitorSim->GetSimLifetimeCV();
						pthread_mutex_lock(&simLifetimeMutex);
						int cvStatus = pthread_cond_timedwait(&simLifetimeCV, &simLifetimeMutex, &ts);
						bool timeout;
#ifdef WIN32
						timeout = (cvStatus == WSAETIMEDOUT);
#else
						timeout = (cvStatus == ETIMEDOUT);
#endif

						pthread_mutex_unlock(&simLifetimeMutex);
						if (!timeout)
						{
							break;
						}
					}
					LoadBehavior(materialMonitorSim, behaviorEl->GetText());

					behaviorEl = (behaviorEl == lastBehaviorEl) ? NULL : behaviorEl->NextSiblingElement();
				}

				LOG_EXT(LEVEL_INFO, "Behavior timeline loaded successfully.");
			}
			else
			{
				LOG_EXT(LEVEL_WARN, "Cannot find file root.");
			}
		}
		catch (...)
		{
			LOG_EXT(LEVEL_WARN, "Invalid timeline.");
		}

		return NULL;
	}