You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2011, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_XMPP_PUBSUBCLIENT_H_
  28. #define TALK_XMPP_PUBSUBCLIENT_H_
  29. #include <string>
  30. #include <vector>
  31. #include "talk/base/sigslot.h"
  32. #include "talk/base/sigslotrepeater.h"
  33. #include "talk/base/task.h"
  34. #include "talk/xmpp/jid.h"
  35. #include "talk/xmpp/pubsubtasks.h"
  36. // Easy to use clients built on top of the tasks for XEP-0060
  37. // (http://xmpp.org/extensions/xep-0060.html).
  38. namespace buzz {
  39. class Jid;
  40. class XmlElement;
  41. class XmppTaskParentInterface;
  42. // An easy-to-use pubsub client that handles the three tasks of
  43. // getting, publishing, and listening for updates. Tied to a specific
  44. // pubsub jid and node. All you have to do is RequestItems, listen
  45. // for SignalItems and PublishItems.
  46. class PubSubClient : public sigslot::has_slots<> {
  47. public:
  48. PubSubClient(XmppTaskParentInterface* parent,
  49. const Jid& pubsubjid,
  50. const std::string& node)
  51. : parent_(parent),
  52. pubsubjid_(pubsubjid),
  53. node_(node) {}
  54. const std::string& node() const { return node_; }
  55. // Requests the <pubsub><items>, which will be returned via
  56. // SignalItems, or SignalRequestError if there is a failure. Should
  57. // auto-subscribe.
  58. void RequestItems();
  59. // Fired when either <pubsub><items> are returned or when
  60. // <event><items> are received.
  61. sigslot::signal2<PubSubClient*,
  62. const std::vector<PubSubItem>&> SignalItems;
  63. // Signal (this, error stanza)
  64. sigslot::signal2<PubSubClient*,
  65. const XmlElement*> SignalRequestError;
  66. // Signal (this, task_id, item, error stanza)
  67. sigslot::signal4<PubSubClient*,
  68. const std::string&,
  69. const XmlElement*,
  70. const XmlElement*> SignalPublishError;
  71. // Signal (this, task_id, item)
  72. sigslot::signal3<PubSubClient*,
  73. const std::string&,
  74. const XmlElement*> SignalPublishResult;
  75. // Signal (this, task_id, error stanza)
  76. sigslot::signal3<PubSubClient*,
  77. const std::string&,
  78. const XmlElement*> SignalRetractError;
  79. // Signal (this, task_id)
  80. sigslot::signal2<PubSubClient*,
  81. const std::string&> SignalRetractResult;
  82. // Publish an item. Takes ownership of payload.
  83. void PublishItem(const std::string& itemid,
  84. XmlElement* payload,
  85. std::string* task_id_out);
  86. // Publish an item. Takes ownership of children.
  87. void PublishItem(const std::string& itemid,
  88. const std::vector<XmlElement*>& children,
  89. std::string* task_id_out);
  90. // Retract (delete) an item.
  91. void RetractItem(const std::string& itemid,
  92. std::string* task_id_out);
  93. private:
  94. void OnRequestError(IqTask* task,
  95. const XmlElement* stanza);
  96. void OnRequestResult(PubSubRequestTask* task,
  97. const std::vector<PubSubItem>& items);
  98. void OnReceiveUpdate(PubSubReceiveTask* task,
  99. const std::vector<PubSubItem>& items);
  100. void OnPublishResult(PubSubPublishTask* task);
  101. void OnPublishError(IqTask* task,
  102. const XmlElement* stanza);
  103. void OnRetractResult(PubSubRetractTask* task);
  104. void OnRetractError(IqTask* task,
  105. const XmlElement* stanza);
  106. XmppTaskParentInterface* parent_;
  107. Jid pubsubjid_;
  108. std::string node_;
  109. };
  110. } // namespace buzz
  111. #endif // TALK_XMPP_PUBSUBCLIENT_H_