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