| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
| 6 #define REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ | 6 #define REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 | 12 |
| 13 namespace buzz { | 13 namespace buzz { |
| 14 class XmlElement; | 14 class XmlElement; |
| 15 } // namespace buzz | 15 } // namespace buzz |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 | 18 |
| 19 // IqRequest class can be used to send an IQ stanza and then receive reply | 19 // IqRequest class can be used to send an IQ stanza and then receive reply |
| 20 // stanza for that request. It sends outgoing stanza when SendIq() is called, | 20 // stanza for that request. It sends outgoing stanza when SendIq() is called, |
| 21 // after that it forwards incoming reply stanza to the callback set with | 21 // after that it forwards incoming reply stanza to the callback set with |
| 22 // set_callback(). If each call to SendIq() will yield one invocation of the | 22 // set_callback(). If each call to SendIq() will yield one invocation of the |
| 23 // callback with the response. | 23 // callback with the response. |
| 24 class IqRequest { | 24 class IqRequest { |
| 25 public: | 25 public: |
| 26 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback; | 26 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback; |
| 27 | 27 |
| 28 static buzz::XmlElement* MakeIqStanza(const std::string& type, | |
| 29 const std::string& addressee, | |
| 30 buzz::XmlElement* iq_body); | |
| 31 | |
| 32 IqRequest() {} | 28 IqRequest() {} |
| 33 virtual ~IqRequest() {} | 29 virtual ~IqRequest() {} |
| 34 | 30 |
| 35 // Sends Iq stanza. Takes ownership of |stanza|. | 31 // Sends stanza of type |type| to |addressee|. |iq_body| contains body of |
| 36 virtual void SendIq(buzz::XmlElement* stanza) = 0; | 32 // the stanza. Takes pwnership of |iq_body|. |
| 33 virtual void SendIq(const std::string& type, const std::string& addressee, |
| 34 buzz::XmlElement* iq_body) = 0; |
| 37 | 35 |
| 38 // Sets callback that is called when reply stanza is received. | 36 // Sets callback that is called when reply stanza is received. |
| 39 virtual void set_callback(const ReplyCallback& callback) = 0; | 37 virtual void set_callback(const ReplyCallback& callback) = 0; |
| 40 | 38 |
| 39 protected: |
| 40 static buzz::XmlElement* MakeIqStanza(const std::string& type, |
| 41 const std::string& addressee, |
| 42 buzz::XmlElement* iq_body, |
| 43 const std::string& id); |
| 44 |
| 41 private: | 45 private: |
| 42 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza); | 46 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza); |
| 43 | 47 |
| 44 DISALLOW_COPY_AND_ASSIGN(IqRequest); | 48 DISALLOW_COPY_AND_ASSIGN(IqRequest); |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 } // namespace remoting | 51 } // namespace remoting |
| 48 | 52 |
| 49 #endif // REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ | 53 #endif // REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
| OLD | NEW |