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 // IqRegistry handles routing of iq responses to corresponding | |
Wez
2011/11/03 02:09:30
IqRegistry -> IqSender?
Sergey Ulanov
2011/11/03 02:41:31
Done.
| |
27 // IqRequest objects. Created in SignalStrategy and should not be used | |
28 // directly. | |
Wez
2011/11/03 02:09:30
This comment is out of date?
Sergey Ulanov
2011/11/03 02:41:31
Done.
| |
29 class IqSender : public SignalStrategy::Listener { | |
30 public: | |
31 typedef base::Callback<void(const buzz::XmlElement*)> ReplyCallback; | |
32 | |
33 static buzz::XmlElement* MakeIqStanza(const std::string& type, | |
34 const std::string& addressee, | |
35 buzz::XmlElement* iq_body); | |
Wez
2011/11/03 02:09:30
Why not fold MakeIqStanza() in to SendIq()?
Sergey Ulanov
2011/11/03 02:41:31
This is a static helper that creates Iq stanzas. I
Wez
2011/11/03 17:09:06
Yes, but given that all(?) the stanzas we send are
Sergey Ulanov
2011/11/03 17:56:00
Not all outgoing stanzas are built with MakeIqStan
| |
36 | |
37 explicit IqSender(SignalStrategy* signal_strategy); | |
38 virtual ~IqSender(); | |
39 | |
40 // Send an iq stanza. Returns an IqRequest object that represends | |
41 // the request. |callback| is called when response to |stanza| is | |
42 // received. Destroy the returned IqRequest to cancel the callback. | |
Wez
2011/11/03 02:09:30
Who owns |stanza|?
Sergey Ulanov
2011/11/03 02:41:31
Done.
| |
43 IqRequest* SendIq(buzz::XmlElement* stanza, const ReplyCallback& callback); | |
Wez
2011/11/03 02:09:30
Who is responsible for cleaning up IqRequest? Wha
Sergey Ulanov
2011/11/03 02:41:31
Done.
| |
44 | |
45 // SignalStrategy::Listener implementation. | |
46 virtual bool OnIncomingStanza(const buzz::XmlElement* stanza) OVERRIDE; | |
47 | |
48 private: | |
49 typedef std::map<std::string, IqRequest*> IqRequestMap; | |
50 friend class IqRequest; | |
51 | |
52 // Removes |request| from the list of pending requests. Called by IqRequest. | |
53 void RemoveRequest(IqRequest* request); | |
54 | |
55 SignalStrategy* signal_strategy_; | |
56 IqRequestMap requests_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(IqSender); | |
59 }; | |
60 | |
61 // This call must only be used on the thread it was created on. | |
62 class IqRequest { | |
63 public: | |
64 IqRequest(IqSender* sender, const IqSender::ReplyCallback& callback); | |
65 ~IqRequest(); | |
66 | |
67 private: | |
68 FRIEND_TEST_ALL_PREFIXES(IqRequestTest, MakeIqStanza); | |
69 friend class IqSender; | |
70 | |
71 // Called by IqSender when a response is received. | |
72 void OnResponse(const buzz::XmlElement* stanza); | |
73 | |
74 SignalStrategy* signal_strategy_; | |
Wez
2011/11/03 02:09:30
Do you need to keep a copy of the SignalStrategy h
Sergey Ulanov
2011/11/03 02:41:31
No. SignalStratgy may be used by other object (in
Wez
2011/11/03 17:09:06
Right. But each IqSender only has a single Signal
Sergey Ulanov
2011/11/03 17:56:00
Oh, sorry, I misunderstood. This field wasn't even
| |
75 IqSender* sender_; | |
76 IqSender::ReplyCallback callback_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(IqRequest); | |
79 }; | |
80 | |
81 } // namespace remoting | |
82 | |
83 #endif // REMOTING_JINGLE_GLUE_IQ_SENDER_H_ | |
OLD | NEW |