OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
8 extern "C" { | 8 extern "C" { |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 } | 10 } |
11 #endif // !defined(OS_WIN) | 11 #endif // !defined(OS_WIN) |
12 | 12 |
13 #include <iostream> | 13 #include <iostream> |
14 #include <list> | 14 #include <list> |
15 | 15 |
16 #include "base/at_exit.h" | 16 #include "base/at_exit.h" |
17 #include "media/base/data_buffer.h" | 17 #include "media/base/data_buffer.h" |
18 #include "remoting/base/constants.h" | 18 #include "remoting/base/constants.h" |
19 #include "remoting/jingle_glue/jingle_channel.h" | 19 #include "remoting/jingle_glue/jingle_channel.h" |
20 #include "remoting/jingle_glue/jingle_client.h" | 20 #include "remoting/jingle_glue/jingle_client.h" |
| 21 #include "remoting/jingle_glue/jingle_thread.h" |
21 | 22 |
22 using remoting::JingleClient; | 23 using remoting::JingleClient; |
23 using remoting::JingleChannel; | 24 using remoting::JingleChannel; |
24 using remoting::kChromotingTokenServiceName; | 25 using remoting::kChromotingTokenServiceName; |
25 | 26 |
26 void SetConsoleEcho(bool on) { | 27 void SetConsoleEcho(bool on) { |
27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
28 HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); | 29 HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); |
29 if ((hIn == INVALID_HANDLE_VALUE) || (hIn == NULL)) | 30 if ((hIn == INVALID_HANDLE_VALUE) || (hIn == NULL)) |
30 return; | 31 return; |
(...skipping 17 matching lines...) Expand all Loading... |
48 #endif // !defined(OS_WIN) | 49 #endif // !defined(OS_WIN) |
49 } | 50 } |
50 | 51 |
51 class JingleTestClient : public JingleChannel::Callback, | 52 class JingleTestClient : public JingleChannel::Callback, |
52 public JingleClient::Callback { | 53 public JingleClient::Callback { |
53 public: | 54 public: |
54 virtual ~JingleTestClient() {} | 55 virtual ~JingleTestClient() {} |
55 | 56 |
56 void Run(const std::string& username, const std::string& auth_token, | 57 void Run(const std::string& username, const std::string& auth_token, |
57 const std::string& host_jid) { | 58 const std::string& host_jid) { |
58 client_ = new JingleClient(); | 59 // TODO(hclam): Fix the threading problem. |
| 60 remoting::JingleThread jingle_thread; |
| 61 jingle_thread.Start(); |
| 62 client_ = new JingleClient(&jingle_thread); |
59 client_->Init(username, auth_token, kChromotingTokenServiceName, this); | 63 client_->Init(username, auth_token, kChromotingTokenServiceName, this); |
60 | 64 |
61 if (host_jid != "") { | 65 if (host_jid != "") { |
62 scoped_refptr<JingleChannel> channel = client_->Connect(host_jid, this); | 66 scoped_refptr<JingleChannel> channel = client_->Connect(host_jid, this); |
63 channels_.push_back(channel); | 67 channels_.push_back(channel); |
64 } | 68 } |
65 | 69 |
66 while (true) { | 70 while (true) { |
67 std::string line; | 71 std::string line; |
68 std::getline(std::cin, line); | 72 std::getline(std::cin, line); |
(...skipping 13 matching lines...) Expand all Loading... |
82 if (line == "exit") | 86 if (line == "exit") |
83 break; | 87 break; |
84 } | 88 } |
85 | 89 |
86 while (!channels_.empty()) { | 90 while (!channels_.empty()) { |
87 channels_.front()->Close(); | 91 channels_.front()->Close(); |
88 channels_.pop_front(); | 92 channels_.pop_front(); |
89 } | 93 } |
90 | 94 |
91 client_->Close(); | 95 client_->Close(); |
| 96 jingle_thread.Stop(); |
92 } | 97 } |
93 | 98 |
94 // JingleChannel::Callback interface. | 99 // JingleChannel::Callback interface. |
95 void OnStateChange(JingleChannel* channel, JingleChannel::State state) { | 100 void OnStateChange(JingleChannel* channel, JingleChannel::State state) { |
96 LOG(INFO) << "State of " << channel->jid() << " changed to " << state; | 101 LOG(INFO) << "State of " << channel->jid() << " changed to " << state; |
97 } | 102 } |
98 | 103 |
99 void OnPacketReceived(JingleChannel* channel, | 104 void OnPacketReceived(JingleChannel* channel, |
100 scoped_refptr<media::DataBuffer> buffer) { | 105 scoped_refptr<media::DataBuffer> buffer) { |
101 std::string str(reinterpret_cast<const char*>(buffer->GetData()), | 106 std::string str(reinterpret_cast<const char*>(buffer->GetData()), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 std::string auth_token; | 154 std::string auth_token; |
150 std::cout << "Auth token: "; | 155 std::cout << "Auth token: "; |
151 std::cin >> auth_token; | 156 std::cin >> auth_token; |
152 | 157 |
153 JingleTestClient client; | 158 JingleTestClient client; |
154 | 159 |
155 client.Run(username, auth_token, host_jid); | 160 client.Run(username, auth_token, host_jid); |
156 | 161 |
157 return 0; | 162 return 0; |
158 } | 163 } |
OLD | NEW |