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