1 // Copyright 2013 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.
5 #ifndef MOJO_COMMON_HANDLE_WATCHER_H_
6 #define MOJO_COMMON_HANDLE_WATCHER_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/run_loop.h"
12 #include "mojo/common/mojo_common_export.h"
13 #include "mojo/public/system/core_cpp.h"
22 class HandleWatcherTest
;
25 // HandleWatcher is used to asynchronously wait on a handle and notify a Closure
26 // when the handle is ready, or the deadline has expired.
27 class MOJO_COMMON_EXPORT HandleWatcher
{
32 // Starts listening for |handle|. This implicitly invokes Stop(). In other
33 // words, Start() performs one asynchronous watch at a time. It is ok to call
34 // Start() multiple times, but it cancels any existing watches. |callback| is
35 // notified when the handle is ready, invalid or deadline has passed and is
36 // notified on the thread Start() was invoked on.
37 void Start(const Handle
& handle
,
38 MojoWaitFlags wait_flags
,
39 MojoDeadline deadline
,
40 const base::Callback
<void(MojoResult
)>& callback
);
42 // Stops listening. Does nothing if not in the process of listening.
48 // See description of |StartState::weak_factory| for details.
49 void OnHandleReady(MojoResult result
);
51 // If non-NULL Start() has been invoked.
52 scoped_ptr
<StartState
> start_state_
;
54 DISALLOW_COPY_AND_ASSIGN(HandleWatcher
);
60 #endif // MOJO_COMMON_HANDLE_WATCHER_H_