OLD | NEW |
(Empty) | |
| 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/xmpppump.h" |
| 12 |
| 13 #include "webrtc/libjingle/xmpp/xmppauth.h" |
| 14 |
| 15 namespace buzz { |
| 16 |
| 17 XmppPump::XmppPump(XmppPumpNotify * notify) { |
| 18 state_ = buzz::XmppEngine::STATE_NONE; |
| 19 notify_ = notify; |
| 20 client_ = new buzz::XmppClient(this); // NOTE: deleted by TaskRunner |
| 21 } |
| 22 |
| 23 void XmppPump::DoLogin(const buzz::XmppClientSettings & xcs, |
| 24 buzz::AsyncSocket* socket, |
| 25 buzz::PreXmppAuth* auth) { |
| 26 OnStateChange(buzz::XmppEngine::STATE_START); |
| 27 if (!AllChildrenDone()) { |
| 28 client_->SignalStateChange.connect(this, &XmppPump::OnStateChange); |
| 29 client_->Connect(xcs, "", socket, auth); |
| 30 client_->Start(); |
| 31 } |
| 32 } |
| 33 |
| 34 void XmppPump::DoDisconnect() { |
| 35 if (!AllChildrenDone()) |
| 36 client_->Disconnect(); |
| 37 OnStateChange(buzz::XmppEngine::STATE_CLOSED); |
| 38 } |
| 39 |
| 40 void XmppPump::OnStateChange(buzz::XmppEngine::State state) { |
| 41 if (state_ == state) |
| 42 return; |
| 43 state_ = state; |
| 44 if (notify_ != NULL) |
| 45 notify_->OnStateChange(state); |
| 46 } |
| 47 |
| 48 void XmppPump::WakeTasks() { |
| 49 rtc::Thread::Current()->Post(RTC_FROM_HERE, this); |
| 50 } |
| 51 |
| 52 int64_t XmppPump::CurrentTime() { |
| 53 return (int64_t)rtc::TimeMillis(); |
| 54 } |
| 55 |
| 56 void XmppPump::OnMessage(rtc::Message *pmsg) { |
| 57 RunTasks(); |
| 58 } |
| 59 |
| 60 buzz::XmppReturnStatus XmppPump::SendStanza(const buzz::XmlElement *stanza) { |
| 61 if (!AllChildrenDone()) |
| 62 return client_->SendStanza(stanza); |
| 63 return buzz::XMPP_RETURN_BADSTATE; |
| 64 } |
| 65 |
| 66 } // namespace buzz |
| 67 |
OLD | NEW |