Block until an event of the given type is received. Note: The calling function is responsible for deleting the returned SVEvent afterwards!
| 447 | /// Note: The calling function is responsible for deleting the returned |
| 448 | /// SVEvent afterwards! |
| 449 | SVEvent* ScrollView::AwaitEvent(SVEventType type) { |
| 450 | // Initialize the waiting semaphore. |
| 451 | SVSemaphore* sem = new SVSemaphore(); |
| 452 | std::pair<ScrollView*, SVEventType> ea(this, type); |
| 453 | waiting_for_events_mu->Lock(); |
| 454 | waiting_for_events[ea] = std::pair<SVSemaphore*, SVEvent*> (sem, (SVEvent*)0); |
| 455 | waiting_for_events_mu->Unlock(); |
| 456 | // Wait on it, but first flush. |
| 457 | stream_->Flush(); |
| 458 | sem->Wait(); |
| 459 | // Process the event we got woken up for (its in waiting_for_events pair). |
| 460 | waiting_for_events_mu->Lock(); |
| 461 | SVEvent* ret = waiting_for_events[ea].second; |
| 462 | waiting_for_events.erase(ea); |
| 463 | delete sem; |
| 464 | waiting_for_events_mu->Unlock(); |
| 465 | return ret; |
| 466 | } |
| 467 | |
| 468 | // Block until any event on any window is received. |
| 469 | // No event is returned here! |
no test coverage detected