blob: 014e5c1ab3e2952c2f17361246fa979ff71bacb1 [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Viet-Trung Luue766dce2015-07-29 14:55:47 -07005#include "mojo/environment/default_async_waiter.h"
James Robinson646469d2014-10-03 15:33:28 -07006
7#include "base/bind.h"
James Robinson94ade6b2015-08-25 13:02:06 -07008#include "mojo/message_pump/handle_watcher.h"
Viet-Trung Luue766dce2015-07-29 14:55:47 -07009#include "mojo/public/c/environment/async_waiter.h"
James Robinson646469d2014-10-03 15:33:28 -070010
11namespace mojo {
12namespace internal {
13namespace {
14
15void OnHandleReady(common::HandleWatcher* watcher,
16 MojoAsyncWaitCallback callback,
17 void* closure,
18 MojoResult result) {
19 delete watcher;
20 callback(closure, result);
21}
22
23MojoAsyncWaitID AsyncWait(MojoHandle handle,
24 MojoHandleSignals signals,
25 MojoDeadline deadline,
26 MojoAsyncWaitCallback callback,
27 void* closure) {
28 // This instance will be deleted when done or cancelled.
29 common::HandleWatcher* watcher = new common::HandleWatcher();
30 watcher->Start(Handle(handle), signals, deadline,
31 base::Bind(&OnHandleReady, watcher, callback, closure));
32 return reinterpret_cast<MojoAsyncWaitID>(watcher);
33}
34
35void CancelWait(MojoAsyncWaitID wait_id) {
36 delete reinterpret_cast<common::HandleWatcher*>(wait_id);
37}
38
James Robinson646469d2014-10-03 15:33:28 -070039} // namespace
40
Viet-Trung Luue766dce2015-07-29 14:55:47 -070041const MojoAsyncWaiter kDefaultAsyncWaiter = {AsyncWait, CancelWait};
James Robinson646469d2014-10-03 15:33:28 -070042
43} // namespace internal
44} // namespace mojo