| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 #include "base/memory/ref_counted.h" | |
| 6 #include "net/base/io_buffer.h" | |
| 7 #include "remoting/proto/control.pb.h" | |
| 8 #include "remoting/proto/event.pb.h" | |
| 9 #include "remoting/proto/internal.pb.h" | |
| 10 #include "remoting/protocol/connection_to_client.h" | |
| 11 #include "remoting/protocol/host_message_dispatcher.h" | |
| 12 #include "remoting/protocol/host_stub.h" | |
| 13 #include "remoting/protocol/input_stub.h" | |
| 14 #include "remoting/protocol/message_reader.h" | |
| 15 #include "remoting/protocol/session.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 namespace protocol { | |
| 19 | |
| 20 HostMessageDispatcher::HostMessageDispatcher() | |
| 21 : connection_(NULL), | |
| 22 host_stub_(NULL), | |
| 23 input_stub_(NULL) { | |
| 24 } | |
| 25 | |
| 26 HostMessageDispatcher::~HostMessageDispatcher() { | |
| 27 } | |
| 28 | |
| 29 void HostMessageDispatcher::Initialize( | |
| 30 ConnectionToClient* connection, | |
| 31 HostStub* host_stub, InputStub* input_stub) { | |
| 32 if (!connection || !host_stub || !input_stub || | |
| 33 !connection->session()->event_channel() || | |
| 34 !connection->session()->control_channel()) { | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 control_message_reader_.reset(new ProtobufMessageReader<ControlMessage>()); | |
| 39 event_message_reader_.reset(new ProtobufMessageReader<EventMessage>()); | |
| 40 connection_ = connection; | |
| 41 host_stub_ = host_stub; | |
| 42 input_stub_ = input_stub; | |
| 43 | |
| 44 // Initialize the readers on the sockets provided by channels. | |
| 45 event_message_reader_->Init( | |
| 46 connection->session()->event_channel(), | |
| 47 base::Bind(&HostMessageDispatcher::OnEventMessageReceived, | |
| 48 base::Unretained(this))); | |
| 49 control_message_reader_->Init( | |
| 50 connection->session()->control_channel(), | |
| 51 base::Bind(&HostMessageDispatcher::OnControlMessageReceived, | |
| 52 base::Unretained(this))); | |
| 53 } | |
| 54 | |
| 55 void HostMessageDispatcher::OnControlMessageReceived( | |
| 56 ControlMessage* message, const base::Closure& done_task) { | |
| 57 LOG(WARNING) << "Invalid control message received."; | |
| 58 done_task.Run(); | |
| 59 } | |
| 60 | |
| 61 void HostMessageDispatcher::OnEventMessageReceived( | |
| 62 EventMessage* message, const base::Closure& done_task) { | |
| 63 base::ScopedClosureRunner done_runner(done_task); | |
| 64 | |
| 65 connection_->UpdateSequenceNumber(message->sequence_number()); | |
| 66 | |
| 67 if (message->has_key_event()) { | |
| 68 const KeyEvent& event = message->key_event(); | |
| 69 if (event.has_keycode() && event.has_pressed()) { | |
| 70 input_stub_->InjectKeyEvent(event); | |
| 71 return; | |
| 72 } | |
| 73 } else if (message->has_mouse_event()) { | |
| 74 input_stub_->InjectMouseEvent(message->mouse_event()); | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 LOG(WARNING) << "Unknown event message received."; | |
| 79 } | |
| 80 | |
| 81 } // namespace protocol | |
| 82 } // namespace remoting | |
| OLD | NEW |