blob: c86bddfa8b1a946d010c3ef92e7efb40df8877f0 [file] [log] [blame]
Steve Antonf2737d22017-10-31 16:27:34 -07001/*
2 * Copyright 2017 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#include "api/proxy.h"
12
13namespace webrtc {
14namespace internal {
15
16SynchronousMethodCall::SynchronousMethodCall(rtc::MessageHandler* proxy)
17 : e_(), proxy_(proxy) {}
18
19SynchronousMethodCall::~SynchronousMethodCall() = default;
20
21void SynchronousMethodCall::Invoke(const rtc::Location& posted_from,
22 rtc::Thread* t) {
23 if (t->IsCurrent()) {
24 proxy_->OnMessage(nullptr);
25 } else {
26 e_.reset(new rtc::Event(false, false));
27 t->Post(posted_from, this, 0);
28 e_->Wait(rtc::Event::kForever);
29 }
30}
31
32void SynchronousMethodCall::OnMessage(rtc::Message*) {
33 proxy_->OnMessage(nullptr);
34 e_->Set();
35}
36
37} // namespace internal
38} // namespace webrtc