henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame^] | 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 | #ifndef WEBRTC_LIBJINGLE_XMPP_PUBSUB_TASK_H_ |
| 12 | #define WEBRTC_LIBJINGLE_XMPP_PUBSUB_TASK_H_ |
| 13 | |
| 14 | #include <map> |
| 15 | #include <string> |
| 16 | #include "webrtc/libjingle/xmllite/xmlelement.h" |
| 17 | #include "webrtc/libjingle/xmpp/jid.h" |
| 18 | #include "webrtc/libjingle/xmpp/xmpptask.h" |
| 19 | |
| 20 | namespace buzz { |
| 21 | |
| 22 | // Base class to help write pubsub tasks. |
| 23 | // In ProcessStart call SubscribeNode with namespaces of interest along with |
| 24 | // NodeHandlers. |
| 25 | // When pubsub notifications arrive and matches the namespace, the NodeHandlers |
| 26 | // will be called back. |
| 27 | class PubsubTask : public buzz::XmppTask { |
| 28 | public: |
| 29 | virtual ~PubsubTask(); |
| 30 | |
| 31 | protected: |
| 32 | typedef void (PubsubTask::*NodeHandler)(const buzz::XmlElement* node); |
| 33 | |
| 34 | PubsubTask(XmppTaskParentInterface* parent, const buzz::Jid& pubsub_node_jid); |
| 35 | |
| 36 | virtual bool HandleStanza(const buzz::XmlElement* stanza); |
| 37 | virtual int ProcessResponse(); |
| 38 | |
| 39 | bool SubscribeToNode(const std::string& pubsub_node, NodeHandler handler); |
| 40 | void UnsubscribeFromNode(const std::string& pubsub_node); |
| 41 | |
| 42 | // Called when there is an error. Derived class can do what it needs to. |
| 43 | virtual void OnPubsubError(const buzz::XmlElement* error_stanza); |
| 44 | |
| 45 | private: |
| 46 | typedef std::map<std::string, NodeHandler> NodeSubscriptions; |
| 47 | |
| 48 | void HandlePubsubIqGetResponse(const buzz::XmlElement* pubsub_iq_response); |
| 49 | void HandlePubsubEventMessage(const buzz::XmlElement* pubsub_event_message); |
| 50 | void HandlePubsubItems(const buzz::XmlElement* items); |
| 51 | |
| 52 | buzz::Jid pubsub_node_jid_; |
| 53 | NodeSubscriptions subscribed_nodes_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace buzz |
| 57 | |
| 58 | #endif // WEBRTC_LIBJINGLE_XMPP_PUBSUB_TASK_H_ |