OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 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 #ifndef WEBRTC_LIBJINGLE_XMPP_PUBSUBCLIENT_H_ |
| 12 #define WEBRTC_LIBJINGLE_XMPP_PUBSUBCLIENT_H_ |
| 13 |
| 14 #include <string> |
| 15 #include <vector> |
| 16 |
| 17 #include "webrtc/libjingle/xmpp/jid.h" |
| 18 #include "webrtc/libjingle/xmpp/pubsubtasks.h" |
| 19 #include "webrtc/base/sigslot.h" |
| 20 #include "webrtc/base/sigslotrepeater.h" |
| 21 #include "webrtc/base/task.h" |
| 22 |
| 23 // Easy to use clients built on top of the tasks for XEP-0060 |
| 24 // (http://xmpp.org/extensions/xep-0060.html). |
| 25 |
| 26 namespace buzz { |
| 27 |
| 28 class Jid; |
| 29 class XmlElement; |
| 30 class XmppTaskParentInterface; |
| 31 |
| 32 // An easy-to-use pubsub client that handles the three tasks of |
| 33 // getting, publishing, and listening for updates. Tied to a specific |
| 34 // pubsub jid and node. All you have to do is RequestItems, listen |
| 35 // for SignalItems and PublishItems. |
| 36 class PubSubClient : public sigslot::has_slots<> { |
| 37 public: |
| 38 PubSubClient(XmppTaskParentInterface* parent, |
| 39 const Jid& pubsubjid, |
| 40 const std::string& node) |
| 41 : parent_(parent), |
| 42 pubsubjid_(pubsubjid), |
| 43 node_(node) {} |
| 44 |
| 45 const std::string& node() const { return node_; } |
| 46 |
| 47 // Requests the <pubsub><items>, which will be returned via |
| 48 // SignalItems, or SignalRequestError if there is a failure. Should |
| 49 // auto-subscribe. |
| 50 void RequestItems(); |
| 51 // Fired when either <pubsub><items> are returned or when |
| 52 // <event><items> are received. |
| 53 sigslot::signal2<PubSubClient*, |
| 54 const std::vector<PubSubItem>&> SignalItems; |
| 55 // Signal (this, error stanza) |
| 56 sigslot::signal2<PubSubClient*, |
| 57 const XmlElement*> SignalRequestError; |
| 58 // Signal (this, task_id, item, error stanza) |
| 59 sigslot::signal4<PubSubClient*, |
| 60 const std::string&, |
| 61 const XmlElement*, |
| 62 const XmlElement*> SignalPublishError; |
| 63 // Signal (this, task_id, item) |
| 64 sigslot::signal3<PubSubClient*, |
| 65 const std::string&, |
| 66 const XmlElement*> SignalPublishResult; |
| 67 // Signal (this, task_id, error stanza) |
| 68 sigslot::signal3<PubSubClient*, |
| 69 const std::string&, |
| 70 const XmlElement*> SignalRetractError; |
| 71 // Signal (this, task_id) |
| 72 sigslot::signal2<PubSubClient*, |
| 73 const std::string&> SignalRetractResult; |
| 74 |
| 75 // Publish an item. Takes ownership of payload. |
| 76 void PublishItem(const std::string& itemid, |
| 77 XmlElement* payload, |
| 78 std::string* task_id_out); |
| 79 // Publish an item. Takes ownership of children. |
| 80 void PublishItem(const std::string& itemid, |
| 81 const std::vector<XmlElement*>& children, |
| 82 std::string* task_id_out); |
| 83 // Retract (delete) an item. |
| 84 void RetractItem(const std::string& itemid, |
| 85 std::string* task_id_out); |
| 86 |
| 87 // Get the publisher nick if it exists from the pubsub item. |
| 88 const std::string GetPublisherNickFromPubSubItem(const XmlElement* item_elem); |
| 89 |
| 90 private: |
| 91 void OnRequestError(IqTask* task, |
| 92 const XmlElement* stanza); |
| 93 void OnRequestResult(PubSubRequestTask* task, |
| 94 const std::vector<PubSubItem>& items); |
| 95 void OnReceiveUpdate(PubSubReceiveTask* task, |
| 96 const std::vector<PubSubItem>& items); |
| 97 void OnPublishResult(PubSubPublishTask* task); |
| 98 void OnPublishError(IqTask* task, |
| 99 const XmlElement* stanza); |
| 100 void OnRetractResult(PubSubRetractTask* task); |
| 101 void OnRetractError(IqTask* task, |
| 102 const XmlElement* stanza); |
| 103 |
| 104 XmppTaskParentInterface* parent_; |
| 105 Jid pubsubjid_; |
| 106 std::string node_; |
| 107 }; |
| 108 |
| 109 } // namespace buzz |
| 110 |
| 111 #endif // WEBRTC_LIBJINGLE_XMPP_PUBSUBCLIENT_H_ |
OLD | NEW |