OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
| 6 #define REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "talk/xmpp/xmppengine.h" |
| 12 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 13 |
| 14 namespace remoting { |
| 15 |
| 16 class JingleClient; |
| 17 |
| 18 // IqRequest class can be used to send an IQ stanza and then receive reply |
| 19 // stanza for that request. It sends outgoing stanza when SendIq() is called, |
| 20 // after that it forwards incoming reply stanza to the callback set with |
| 21 // set_callback(). If multiple IQ stanzas are send with SendIq() then only reply |
| 22 // to the last one will be received. |
| 23 // The class must be used on the jingle thread only. |
| 24 // TODO(sergeyu): Implement unittests for this class. |
| 25 class IqRequest : private buzz::XmppIqHandler { |
| 26 public: |
| 27 typedef Callback1<const buzz::XmlElement*>::Type ReplyCallback; |
| 28 |
| 29 explicit IqRequest(JingleClient* jingle_client); |
| 30 virtual ~IqRequest(); |
| 31 |
| 32 // Sends stanza of type |type| to |addressee|. |iq_body| contains body of |
| 33 // the stanza. Ownership of |iq_body| is transfered to IqRequest. Must |
| 34 // be called on the jingle thread. |
| 35 void SendIq(const std::string& type, const std::string& addressee, |
| 36 buzz::XmlElement* iq_body); |
| 37 |
| 38 // Sets callback that is called when reply stanza is received. Callback |
| 39 // is called on the jingle thread. |
| 40 void set_callback(ReplyCallback* callback) { |
| 41 callback_.reset(callback); |
| 42 } |
| 43 |
| 44 private: |
| 45 FRIEND_TEST(IqRequestTest, MakeIqStanza); |
| 46 |
| 47 // XmppIqHandler interface. |
| 48 virtual void IqResponse(buzz::XmppIqCookie cookie, |
| 49 const buzz::XmlElement* stanza); |
| 50 |
| 51 static buzz::XmlElement* MakeIqStanza(const std::string& type, |
| 52 const std::string& addressee, |
| 53 buzz::XmlElement* iq_body, |
| 54 const std::string& id); |
| 55 |
| 56 void Unregister(); |
| 57 |
| 58 scoped_refptr<JingleClient> jingle_client_; |
| 59 buzz::XmppIqCookie cookie_; |
| 60 scoped_ptr<ReplyCallback> callback_; |
| 61 }; |
| 62 |
| 63 } // namespace remoting |
| 64 |
| 65 #endif // REMOTING_JINGLE_GLUE_IQ_REQUEST_H_ |
OLD | NEW |