OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/host_event_dispatcher.h" | 5 #include "remoting/protocol/host_event_dispatcher.h" |
6 | 6 |
7 #include "net/socket/stream_socket.h" | 7 #include "net/socket/stream_socket.h" |
8 #include "remoting/base/constants.h" | 8 #include "remoting/base/constants.h" |
9 #include "remoting/proto/event.pb.h" | 9 #include "remoting/proto/event.pb.h" |
10 #include "remoting/proto/internal.pb.h" | 10 #include "remoting/proto/internal.pb.h" |
11 #include "remoting/protocol/input_stub.h" | 11 #include "remoting/protocol/input_stub.h" |
| 12 #include "remoting/protocol/message_serialization.h" |
12 | 13 |
13 namespace remoting { | 14 namespace remoting { |
14 namespace protocol { | 15 namespace protocol { |
15 | 16 |
16 HostEventDispatcher::HostEventDispatcher() | 17 HostEventDispatcher::HostEventDispatcher() |
17 : ChannelDispatcherBase(kEventChannelName), | 18 : ChannelDispatcherBase(kEventChannelName) {} |
18 input_stub_(nullptr), | |
19 parser_(base::Bind(&HostEventDispatcher::OnMessageReceived, | |
20 base::Unretained(this)), | |
21 reader()) {} | |
22 | |
23 HostEventDispatcher::~HostEventDispatcher() {} | 19 HostEventDispatcher::~HostEventDispatcher() {} |
24 | 20 |
25 void HostEventDispatcher::OnMessageReceived(scoped_ptr<EventMessage> message) { | 21 void HostEventDispatcher::OnIncomingMessage(scoped_ptr<CompoundBuffer> buffer) { |
26 DCHECK(input_stub_); | 22 DCHECK(input_stub_); |
27 | 23 |
| 24 scoped_ptr<EventMessage> message = ParseMessage<EventMessage>(buffer.get()); |
| 25 if (!message) |
| 26 return; |
| 27 |
28 if (!on_input_event_callback_.is_null()) | 28 if (!on_input_event_callback_.is_null()) |
29 on_input_event_callback_.Run(message->timestamp()); | 29 on_input_event_callback_.Run(message->timestamp()); |
30 | 30 |
31 if (message->has_key_event()) { | 31 if (message->has_key_event()) { |
32 const KeyEvent& event = message->key_event(); | 32 const KeyEvent& event = message->key_event(); |
33 if (event.has_usb_keycode() && event.has_pressed()) { | 33 if (event.has_usb_keycode() && event.has_pressed()) { |
34 input_stub_->InjectKeyEvent(event); | 34 input_stub_->InjectKeyEvent(event); |
35 } else { | 35 } else { |
36 LOG(WARNING) << "Received invalid key event."; | 36 LOG(WARNING) << "Received invalid key event."; |
37 } | 37 } |
38 } else if (message->has_text_event()) { | 38 } else if (message->has_text_event()) { |
39 const TextEvent& event = message->text_event(); | 39 const TextEvent& event = message->text_event(); |
40 if (event.has_text()) { | 40 if (event.has_text()) { |
41 input_stub_->InjectTextEvent(event); | 41 input_stub_->InjectTextEvent(event); |
42 } else { | 42 } else { |
43 LOG(WARNING) << "Received invalid text event."; | 43 LOG(WARNING) << "Received invalid text event."; |
44 } | 44 } |
45 } else if (message->has_mouse_event()) { | 45 } else if (message->has_mouse_event()) { |
46 input_stub_->InjectMouseEvent(message->mouse_event()); | 46 input_stub_->InjectMouseEvent(message->mouse_event()); |
47 } else if (message->has_touch_event()) { | 47 } else if (message->has_touch_event()) { |
48 input_stub_->InjectTouchEvent(message->touch_event()); | 48 input_stub_->InjectTouchEvent(message->touch_event()); |
49 } else { | 49 } else { |
50 LOG(WARNING) << "Unknown event message received."; | 50 LOG(WARNING) << "Unknown event message received."; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 } // namespace protocol | 54 } // namespace protocol |
55 } // namespace remoting | 55 } // namespace remoting |
OLD | NEW |