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
3 // found in the LICENSE file.
5 #include "remoting/protocol/client_event_dispatcher.h"
7 #include "base/time/time.h"
8 #include "net/socket/stream_socket.h"
9 #include "remoting/base/constants.h"
10 #include "remoting/proto/event.pb.h"
11 #include "remoting/proto/internal.pb.h"
12 #include "remoting/protocol/message_serialization.h"
17 ClientEventDispatcher::ClientEventDispatcher()
18 : ChannelDispatcherBase(kEventChannelName
) {
21 ClientEventDispatcher::~ClientEventDispatcher() {
24 void ClientEventDispatcher::InjectKeyEvent(const KeyEvent
& event
) {
25 DCHECK(event
.has_usb_keycode());
26 DCHECK(event
.has_pressed());
28 message
.set_timestamp(base::Time::Now().ToInternalValue());
29 message
.mutable_key_event()->CopyFrom(event
);
30 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
33 void ClientEventDispatcher::InjectTextEvent(const TextEvent
& event
) {
34 DCHECK(event
.has_text());
36 message
.set_timestamp(base::Time::Now().ToInternalValue());
37 message
.mutable_text_event()->CopyFrom(event
);
38 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
41 void ClientEventDispatcher::InjectMouseEvent(const MouseEvent
& event
) {
43 message
.set_timestamp(base::Time::Now().ToInternalValue());
44 message
.mutable_mouse_event()->CopyFrom(event
);
45 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
48 void ClientEventDispatcher::InjectTouchEvent(const TouchEvent
& event
) {
50 message
.set_timestamp(base::Time::Now().ToInternalValue());
51 message
.mutable_touch_event()->CopyFrom(event
);
52 writer()->Write(SerializeAndFrameMessage(message
), base::Closure());
55 } // namespace protocol
56 } // namespace remoting