henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/libjingle/xmpp/xmppthread.h" |
| 12 | |
| 13 | #include "webrtc/libjingle/xmpp/xmppauth.h" |
| 14 | #include "webrtc/libjingle/xmpp/xmppclientsettings.h" |
| 15 | |
| 16 | namespace buzz { |
| 17 | namespace { |
| 18 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 19 | const uint32_t MSG_LOGIN = 1; |
| 20 | const uint32_t MSG_DISCONNECT = 2; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 21 | |
| 22 | struct LoginData: public rtc::MessageData { |
| 23 | LoginData(const buzz::XmppClientSettings& s) : xcs(s) {} |
| 24 | virtual ~LoginData() {} |
| 25 | |
| 26 | buzz::XmppClientSettings xcs; |
| 27 | }; |
| 28 | |
| 29 | } // namespace |
| 30 | |
| 31 | XmppThread::XmppThread() { |
| 32 | pump_ = new buzz::XmppPump(this); |
| 33 | } |
| 34 | |
| 35 | XmppThread::~XmppThread() { |
| 36 | Stop(); |
| 37 | delete pump_; |
| 38 | } |
| 39 | |
| 40 | void XmppThread::ProcessMessages(int cms) { |
| 41 | rtc::Thread::ProcessMessages(cms); |
| 42 | } |
| 43 | |
| 44 | void XmppThread::Login(const buzz::XmppClientSettings& xcs) { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame^] | 45 | Post(RTC_FROM_HERE, this, MSG_LOGIN, new LoginData(xcs)); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void XmppThread::Disconnect() { |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame^] | 49 | Post(RTC_FROM_HERE, this, MSG_DISCONNECT); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void XmppThread::OnStateChange(buzz::XmppEngine::State state) { |
| 53 | } |
| 54 | |
| 55 | void XmppThread::OnMessage(rtc::Message* pmsg) { |
| 56 | if (pmsg->message_id == MSG_LOGIN) { |
| 57 | ASSERT(pmsg->pdata != NULL); |
| 58 | LoginData* data = reinterpret_cast<LoginData*>(pmsg->pdata); |
| 59 | pump_->DoLogin(data->xcs, new XmppSocket(buzz::TLS_DISABLED), |
| 60 | new XmppAuth()); |
| 61 | delete data; |
| 62 | } else if (pmsg->message_id == MSG_DISCONNECT) { |
| 63 | pump_->DoDisconnect(); |
| 64 | } else { |
| 65 | ASSERT(false); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } // namespace buzz |