summaryrefslogtreecommitdiffstats
path: root/remoting/client/plugin/pepper_signal_strategy.cc
blob: 3e8f675e601bd32eeba94e30b84c19c0c6565ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/client/plugin/pepper_signal_strategy.h"

#include "base/strings/string_number_conversions.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"

namespace remoting {

PepperSignalStrategy::PepperSignalStrategy(
    std::string local_jid,
    const SendIqCallback& send_iq_callback)
    : local_jid_(local_jid),
      send_iq_callback_(send_iq_callback),
      last_id_(0) {
}

PepperSignalStrategy::~PepperSignalStrategy() {
}

void PepperSignalStrategy::OnIncomingMessage(const std::string& message) {
 scoped_ptr<buzz::XmlElement> stanza(buzz::XmlElement::ForStr(message));
  if (!stanza.get()) {
    LOG(WARNING) << "Malformed XMPP stanza received: " << message;
    return;
  }

  ObserverListBase<Listener>::Iterator it(listeners_);
  Listener* listener;
  while ((listener = it.GetNext()) != NULL) {
    if (listener->OnSignalStrategyIncomingStanza(stanza.get()))
      break;
  }
}

void PepperSignalStrategy::Connect() {
}

void PepperSignalStrategy::Disconnect() {
}

SignalStrategy::State PepperSignalStrategy::GetState() const {
  return CONNECTED;
}

SignalStrategy::Error PepperSignalStrategy::GetError() const {
  return OK;
}

std::string PepperSignalStrategy::GetLocalJid() const {
  return local_jid_;
}

void PepperSignalStrategy::AddListener(Listener* listener) {
  listeners_.AddObserver(listener);
}

void PepperSignalStrategy::RemoveListener(Listener* listener) {
  listeners_.RemoveObserver(listener);
}

bool PepperSignalStrategy::SendStanza(scoped_ptr<buzz::XmlElement> stanza) {
  send_iq_callback_.Run(stanza->Str());
  return true;
}

std::string PepperSignalStrategy::GetNextId() {
  ++last_id_;
  return base::IntToString(last_id_);
}

}  // namespace remoting