blob: 0fd5002d629fd1d39bc7a1e9ffbad905278f1e49 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
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
16namespace buzz {
17namespace {
18
Peter Boström0c4e06b2015-10-07 12:23:21 +020019const uint32_t MSG_LOGIN = 1;
20const uint32_t MSG_DISCONNECT = 2;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000021
22struct 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
31XmppThread::XmppThread() {
32 pump_ = new buzz::XmppPump(this);
33}
34
35XmppThread::~XmppThread() {
36 Stop();
37 delete pump_;
38}
39
40void XmppThread::ProcessMessages(int cms) {
41 rtc::Thread::ProcessMessages(cms);
42}
43
44void XmppThread::Login(const buzz::XmppClientSettings& xcs) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -070045 Post(RTC_FROM_HERE, this, MSG_LOGIN, new LoginData(xcs));
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000046}
47
48void XmppThread::Disconnect() {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -070049 Post(RTC_FROM_HERE, this, MSG_DISCONNECT);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000050}
51
52void XmppThread::OnStateChange(buzz::XmppEngine::State state) {
53}
54
55void 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