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/client_event_dispatcher.h" | 5 #include "remoting/protocol/client_event_dispatcher.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "net/socket/stream_socket.h" | 8 #include "net/socket/stream_socket.h" |
9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/proto/event.pb.h" | 10 #include "remoting/proto/event.pb.h" |
11 #include "remoting/proto/internal.pb.h" | 11 #include "remoting/proto/internal.pb.h" |
12 #include "remoting/protocol/message_serialization.h" | |
13 | 12 |
14 namespace remoting { | 13 namespace remoting { |
15 namespace protocol { | 14 namespace protocol { |
16 | 15 |
17 ClientEventDispatcher::ClientEventDispatcher() | 16 ClientEventDispatcher::ClientEventDispatcher() |
18 : ChannelDispatcherBase(kEventChannelName) { | 17 : ChannelDispatcherBase(kEventChannelName) {} |
19 } | |
20 | 18 |
21 ClientEventDispatcher::~ClientEventDispatcher() { | 19 ClientEventDispatcher::~ClientEventDispatcher() {} |
22 } | |
23 | 20 |
24 void ClientEventDispatcher::InjectKeyEvent(const KeyEvent& event) { | 21 void ClientEventDispatcher::InjectKeyEvent(const KeyEvent& event) { |
25 DCHECK(event.has_usb_keycode()); | 22 DCHECK(event.has_usb_keycode()); |
26 DCHECK(event.has_pressed()); | 23 DCHECK(event.has_pressed()); |
27 EventMessage message; | 24 EventMessage message; |
28 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); | 25 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); |
29 message.mutable_key_event()->CopyFrom(event); | 26 message.mutable_key_event()->CopyFrom(event); |
30 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 27 message_pipe()->Send(&message, base::Closure()); |
31 } | 28 } |
32 | 29 |
33 void ClientEventDispatcher::InjectTextEvent(const TextEvent& event) { | 30 void ClientEventDispatcher::InjectTextEvent(const TextEvent& event) { |
34 DCHECK(event.has_text()); | 31 DCHECK(event.has_text()); |
35 EventMessage message; | 32 EventMessage message; |
36 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); | 33 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); |
37 message.mutable_text_event()->CopyFrom(event); | 34 message.mutable_text_event()->CopyFrom(event); |
38 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 35 message_pipe()->Send(&message, base::Closure()); |
39 } | 36 } |
40 | 37 |
41 void ClientEventDispatcher::InjectMouseEvent(const MouseEvent& event) { | 38 void ClientEventDispatcher::InjectMouseEvent(const MouseEvent& event) { |
42 EventMessage message; | 39 EventMessage message; |
43 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); | 40 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); |
44 message.mutable_mouse_event()->CopyFrom(event); | 41 message.mutable_mouse_event()->CopyFrom(event); |
45 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 42 message_pipe()->Send(&message, base::Closure()); |
46 } | 43 } |
47 | 44 |
48 void ClientEventDispatcher::InjectTouchEvent(const TouchEvent& event) { | 45 void ClientEventDispatcher::InjectTouchEvent(const TouchEvent& event) { |
49 EventMessage message; | 46 EventMessage message; |
50 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); | 47 message.set_timestamp(base::TimeTicks::Now().ToInternalValue()); |
51 message.mutable_touch_event()->CopyFrom(event); | 48 message.mutable_touch_event()->CopyFrom(event); |
52 writer()->Write(SerializeAndFrameMessage(message), base::Closure()); | 49 message_pipe()->Send(&message, base::Closure()); |
53 } | 50 } |
54 | 51 |
55 } // namespace protocol | 52 } // namespace protocol |
56 } // namespace remoting | 53 } // namespace remoting |
OLD | NEW |