2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
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.
11 #include "webrtc/libjingle/xmpp/xmpppump.h"
13 #include "webrtc/libjingle/xmpp/xmppauth.h"
17 XmppPump::XmppPump(XmppPumpNotify * notify) {
18 state_ = buzz::XmppEngine::STATE_NONE;
20 client_ = new buzz::XmppClient(this); // NOTE: deleted by TaskRunner
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);
34 void XmppPump::DoDisconnect() {
35 if (!AllChildrenDone())
36 client_->Disconnect();
37 OnStateChange(buzz::XmppEngine::STATE_CLOSED);
40 void XmppPump::OnStateChange(buzz::XmppEngine::State state) {
45 notify_->OnStateChange(state);
48 void XmppPump::WakeTasks() {
49 rtc::Thread::Current()->Post(this);
52 int64 XmppPump::CurrentTime() {
53 return (int64)rtc::Time();
56 void XmppPump::OnMessage(rtc::Message *pmsg) {
60 buzz::XmppReturnStatus XmppPump::SendStanza(const buzz::XmlElement *stanza) {
61 if (!AllChildrenDone())
62 return client_->SendStanza(stanza);
63 return buzz::XMPP_RETURN_BADSTATE;