1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/client/host_connection.h"
namespace remoting {
HostConnection::HostConnection(ProtocolDecoder* decoder,
EventHandler* handler)
: decoder_(decoder), handler_(handler) {
}
HostConnection::~HostConnection() {
Disconnect();
}
void HostConnection::Connect(const std::string& username,
const std::string& password,
const std::string& host_jid) {
jingle_client_ = new JingleClient();
jingle_client_->Init(username, password, this);
jingle_channel_ = jingle_client_->Connect(host_jid, this);
}
void HostConnection::Disconnect() {
if (jingle_channel_.get())
jingle_channel_->Close();
if (jingle_client_.get())
jingle_client_->Close();
}
void HostConnection::OnStateChange(JingleChannel* channel,
JingleChannel::State state) {
DCHECK(handler_);
if (state == JingleChannel::FAILED)
handler_->OnConnectionFailed(this);
else if (state == JingleChannel::CLOSED)
handler_->OnConnectionClosed(this);
else if (state == JingleChannel::OPEN)
handler_->OnConnectionOpened(this);
}
void HostConnection::OnPacketReceived(JingleChannel* channel,
scoped_refptr<media::DataBuffer> buffer) {
HostMessageList list;
decoder_->ParseHostMessages(buffer, &list);
DCHECK(handler_);
handler_->HandleMessages(this, &list);
}
// JingleClient::Callback interface.
void HostConnection::OnStateChange(JingleClient* client,
JingleClient::State state) {
DCHECK(client);
DCHECK(handler_);
if (state == JingleClient::CONNECTED) {
LOG(INFO) << "Connected as: " << client->GetFullJid();
} else if (state == JingleClient::CLOSED) {
LOG(INFO) << "Connection closed.";
handler_->OnConnectionClosed(this);
}
}
bool HostConnection::OnAcceptConnection(JingleClient* client,
const std::string& jid,
JingleChannel::Callback** callback) {
// Client rejects all connection.
return false;
}
void HostConnection::OnNewConnection(JingleClient* client,
scoped_refptr<JingleChannel> channel) {
NOTREACHED() << "SimpleClient can't accept connection.";
}
} // namespace remoting
|