OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 BLIMP_NET_BLIMP_MESSAGE_DISPATCHER_H_ | |
6 #define BLIMP_NET_BLIMP_MESSAGE_DISPATCHER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/containers/small_map.h" | |
11 #include "base/threading/thread_checker.h" | |
12 #include "blimp/common/proto/blimp_message.pb.h" | |
13 #include "blimp/net/blimp_message_receiver.h" | |
14 #include "blimp/net/blimp_net_export.h" | |
15 | |
16 namespace blimp { | |
17 | |
18 // Multiplexing BlimpMessageReceiver which routes BlimpMessages to other | |
19 // receivers based on the messages' feature type. | |
20 class BLIMP_NET_EXPORT BlimpMessageDispatcher : public BlimpMessageReceiver { | |
21 public: | |
22 BlimpMessageDispatcher(); | |
23 ~BlimpMessageDispatcher() override; | |
24 | |
25 // Registers a message receiver which will process all messages | |
26 // with of the specified |type|. | |
27 // Only one handler may be added per type. | |
28 // | |
29 // |handler| must be valid when OnBlimpMessage() is called. | |
30 void AddReceiver(BlimpMessage::Type type, BlimpMessageReceiver* handler); | |
31 | |
32 // BlimpMessageReceiver implementation. | |
33 net::Error OnBlimpMessage(const BlimpMessage& message) override; | |
34 | |
35 private: | |
36 base::SmallMap<std::map<BlimpMessage::Type, BlimpMessageReceiver*>> | |
37 feature_receiver_map_; | |
38 | |
39 DISALLOW_COPY_AND_ASSIGN(BlimpMessageDispatcher); | |
40 }; | |
41 | |
42 } // namespace blimp | |
43 | |
44 #endif // BLIMP_NET_BLIMP_MESSAGE_DISPATCHER_H_ | |
OLD | NEW |