[email protected] | b2e375f | 2011-03-03 23:20:24 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 5 | #include "ipc/message_router.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | d84effeb | 2012-06-25 17:03:10 | [diff] [blame] | 7 | #include "ipc/ipc_message.h" |
8 | |||||
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 9 | namespace IPC { |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 10 | |
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 11 | MessageRouter::MessageRouter() {} |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 12 | |
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 13 | MessageRouter::~MessageRouter() {} |
[email protected] | d4799a3 | 2010-09-28 22:54:58 | [diff] [blame] | 14 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 15 | bool MessageRouter::OnControlMessageReceived(const IPC::Message& msg) { |
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 16 | NOTREACHED() |
17 | << "should override in subclass if you care about control messages"; | ||||
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 18 | return false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | } |
20 | |||||
21 | bool MessageRouter::Send(IPC::Message* msg) { | ||||
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 22 | NOTREACHED() |
23 | << "should override in subclass if you care about sending messages"; | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | return false; |
25 | } | ||||
26 | |||||
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 27 | bool MessageRouter::AddRoute(int32_t routing_id, IPC::Listener* listener) { |
[email protected] | 0d78ec0e | 2014-04-08 23:35:23 | [diff] [blame] | 28 | if (routes_.Lookup(routing_id)) { |
29 | DLOG(ERROR) << "duplicate routing ID"; | ||||
30 | return false; | ||||
31 | } | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | routes_.AddWithID(listener, routing_id); |
[email protected] | 0d78ec0e | 2014-04-08 23:35:23 | [diff] [blame] | 33 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | } |
35 | |||||
avi | a9aa7a8 | 2015-12-25 03:06:31 | [diff] [blame] | 36 | void MessageRouter::RemoveRoute(int32_t routing_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | routes_.Remove(routing_id); |
38 | } | ||||
39 | |||||
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 40 | Listener* MessageRouter::GetRoute(int32_t routing_id) { |
41 | return routes_.Lookup(routing_id); | ||||
42 | } | ||||
43 | |||||
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 44 | bool MessageRouter::OnMessageReceived(const IPC::Message& msg) { |
45 | if (msg.routing_id() == MSG_ROUTING_CONTROL) | ||||
46 | return OnControlMessageReceived(msg); | ||||
47 | |||||
48 | return RouteMessage(msg); | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | } |
50 | |||||
51 | bool MessageRouter::RouteMessage(const IPC::Message& msg) { | ||||
[email protected] | bae061f7 | 2013-04-26 16:22:29 | [diff] [blame] | 52 | IPC::Listener* listener = routes_.Lookup(msg.routing_id()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | if (!listener) |
54 | return false; | ||||
55 | |||||
boliu | 60df207 | 2015-10-26 22:55:19 | [diff] [blame] | 56 | return listener->OnMessageReceived(msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | } |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 58 | |
markdittmer | 638a149 | 2016-02-19 01:11:50 | [diff] [blame] | 59 | } // namespace IPC |