Esempio n. 1
0
void EventScheduler::simulate()
{
	generateObserverEvents();
	generateArrivalEvents();
	
	while (!m_observerEventQueue->isEmpty() || !m_arrivalEventQueue->isEmpty() || !m_departureEventQueue->isEmpty())
	{
		Event* firstEvent = getFirstEvent(m_observerEventQueue->peekFront(), m_arrivalEventQueue->peekFront(), m_departureEventQueue->peekFront());

		if (firstEvent != NULL)
		{
			switch (firstEvent->getEventType())
			{
			case OBSERVER:
				m_observerEventQueue->dequeue();
				observerEventHandler(*firstEvent);
				break;
			case ARRIVAL:
				m_arrivalEventQueue->dequeue();
				arrivalEventHandler(*firstEvent);
				break;
			case DEPARTURE:
				m_departureEventQueue->dequeue();
				departureEventHandler(*firstEvent);
				break;
			default:
				break;
			}
		}
		
		generateObserverEvents();
		generateArrivalEvents();
	}
	benchmark();
}
Json::Value F::waifForEvent (const std::chrono::seconds timeout)
{
  Json::Value event;
  std::unique_lock <std::mutex> lock (mutex);

  try {
    event = getFirstEvent();
  } catch (KurentoException e) {
    if (!cond.wait_for (lock, timeout, std::bind (&F::receivedEvent, this) ) ) {
      throw kurento::KurentoException (UNEXPECTED_ERROR, "Timeout waiting for event");
    }

    event = getFirstEvent();
  }

  return event;
}