OLD | NEW |
(Empty) | |
| 1 // Copyright 2004 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "third_party/libjingle_xmpp/xmpp/xmppthread.h" |
| 6 |
| 7 #include "third_party/libjingle_xmpp/xmpp/xmppauth.h" |
| 8 #include "third_party/libjingle_xmpp/xmpp/xmppclientsettings.h" |
| 9 |
| 10 namespace buzz { |
| 11 namespace { |
| 12 |
| 13 const uint32_t MSG_LOGIN = 1; |
| 14 const uint32_t MSG_DISCONNECT = 2; |
| 15 |
| 16 struct LoginData: public rtc::MessageData { |
| 17 LoginData(const buzz::XmppClientSettings& s) : xcs(s) {} |
| 18 virtual ~LoginData() {} |
| 19 |
| 20 buzz::XmppClientSettings xcs; |
| 21 }; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 XmppThread::XmppThread() { |
| 26 pump_ = new buzz::XmppPump(this); |
| 27 } |
| 28 |
| 29 XmppThread::~XmppThread() { |
| 30 Stop(); |
| 31 delete pump_; |
| 32 } |
| 33 |
| 34 void XmppThread::ProcessMessages(int cms) { |
| 35 rtc::Thread::ProcessMessages(cms); |
| 36 } |
| 37 |
| 38 void XmppThread::Login(const buzz::XmppClientSettings& xcs) { |
| 39 Post(RTC_FROM_HERE, this, MSG_LOGIN, new LoginData(xcs)); |
| 40 } |
| 41 |
| 42 void XmppThread::Disconnect() { |
| 43 Post(RTC_FROM_HERE, this, MSG_DISCONNECT); |
| 44 } |
| 45 |
| 46 void XmppThread::OnStateChange(buzz::XmppEngine::State state) { |
| 47 } |
| 48 |
| 49 void XmppThread::OnMessage(rtc::Message* pmsg) { |
| 50 if (pmsg->message_id == MSG_LOGIN) { |
| 51 ASSERT(pmsg->pdata != NULL); |
| 52 LoginData* data = reinterpret_cast<LoginData*>(pmsg->pdata); |
| 53 pump_->DoLogin(data->xcs, new XmppSocket(buzz::TLS_DISABLED), |
| 54 new XmppAuth()); |
| 55 delete data; |
| 56 } else if (pmsg->message_id == MSG_DISCONNECT) { |
| 57 pump_->DoDisconnect(); |
| 58 } else { |
| 59 ASSERT(false); |
| 60 } |
| 61 } |
| 62 |
| 63 } // namespace buzz |
OLD | NEW |