OLD | NEW |
| (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_SESSIONMANAGERTASK_H_ | |
12 #define WEBRTC_LIBJINGLE_SESSION_SESSIONMANAGERTASK_H_ | |
13 | |
14 #include "webrtc/libjingle/session/sessionmanager.h" | |
15 #include "webrtc/libjingle/session/sessionsendtask.h" | |
16 #include "webrtc/libjingle/xmpp/xmppengine.h" | |
17 #include "webrtc/libjingle/xmpp/xmpptask.h" | |
18 | |
19 namespace cricket { | |
20 | |
21 // This class handles sending and receiving XMPP messages on behalf of the | |
22 // SessionManager. The sending part is handed over to SessionSendTask. | |
23 | |
24 class SessionManagerTask : public buzz::XmppTask { | |
25 public: | |
26 SessionManagerTask(buzz::XmppTaskParentInterface* parent, | |
27 SessionManager* session_manager) | |
28 : buzz::XmppTask(parent, buzz::XmppEngine::HL_SINGLE), | |
29 session_manager_(session_manager) { | |
30 } | |
31 | |
32 ~SessionManagerTask() { | |
33 } | |
34 | |
35 // Turns on simple support for sending messages, using SessionSendTask. | |
36 void EnableOutgoingMessages() { | |
37 session_manager_->SignalOutgoingMessage.connect( | |
38 this, &SessionManagerTask::OnOutgoingMessage); | |
39 session_manager_->SignalRequestSignaling.connect( | |
40 session_manager_, &SessionManager::OnSignalingReady); | |
41 } | |
42 | |
43 virtual int ProcessStart() { | |
44 const buzz::XmlElement *stanza = NextStanza(); | |
45 if (stanza == NULL) | |
46 return STATE_BLOCKED; | |
47 session_manager_->OnIncomingMessage(stanza); | |
48 return STATE_START; | |
49 } | |
50 | |
51 protected: | |
52 virtual bool HandleStanza(const buzz::XmlElement *stanza) { | |
53 if (!session_manager_->IsSessionMessage(stanza)) | |
54 return false; | |
55 // Responses are handled by the SessionSendTask that sent the request. | |
56 //if (stanza->Attr(buzz::QN_TYPE) != buzz::STR_SET) | |
57 // return false; | |
58 QueueStanza(stanza); | |
59 return true; | |
60 } | |
61 | |
62 private: | |
63 void OnOutgoingMessage(SessionManager* manager, | |
64 const buzz::XmlElement* stanza) { | |
65 cricket::SessionSendTask* sender = | |
66 new cricket::SessionSendTask(parent_, session_manager_); | |
67 sender->Send(stanza); | |
68 sender->Start(); | |
69 } | |
70 | |
71 SessionManager* session_manager_; | |
72 }; | |
73 | |
74 } // namespace cricket | |
75 | |
76 #endif // WEBRTC_P2P_CLIENT_SESSIONMANAGERTASK_H_ | |
OLD | NEW |