| 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 |
| 28 IqRequest() {} | 32 IqRequest() {} |
| 29 virtual ~IqRequest() {} | 33 virtual ~IqRequest() {} |
| 30 | 34 |
| 31 // Sends stanza of type |type| to |addressee|. |iq_body| contains body of | 35 // Sends Iq stanza. Takes ownership of |stanza|. |
| 32 // the stanza. Takes pwnership of |iq_body|. | 36 virtual void SendIq(buzz::XmlElement* stanza) = 0; |
| 33 virtual void SendIq(const std::string& type, const std::string& addressee, | |
| 34 buzz::XmlElement* iq_body) = 0; | |
| 35 | 37 |
| 36 // Sets callback that is called when reply stanza is received. | 38 // Sets callback that is called when reply stanza is received. |
| 37 virtual void set_callback(const ReplyCallback& callback) = 0; | 39 virtual void set_callback(const ReplyCallback& callback) = 0; |
| 38 | 40 |
| 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 | |
| 45 private: | 41 private: |
| 46 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza); | 42 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza); |
| 47 | 43 |
| 48 DISALLOW_COPY_AND_ASSIGN(IqRequest); | 44 DISALLOW_COPY_AND_ASSIGN(IqRequest); |
| 49 }; | 45 }; |
| 50 | 46 |
| 51 } // namespace remoting | 47 } // namespace remoting |
| 52 | 48 |
| 53 #endif // REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ | 49 #endif // REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
| OLD | NEW |