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 19 const uint32_t MSG_LOGIN = 1; 20 const uint32_t MSG_DISCONNECT = 2; 21 22 struct LoginData: public rtc::MessageData { LoginDatabuzz::__anonb3a033060111::LoginData23 LoginData(const buzz::XmppClientSettings& s) : xcs(s) {} ~LoginDatabuzz::__anonb3a033060111::LoginData24 virtual ~LoginData() {} 25 26 buzz::XmppClientSettings xcs; 27 }; 28 29 } // namespace 30 XmppThread()31XmppThread::XmppThread() { 32 pump_ = new buzz::XmppPump(this); 33 } 34 ~XmppThread()35XmppThread::~XmppThread() { 36 Stop(); 37 delete pump_; 38 } 39 ProcessMessages(int cms)40void XmppThread::ProcessMessages(int cms) { 41 rtc::Thread::ProcessMessages(cms); 42 } 43 Login(const buzz::XmppClientSettings & xcs)44void XmppThread::Login(const buzz::XmppClientSettings& xcs) { 45 Post(this, MSG_LOGIN, new LoginData(xcs)); 46 } 47 Disconnect()48void XmppThread::Disconnect() { 49 Post(this, MSG_DISCONNECT); 50 } 51 OnStateChange(buzz::XmppEngine::State state)52void XmppThread::OnStateChange(buzz::XmppEngine::State state) { 53 } 54 OnMessage(rtc::Message * pmsg)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 70