OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SIGNALING_IQ_SENDER_H_ | 5 #ifndef REMOTING_SIGNALING_IQ_SENDER_H_ |
6 #define REMOTING_SIGNALING_IQ_SENDER_H_ | 6 #define REMOTING_SIGNALING_IQ_SENDER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace remoting { | 26 namespace remoting { |
27 | 27 |
28 class IqRequest; | 28 class IqRequest; |
29 class SignalStrategy; | 29 class SignalStrategy; |
30 | 30 |
31 // IqSender handles sending iq requests and routing of responses to | 31 // IqSender handles sending iq requests and routing of responses to |
32 // those requests. | 32 // those requests. |
33 class IqSender : public SignalStrategy::Listener { | 33 class IqSender : public SignalStrategy::Listener { |
34 public: | 34 public: |
35 // Callback that is called when an Iq response is received. Called | 35 // Callback that is called when an Iq response is received. Called |
36 // with the |response| set to NULL in case of a timeout. | 36 // with the |response| set to nullptr in case of a timeout. |
37 typedef base::Callback<void(IqRequest* request, | 37 typedef base::Callback<void(IqRequest* request, |
38 const buzz::XmlElement* response)> ReplyCallback; | 38 const buzz::XmlElement* response)> ReplyCallback; |
39 | 39 |
40 explicit IqSender(SignalStrategy* signal_strategy); | 40 explicit IqSender(SignalStrategy* signal_strategy); |
41 ~IqSender() override; | 41 ~IqSender() override; |
42 | 42 |
43 // Send an iq stanza. Returns an IqRequest object that represends | 43 // Send an iq stanza. Returns an IqRequest object that represends |
44 // the request. |callback| is called when response to |stanza| is | 44 // the request. |callback| is called when response to |stanza| is |
45 // received. Destroy the returned IqRequest to cancel the callback. | 45 // received. Destroy the returned IqRequest to cancel the callback. |
46 // Caller must take ownership of the result. Result must be | 46 // Caller must take ownership of the result. Result must be |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 }; | 78 }; |
79 | 79 |
80 // This call must only be used on the thread it was created on. | 80 // This call must only be used on the thread it was created on. |
81 class IqRequest : public base::SupportsWeakPtr<IqRequest> { | 81 class IqRequest : public base::SupportsWeakPtr<IqRequest> { |
82 public: | 82 public: |
83 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback, | 83 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback, |
84 const std::string& addressee); | 84 const std::string& addressee); |
85 ~IqRequest(); | 85 ~IqRequest(); |
86 | 86 |
87 // Sets timeout for the request. When the timeout expires the | 87 // Sets timeout for the request. When the timeout expires the |
88 // callback is called with the |response| set to NULL. | 88 // callback is called with the |response| set to nullptr. |
89 void SetTimeout(base::TimeDelta timeout); | 89 void SetTimeout(base::TimeDelta timeout); |
90 | 90 |
91 private: | 91 private: |
92 friend class IqSender; | 92 friend class IqSender; |
93 | 93 |
94 void CallCallback(const buzz::XmlElement* stanza); | 94 void CallCallback(const buzz::XmlElement* stanza); |
95 void OnTimeout(); | 95 void OnTimeout(); |
96 | 96 |
97 // Called by IqSender when a response is received. | 97 // Called by IqSender when a response is received. |
98 void OnResponse(const buzz::XmlElement* stanza); | 98 void OnResponse(const buzz::XmlElement* stanza); |
99 | 99 |
100 void DeliverResponse(scoped_ptr<buzz::XmlElement> stanza); | 100 void DeliverResponse(scoped_ptr<buzz::XmlElement> stanza); |
101 | 101 |
102 IqSender* sender_; | 102 IqSender* sender_; |
103 IqSender::ReplyCallback callback_; | 103 IqSender::ReplyCallback callback_; |
104 std::string addressee_; | 104 std::string addressee_; |
105 | 105 |
106 DISALLOW_COPY_AND_ASSIGN(IqRequest); | 106 DISALLOW_COPY_AND_ASSIGN(IqRequest); |
107 }; | 107 }; |
108 | 108 |
109 } // namespace remoting | 109 } // namespace remoting |
110 | 110 |
111 #endif // REMOTING_SIGNALING_IQ_SENDER_H_ | 111 #endif // REMOTING_SIGNALING_IQ_SENDER_H_ |
OLD | NEW |