1e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent/* 2e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * 4e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * Use of this source code is governed by a BSD-style license 5e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * that can be found in the LICENSE file in the root of the source 6e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * tree. An additional intellectual property rights grant can be found 7e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * in the file PATENTS. All contributing project authors may 8e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent * be found in the AUTHORS file in the root of the source tree. 9e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent */ 10e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 11e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_ 12e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_ 13e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 14e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentnamespace webrtc { 15e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentenum EventTypeWrapper 16e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent{ 17e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent kEventSignaled = 1, 18e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent kEventError = 2, 19e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent kEventTimeout = 3 20e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent}; 21e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 22e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define WEBRTC_EVENT_10_SEC 10000 23e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#define WEBRTC_EVENT_INFINITE 0xffffffff 24e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 25e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentclass EventWrapper 26e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent{ 27e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurentpublic: 28e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Factory method. Constructor disabled. 29e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent static EventWrapper* Create(); 30e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent virtual ~EventWrapper() {} 31e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 32e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Releases threads who are calling Wait() and has started waiting. Please 33e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // note that a thread calling Wait() will not start waiting immediately. 34e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // assumptions to the contrary is a very common source of issues in 35e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // multithreaded programming. 36e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Set is sticky in the sense that it will release at least one thread 37e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // either immediately or some time in the future. 38e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent virtual bool Set() = 0; 39e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 40e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Prevents future Wait() calls from finishing without a new Set() call. 41e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent virtual bool Reset() = 0; 42e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 43e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Puts the calling thread into a wait state. The thread may be released 44e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // by a Set() call depending on if other threads are waiting and if so on 45e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // timing. The thread that was released will call Reset() before leaving 46e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // preventing more threads from being released. If multiple threads 47e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // are waiting for the same Set(), only one (random) thread is guaranteed to 48e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // be released. It is possible that multiple (random) threads are released 49e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Depending on timing. 50e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent virtual EventTypeWrapper Wait(unsigned long maxTime) = 0; 51e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 52e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Starts a timer that will call a non-sticky version of Set() either once 53e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // or periodically. If the timer is periodic it ensures that there is no 54e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // drift over time relative to the system clock. 55e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent virtual bool StartTimer(bool periodic, unsigned long time) = 0; 56e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 57e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent virtual bool StopTimer() = 0; 58e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 59e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Only implemented on Windows 60e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // Returns 1 if a key has been pressed since last call to this function. 61e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // -1 indicates failure 62e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // 0 indicates no key has been pressed since last call 63e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent // TODO(hellner) this function does not seem to belong here 64e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent static int KeyPressed(); 65e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent}; 66e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent} // namespace webrtc 67e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent 68e48d5845c8b35de2ab73ea055c18a61fa3a9f0beEric Laurent#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_ 69