2 * Copyright 2011 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 #ifndef WEBRTC_LIBJINGLE_XMPP_PUBSUBCLIENT_H_
12 #define WEBRTC_LIBJINGLE_XMPP_PUBSUBCLIENT_H_
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"
23 // Easy to use clients built on top of the tasks for XEP-0060
24 // (http://xmpp.org/extensions/xep-0060.html).
30 class XmppTaskParentInterface;
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<> {
38 PubSubClient(XmppTaskParentInterface* parent,
40 const std::string& node)
42 pubsubjid_(pubsubjid),
45 const std::string& node() const { return node_; }
47 // Requests the <pubsub><items>, which will be returned via
48 // SignalItems, or SignalRequestError if there is a failure. Should
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*,
62 const XmlElement*> SignalPublishError;
63 // Signal (this, task_id, item)
64 sigslot::signal3<PubSubClient*,
66 const XmlElement*> SignalPublishResult;
67 // Signal (this, task_id, error stanza)
68 sigslot::signal3<PubSubClient*,
70 const XmlElement*> SignalRetractError;
71 // Signal (this, task_id)
72 sigslot::signal2<PubSubClient*,
73 const std::string&> SignalRetractResult;
75 // Publish an item. Takes ownership of payload.
76 void PublishItem(const std::string& itemid,
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);
87 // Get the publisher nick if it exists from the pubsub item.
88 const std::string GetPublisherNickFromPubSubItem(const XmlElement* item_elem);
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);
104 XmppTaskParentInterface* parent_;
111 #endif // WEBRTC_LIBJINGLE_XMPP_PUBSUBCLIENT_H_