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#include "mojo/public/cpp/system/macros.h"
10
11namespace mojo {
12
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_|.
16class MessageFilter : public MessageReceiver {
17 public:
18  // Doesn't take ownership of |sink|. Therefore |sink| has to stay alive while
19  // this object is alive.
20  explicit MessageFilter(MessageReceiver* sink = NULL);
21  virtual ~MessageFilter();
22
23  void set_sink(MessageReceiver* sink) { sink_ = sink; }
24
25 protected:
26  MessageReceiver* sink_;
27};
28
29// A trivial filter that simply forwards every message it receives to |sink_|.
30class PassThroughFilter : public MessageFilter {
31 public:
32  explicit PassThroughFilter(MessageReceiver* sink = NULL);
33
34  virtual bool Accept(Message* message) MOJO_OVERRIDE;
35};
36
37}  // namespace mojo
38
39#endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_FILTER_H_
40