blob: 752118023940799d46c3c9e716f81bd9dfd4cbfb (
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
|
// Copyright 2014 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_CPP_BINDINGS_SYNC_DISPATCHER_H_
#define MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_
#include "mojo/public/cpp/system/core.h"
namespace mojo {
class MessageReceiver;
// Waits for one message to arrive on the message pipe, and dispatch it to the
// receiver. Returns true on success, false on failure.
bool WaitForMessageAndDispatch(MessagePipeHandle handle,
mojo::MessageReceiver* receiver);
template<typename Interface> class SyncDispatcher {
public:
SyncDispatcher(ScopedMessagePipeHandle message_pipe, Interface* sink)
: message_pipe_(message_pipe.Pass()) {
stub_.set_sink(sink);
}
bool WaitAndDispatchOneMessage() {
return WaitForMessageAndDispatch(message_pipe_.get(), &stub_);
}
private:
ScopedMessagePipeHandle message_pipe_;
typename Interface::Stub_ stub_;
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_DISPATCHER_H_
|