Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_JINGLE_GLUE_IQ_SENDER_H_ | |
| 6 #define REMOTING_JINGLE_GLUE_IQ_SENDER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "remoting/jingle_glue/signal_strategy.h" | |
| 16 | |
| 17 namespace buzz { | |
| 18 class XmlElement; | |
| 19 } // namespace buzz | |
| 20 | |
| 21 namespace remoting { | |
| 22 | |
| 23 class IqRequest; | |
| 24 class SignalStrategy; | |
| 25 | |
| 26 // IqSender handles sending iq requests and routing of responses to | |
| 27 // those requests. | |
| 28 class IqSender : public SignalStrategy::Listener { | |
| 29 public: | |
| 30 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback; | |
| 31 | |
| 32 explicit IqSender(SignalStrategy* signal_strategy); | |
| 33 virtual ~IqSender(); | |
| 34 | |
| 35 // Send an iq stanza. Returns an IqRequest object that represends | |
| 36 // the request. |callback| is called when response to |stanza| is | |
| 37 // received. Destroy the returned IqRequest to cancel the callback. | |
| 38 // Takes ownership of |stanza|. Caller must take ownership of the | |
| 39 // result. Result must be destroyed before sender is destroyed. | |
| 40 IqRequest* SendIq(buzz::XmlElement* stanza, const ReplyCallback& callback); | |
| 41 | |
| 42 // Same as above, but also formats the message. Takes ownership of | |
| 43 // |iq_body|. | |
| 44 IqRequest* SendIq(const std::string& type, | |
| 45 const std::string& addressee, | |
| 46 buzz::XmlElement* iq_body, | |
| 47 const ReplyCallback& callback); | |
|
Wez
2011/11/03 20:29:19
Overloads make style pixie cry.
Sergey Ulanov
2011/11/03 20:52:12
I think this is a case when function overload is a
| |
| 48 | |
| 49 // SignalStrategy::Listener implementation. | |
| 50 virtual bool OnIncomingStanza(const buzz::XmlElement* stanza) OVERRIDE; | |
| 51 | |
| 52 private: | |
| 53 typedef std::map<std::string, IqRequest*> IqRequestMap; | |
| 54 friend class IqRequest; | |
| 55 | |
| 56 // Helper function used to create iq stanzas. | |
| 57 static buzz::XmlElement* MakeIqStanza(const std::string& type, | |
| 58 const std::string& addressee, | |
| 59 buzz::XmlElement* iq_body); | |
| 60 | |
| 61 // Removes |request| from the list of pending requests. Called by IqRequest. | |
| 62 void RemoveRequest(IqRequest* request); | |
| 63 | |
| 64 SignalStrategy* signal_strategy_; | |
| 65 IqRequestMap requests_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(IqSender); | |
| 68 }; | |
| 69 | |
| 70 // This call must only be used on the thread it was created on. | |
| 71 class IqRequest { | |
| 72 public: | |
| 73 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback); | |
| 74 ~IqRequest(); | |
| 75 | |
| 76 private: | |
| 77 friend class IqSender; | |
| 78 | |
| 79 // Called by IqSender when a response is received. | |
| 80 void OnResponse(const buzz::XmlElement* stanza); | |
| 81 | |
| 82 IqSender* sender_; | |
| 83 IqSender::ReplyCallback callback_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(IqRequest); | |
| 86 }; | |
| 87 | |
| 88 } // namespace remoting | |
| 89 | |
| 90 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_ | |
| OLD | NEW |