chromeos: bluetooth: add BluetoothNodeClient
[chromium-blink-merge.git] / ipc / ipc_test_sink.cc
blob44042390727c75455a5758e16cb55c1be521610a
1 // Copyright (c) 2011 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 #include "ipc/ipc_test_sink.h"
7 #include "ipc/ipc_message.h"
9 namespace IPC {
11 TestSink::TestSink() {
14 TestSink::~TestSink() {
17 bool TestSink::Send(Message* message) {
18 OnMessageReceived(*message);
19 delete message;
20 return true;
23 bool TestSink::OnMessageReceived(const Message& msg) {
24 ObserverListBase<Channel::Listener>::Iterator it(filter_list_);
25 Channel::Listener* observer;
26 while ((observer = it.GetNext()) != NULL) {
27 if (observer->OnMessageReceived(msg))
28 return true;
31 // No filter handled the message, so store it.
32 messages_.push_back(Message(msg));
33 return true;
36 void TestSink::ClearMessages() {
37 messages_.clear();
40 const Message* TestSink::GetMessageAt(size_t index) const {
41 if (index >= messages_.size())
42 return NULL;
43 return &messages_[index];
46 const Message* TestSink::GetFirstMessageMatching(uint32 id) const {
47 for (size_t i = 0; i < messages_.size(); i++) {
48 if (messages_[i].type() == id)
49 return &messages_[i];
51 return NULL;
54 const Message* TestSink::GetUniqueMessageMatching(uint32 id) const {
55 size_t found_index = 0;
56 size_t found_count = 0;
57 for (size_t i = 0; i < messages_.size(); i++) {
58 if (messages_[i].type() == id) {
59 found_count++;
60 found_index = i;
63 if (found_count != 1)
64 return NULL; // Didn't find a unique one.
65 return &messages_[found_index];
68 void TestSink::AddFilter(Channel::Listener* filter) {
69 filter_list_.AddObserver(filter);
72 void TestSink::RemoveFilter(Channel::Listener* filter) {
73 filter_list_.RemoveObserver(filter);
76 } // namespace IPC