Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: webrtc/libjingle/session/sessionsendtask.h

Issue 1175243003: Remove webrtc/libjingle/{examples,session}. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/libjingle/session/sessionmessages.cc ('k') | webrtc/libjingle/session/transportparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef WEBRTC_LIBJINGLE_SESSION_SESSIONSENDTASK_H_
12 #define WEBRTC_LIBJINGLE_SESSION_SESSIONSENDTASK_H_
13
14 #include "webrtc/libjingle/session/sessionmanager.h"
15 #include "webrtc/libjingle/xmpp/constants.h"
16 #include "webrtc/libjingle/xmpp/xmppclient.h"
17 #include "webrtc/libjingle/xmpp/xmppengine.h"
18 #include "webrtc/libjingle/xmpp/xmpptask.h"
19 #include "webrtc/base/common.h"
20
21 namespace cricket {
22
23 // The job of this task is to send an IQ stanza out (after stamping it with
24 // an ID attribute) and then wait for a response. If not response happens
25 // within 5 seconds, it will signal failure on a SessionManager. If an error
26 // happens it will also signal failure. If, however, the send succeeds this
27 // task will quietly go away.
28
29 class SessionSendTask : public buzz::XmppTask {
30 public:
31 SessionSendTask(buzz::XmppTaskParentInterface* parent,
32 SessionManager* session_manager)
33 : buzz::XmppTask(parent, buzz::XmppEngine::HL_SINGLE),
34 session_manager_(session_manager) {
35 set_timeout_seconds(15);
36 session_manager_->SignalDestroyed.connect(
37 this, &SessionSendTask::OnSessionManagerDestroyed);
38 }
39
40 virtual ~SessionSendTask() {
41 SignalDone(this);
42 }
43
44 void Send(const buzz::XmlElement* stanza) {
45 ASSERT(stanza_.get() == NULL);
46
47 // This should be an IQ of type set, result, or error. In the first case,
48 // we supply an ID. In the others, it should be present.
49 ASSERT(stanza->Name() == buzz::QN_IQ);
50 ASSERT(stanza->HasAttr(buzz::QN_TYPE));
51 if (stanza->Attr(buzz::QN_TYPE) == "set") {
52 ASSERT(!stanza->HasAttr(buzz::QN_ID));
53 } else {
54 ASSERT((stanza->Attr(buzz::QN_TYPE) == "result") ||
55 (stanza->Attr(buzz::QN_TYPE) == "error"));
56 ASSERT(stanza->HasAttr(buzz::QN_ID));
57 }
58
59 stanza_.reset(new buzz::XmlElement(*stanza));
60 if (stanza_->HasAttr(buzz::QN_ID)) {
61 set_task_id(stanza_->Attr(buzz::QN_ID));
62 } else {
63 stanza_->SetAttr(buzz::QN_ID, task_id());
64 }
65 }
66
67 void OnSessionManagerDestroyed() {
68 // If the session manager doesn't exist anymore, we should still try to
69 // send the message, but avoid calling back into the SessionManager.
70 session_manager_ = NULL;
71 }
72
73 sigslot::signal1<SessionSendTask *> SignalDone;
74
75 protected:
76 virtual int OnTimeout() {
77 if (session_manager_ != NULL) {
78 session_manager_->OnFailedSend(stanza_.get(), NULL);
79 }
80
81 return XmppTask::OnTimeout();
82 }
83
84 virtual int ProcessStart() {
85 SendStanza(stanza_.get());
86 if (stanza_->Attr(buzz::QN_TYPE) == buzz::STR_SET) {
87 return STATE_RESPONSE;
88 } else {
89 return STATE_DONE;
90 }
91 }
92
93 virtual int ProcessResponse() {
94 const buzz::XmlElement* next = NextStanza();
95 if (next == NULL)
96 return STATE_BLOCKED;
97
98 if (session_manager_ != NULL) {
99 if (next->Attr(buzz::QN_TYPE) == buzz::STR_RESULT) {
100 session_manager_->OnIncomingResponse(stanza_.get(), next);
101 } else {
102 session_manager_->OnFailedSend(stanza_.get(), next);
103 }
104 }
105
106 return STATE_DONE;
107 }
108
109 virtual bool HandleStanza(const buzz::XmlElement *stanza) {
110 if (!MatchResponseIq(stanza,
111 buzz::Jid(stanza_->Attr(buzz::QN_TO)), task_id()))
112 return false;
113 if (stanza->Attr(buzz::QN_TYPE) == buzz::STR_RESULT ||
114 stanza->Attr(buzz::QN_TYPE) == buzz::STR_ERROR) {
115 QueueStanza(stanza);
116 return true;
117 }
118 return false;
119 }
120
121 private:
122 SessionManager *session_manager_;
123 rtc::scoped_ptr<buzz::XmlElement> stanza_;
124 };
125
126 }
127
128 #endif // WEBRTC_P2P_CLIENT_SESSIONSENDTASK_H_
OLDNEW
« no previous file with comments | « webrtc/libjingle/session/sessionmessages.cc ('k') | webrtc/libjingle/session/transportparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698