summaryrefslogtreecommitdiffstats
path: root/mojo/public/tests/simple_bindings_support.h
blob: e124625633fa3b0c3e02e3fd00c8327b78214f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_PUBLIC_TESTS_SIMPLE_BINDINGS_SUPPORT_H_
#define MOJO_PUBLIC_TESTS_SIMPLE_BINDINGS_SUPPORT_H_

#include <list>

#include "mojo/public/bindings/lib/bindings_support.h"

namespace mojo {
namespace test {

class SimpleBindingsSupport : public BindingsSupport {
 public:
  SimpleBindingsSupport();
  virtual ~SimpleBindingsSupport();

  virtual Buffer* SetCurrentBuffer(Buffer* buf) MOJO_OVERRIDE;
  virtual Buffer* GetCurrentBuffer() MOJO_OVERRIDE;

  virtual AsyncWaitID AsyncWait(const Handle& handle,
                                MojoWaitFlags flags,
                                AsyncWaitCallback* callback) MOJO_OVERRIDE;
  virtual void CancelWait(AsyncWaitID async_wait_id) MOJO_OVERRIDE;

  // This method is called by unit tests to check the status of any handles
  // that we are asynchronously waiting on and to dispatch callbacks for any
  // handles that are ready.
  void Process();

 private:
  bool IsReady(const Handle& handle, MojoWaitFlags flags, MojoResult* result);

  struct Waiter {
    Handle handle;
    MojoWaitFlags flags;
    AsyncWaitCallback* callback;
  };

  typedef std::list<Waiter*> WaiterList;
  WaiterList waiters_;

  Buffer* buf_;
};

}  // namespace test
}  // namespace mojo

#endif  // MOJO_PUBLIC_TESTS_SIMPLE_BINDINGS_SUPPORT_H_