1 // 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.
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_FILTER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_FILTER_H_
8 #include "mojo/public/cpp/bindings/message.h"
9 #include "mojo/public/cpp/system/macros.h"
13 // This class is the base class for message filters. Subclasses should
14 // implement the pure virtual method Accept() inherited from MessageReceiver to
15 // process messages and/or forward them to |sink_|.
16 class MessageFilter : public MessageReceiver {
18 // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
19 // this object is alive.
20 explicit MessageFilter(MessageReceiver* sink = nullptr);
21 ~MessageFilter() override;
23 void set_sink(MessageReceiver* sink) { sink_ = sink; }
26 MessageReceiver* sink_;
29 // A trivial filter that simply forwards every message it receives to |sink_|.
30 class PassThroughFilter : public MessageFilter {
32 explicit PassThroughFilter(MessageReceiver* sink = nullptr);
34 bool Accept(Message* message) override;
39 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_FILTER_H_