• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libjingle
3  * Copyright 2004--2005, Google Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  *  1. Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *  2. Redistributions in binary form must reproduce the above copyright notice,
11  *     this list of conditions and the following disclaimer in the documentation
12  *     and/or other materials provided with the distribution.
13  *  3. The name of the author may not be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _SESSIONMANAGERTASK_H_
29 #define _SESSIONMANAGERTASK_H_
30 
31 #include "talk/p2p/base/sessionmanager.h"
32 #include "talk/p2p/client/sessionsendtask.h"
33 #include "talk/xmpp/xmppengine.h"
34 #include "talk/xmpp/xmpptask.h"
35 
36 namespace cricket {
37 
38 // This class handles sending and receiving XMPP messages on behalf of the
39 // SessionManager.  The sending part is handed over to SessionSendTask.
40 
41 class SessionManagerTask : public buzz::XmppTask {
42  public:
SessionManagerTask(TaskParent * parent,SessionManager * session_manager)43   SessionManagerTask(TaskParent *parent, SessionManager *session_manager)
44       : buzz::XmppTask(parent, buzz::XmppEngine::HL_SINGLE) {
45     session_manager_ = session_manager;
46   }
47 
~SessionManagerTask()48   ~SessionManagerTask() {
49   }
50 
51   // Turns on simple support for sending messages, using SessionSendTask.
EnableOutgoingMessages()52   void EnableOutgoingMessages() {
53     session_manager_->SignalOutgoingMessage.connect(
54         this, &SessionManagerTask::OnOutgoingMessage);
55     session_manager_->SignalRequestSignaling.connect(
56         session_manager_, &SessionManager::OnSignalingReady);
57   }
58 
ProcessStart()59   virtual int ProcessStart() {
60     const buzz::XmlElement *stanza = NextStanza();
61     if (stanza == NULL)
62       return STATE_BLOCKED;
63     session_manager_->OnIncomingMessage(stanza);
64     return STATE_START;
65   }
66 
67  protected:
HandleStanza(const buzz::XmlElement * stanza)68   virtual bool HandleStanza(const buzz::XmlElement *stanza) {
69     if (!session_manager_->IsSessionMessage(stanza))
70       return false;
71     // Responses are handled by the SessionSendTask that sent the request.
72     //if (stanza->Attr(buzz::QN_TYPE) != buzz::STR_SET)
73     //  return false;
74     QueueStanza(stanza);
75     return true;
76   }
77 
78  private:
79   SessionManager* session_manager_;
80 
OnOutgoingMessage(SessionManager * manager,const buzz::XmlElement * stanza)81   void OnOutgoingMessage(SessionManager* manager,
82                          const buzz::XmlElement* stanza) {
83     cricket::SessionSendTask* sender =
84         new cricket::SessionSendTask(GetParent(), session_manager_);
85     sender->Send(stanza);
86     sender->Start();
87   }
88 };
89 
90 }  // namespace cricket
91 
92 #endif // _SESSIONMANAGERTASK_H_
93