Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SENDER_H_ | 5 #ifndef REMOTING_JINGLE_GLUE_IQ_SENDER_H_ |
| 6 #define REMOTING_JINGLE_GLUE_IQ_SENDER_H_ | 6 #define REMOTING_JINGLE_GLUE_IQ_SENDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | |
| 15 #include "remoting/jingle_glue/signal_strategy.h" | 16 #include "remoting/jingle_glue/signal_strategy.h" |
| 16 | 17 |
| 17 namespace buzz { | 18 namespace buzz { |
| 18 class XmlElement; | 19 class XmlElement; |
| 19 } // namespace buzz | 20 } // namespace buzz |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace remoting { |
| 22 | 23 |
| 23 class IqRequest; | 24 class IqRequest; |
| 24 class SignalStrategy; | 25 class SignalStrategy; |
| 25 | 26 |
| 26 // IqSender handles sending iq requests and routing of responses to | 27 // IqSender handles sending iq requests and routing of responses to |
| 27 // those requests. | 28 // those requests. |
| 28 class IqSender : public SignalStrategy::Listener { | 29 class IqSender : public SignalStrategy::Listener { |
| 29 public: | 30 public: |
| 30 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback; | 31 // Callback that is called when an Iq response is received. Called |
| 32 // with the |response| set to NULL in case of a timeout. | |
| 33 typedef base::Callback<void(IqRequest* request, | |
| 34 const buzz::XmlElement* response)> ReplyCallback; | |
| 31 | 35 |
| 32 explicit IqSender(SignalStrategy* signal_strategy); | 36 explicit IqSender(SignalStrategy* signal_strategy); |
| 33 virtual ~IqSender(); | 37 virtual ~IqSender(); |
| 34 | 38 |
| 35 // Send an iq stanza. Returns an IqRequest object that represends | 39 // Send an iq stanza. Returns an IqRequest object that represends |
| 36 // the request. |callback| is called when response to |stanza| is | 40 // the request. |callback| is called when response to |stanza| is |
| 37 // received. Destroy the returned IqRequest to cancel the callback. | 41 // received. Destroy the returned IqRequest to cancel the callback. |
| 38 // Caller must take ownership of the result. Result must be | 42 // Caller must take ownership of the result. Result must be |
| 39 // destroyed before sender is destroyed. | 43 // destroyed before sender is destroyed. |
| 40 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza, | 44 scoped_ptr<IqRequest> SendIq(scoped_ptr<buzz::XmlElement> stanza, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 65 // Removes |request| from the list of pending requests. Called by IqRequest. | 69 // Removes |request| from the list of pending requests. Called by IqRequest. |
| 66 void RemoveRequest(IqRequest* request); | 70 void RemoveRequest(IqRequest* request); |
| 67 | 71 |
| 68 SignalStrategy* signal_strategy_; | 72 SignalStrategy* signal_strategy_; |
| 69 IqRequestMap requests_; | 73 IqRequestMap requests_; |
| 70 | 74 |
| 71 DISALLOW_COPY_AND_ASSIGN(IqSender); | 75 DISALLOW_COPY_AND_ASSIGN(IqSender); |
| 72 }; | 76 }; |
| 73 | 77 |
| 74 // This call must only be used on the thread it was created on. | 78 // This call must only be used on the thread it was created on. |
| 75 class IqRequest { | 79 class IqRequest : public base::SupportsWeakPtr<IqRequest> { |
| 76 public: | 80 public: |
| 77 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback); | 81 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback, |
| 82 const std::string& jid); | |
|
simonmorris
2012/02/24 00:11:31
|jid| is called "addressee" elsewhere. I'd suggest
Sergey Ulanov
2012/02/24 21:56:31
Done.
| |
| 78 ~IqRequest(); | 83 ~IqRequest(); |
| 79 | 84 |
| 85 // Sets timeout for the request. When the timeout expires the | |
| 86 // callback is called with the |response| set to NULL. | |
| 87 void SetTimeout(base::TimeDelta timeout); | |
| 88 | |
| 80 private: | 89 private: |
| 81 friend class IqSender; | 90 friend class IqSender; |
| 82 | 91 |
| 92 void CallCallback(const buzz::XmlElement* stanza); | |
| 93 void OnTimeout(); | |
| 94 | |
| 83 // Called by IqSender when a response is received. | 95 // Called by IqSender when a response is received. |
| 84 void OnResponse(const buzz::XmlElement* stanza); | 96 void OnResponse(const buzz::XmlElement* stanza); |
| 85 | 97 |
| 86 IqSender* sender_; | 98 IqSender* sender_; |
| 87 IqSender::ReplyCallback callback_; | 99 IqSender::ReplyCallback callback_; |
| 100 std::string addressee_; | |
| 88 | 101 |
| 89 DISALLOW_COPY_AND_ASSIGN(IqRequest); | 102 DISALLOW_COPY_AND_ASSIGN(IqRequest); |
| 90 }; | 103 }; |
| 91 | 104 |
| 92 } // namespace remoting | 105 } // namespace remoting |
| 93 | 106 |
| 94 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_ | 107 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_ |
| OLD | NEW |