| 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 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 private: | 107 private: |
| 108 typedef std::list<scoped_refptr<ProtocolTestConnection> > ConnectionsList; | 108 typedef std::list<scoped_refptr<ProtocolTestConnection> > ConnectionsList; |
| 109 | 109 |
| 110 void OnFinishedClosing(); | 110 void OnFinishedClosing(); |
| 111 void DestroyConnection(scoped_refptr<ProtocolTestConnection> connection); | 111 void DestroyConnection(scoped_refptr<ProtocolTestConnection> connection); |
| 112 | 112 |
| 113 std::string host_jid_; | 113 std::string host_jid_; |
| 114 scoped_refptr<JingleClient> client_; | 114 scoped_refptr<JingleClient> client_; |
| 115 scoped_refptr<JingleSessionManager> session_manager_; | 115 scoped_refptr<JingleSessionManager> session_manager_; |
| 116 ConnectionsList connections_; | 116 ConnectionsList connections_; |
| 117 Lock connections_lock_; | 117 base::Lock connections_lock_; |
| 118 base::WaitableEvent closed_event_; | 118 base::WaitableEvent closed_event_; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 | 121 |
| 122 void ProtocolTestConnection::Init(Session* session) { | 122 void ProtocolTestConnection::Init(Session* session) { |
| 123 session_ = session; | 123 session_ = session; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ProtocolTestConnection::Write(const std::string& str) { | 126 void ProtocolTestConnection::Write(const std::string& str) { |
| 127 if (str.empty()) | 127 if (str.empty()) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 session_manager_ = new JingleSessionManager(&jingle_thread); | 230 session_manager_ = new JingleSessionManager(&jingle_thread); |
| 231 | 231 |
| 232 host_jid_ = host_jid; | 232 host_jid_ = host_jid; |
| 233 | 233 |
| 234 while (true) { | 234 while (true) { |
| 235 std::string line; | 235 std::string line; |
| 236 std::getline(std::cin, line); | 236 std::getline(std::cin, line); |
| 237 | 237 |
| 238 { | 238 { |
| 239 AutoLock auto_lock(connections_lock_); | 239 base::AutoLock auto_lock(connections_lock_); |
| 240 | 240 |
| 241 // Broadcast message to all clients. | 241 // Broadcast message to all clients. |
| 242 for (ConnectionsList::iterator it = connections_.begin(); | 242 for (ConnectionsList::iterator it = connections_.begin(); |
| 243 it != connections_.end(); ++it) { | 243 it != connections_.end(); ++it) { |
| 244 (*it)->Write(line); | 244 (*it)->Write(line); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 if (line == "exit") | 248 if (line == "exit") |
| 249 break; | 249 break; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 std::cerr << "Accepting connection from " << session->jid() << std::endl; | 302 std::cerr << "Accepting connection from " << session->jid() << std::endl; |
| 303 | 303 |
| 304 session->set_config(SessionConfig::CreateDefault()); | 304 session->set_config(SessionConfig::CreateDefault()); |
| 305 *response = SessionManager::ACCEPT; | 305 *response = SessionManager::ACCEPT; |
| 306 | 306 |
| 307 ProtocolTestConnection* test_connection = | 307 ProtocolTestConnection* test_connection = |
| 308 new ProtocolTestConnection(this, client_->message_loop()); | 308 new ProtocolTestConnection(this, client_->message_loop()); |
| 309 session->SetStateChangeCallback( | 309 session->SetStateChangeCallback( |
| 310 NewCallback(test_connection, &ProtocolTestConnection::OnStateChange)); | 310 NewCallback(test_connection, &ProtocolTestConnection::OnStateChange)); |
| 311 test_connection->Init(session); | 311 test_connection->Init(session); |
| 312 AutoLock auto_lock(connections_lock_); | 312 base::AutoLock auto_lock(connections_lock_); |
| 313 connections_.push_back(make_scoped_refptr(test_connection)); | 313 connections_.push_back(make_scoped_refptr(test_connection)); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void ProtocolTestClient::OnFinishedClosing() { | 316 void ProtocolTestClient::OnFinishedClosing() { |
| 317 closed_event_.Signal(); | 317 closed_event_.Signal(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 void ProtocolTestClient::DestroyConnection( | 320 void ProtocolTestClient::DestroyConnection( |
| 321 scoped_refptr<ProtocolTestConnection> connection) { | 321 scoped_refptr<ProtocolTestConnection> connection) { |
| 322 connection->Close(); | 322 connection->Close(); |
| 323 AutoLock auto_lock(connections_lock_); | 323 base::AutoLock auto_lock(connections_lock_); |
| 324 for (ConnectionsList::iterator it = connections_.begin(); | 324 for (ConnectionsList::iterator it = connections_.begin(); |
| 325 it != connections_.end(); ++it) { | 325 it != connections_.end(); ++it) { |
| 326 if ((*it) == connection) { | 326 if ((*it) == connection) { |
| 327 connections_.erase(it); | 327 connections_.erase(it); |
| 328 return; | 328 return; |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 } // namespace protocol | 333 } // namespace protocol |
| (...skipping 29 matching lines...) Expand all Loading... |
| 363 if (!cmd_line->HasSwitch("auth_token")) | 363 if (!cmd_line->HasSwitch("auth_token")) |
| 364 usage(argv[0]); | 364 usage(argv[0]); |
| 365 std::string auth_token(cmd_line->GetSwitchValueASCII("auth_token")); | 365 std::string auth_token(cmd_line->GetSwitchValueASCII("auth_token")); |
| 366 | 366 |
| 367 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); | 367 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); |
| 368 | 368 |
| 369 client->Run(username, auth_token, host_jid); | 369 client->Run(username, auth_token, host_jid); |
| 370 | 370 |
| 371 return 0; | 371 return 0; |
| 372 } | 372 } |
| OLD | NEW |