gloox  1.1-svn
jinglesession.h
1 /*
2  Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef JINGLESESSION_H__
15 #define JINGLESESSION_H__
16 
17 #include "stanzaextension.h"
18 #include "tag.h"
19 #include "iqhandler.h"
20 #include "jingleplugin.h"
21 
22 #include <string>
23 
24 namespace gloox
25 {
26 
27  class ClientBase;
28 
38  namespace Jingle
39  {
40 
41  class Description;
42  class Transport;
43  class SessionHandler;
44  class Content;
45 
49  typedef std::list<const Plugin*> PluginList;
50 
54  enum Action
55  {
71  };
72 
84  class GLOOX_API Session : public IqHandler
85  {
86 
87  public:
91  enum State
92  {
95  Active
96  };
97 
105  class GLOOX_API Reason : public Plugin
106  {
107  public:
111  enum Reasons
112  {
127  InvalidReason
128  };
129 
136  Reason( Reasons reason, const std::string& sid = EmptyString,
137  const std::string& text = EmptyString );
138 
143  Reason( const Tag* tag = 0 );
144 
148  virtual ~Reason() {}
149 
154  Reasons reason() const { return m_reason; }
155 
161  const std::string& sid() const { return m_sid; }
162 
168  const std::string& text() const { return m_text; }
169 
170  // reimplemented from Jingle::Plugin
171  virtual const std::string& filterString() const;
172 
173  // reimplemented from Jingle::Plugin
174  virtual Tag* tag() const;
175 
176  // reimplemented from Jingle::Plugin
177  virtual Plugin* clone() const;
178 
179  private:
180  Reasons m_reason;
181  std::string m_sid;
182  std::string m_text;
183 
184  };
185 
193  class Jingle : public StanzaExtension
194  {
195 
196  friend class Session;
197 
198  public:
203  Jingle( const Tag* tag = 0 );
204 
208  virtual ~Jingle();
209 
214  const std::string& sid() const { return m_sid; }
215 
219  void setInitiator( const JID& jid ) { m_initiator = jid; }
220 
225  const JID& initiator() const { return m_initiator; }
226 
230  void setResponder( const std::string& responder ) { m_responder = responder; }
231 
235  Action action() const { return m_action; }
236 
237  // reimplemented from StanzaExtension
238  virtual const std::string& filterString() const;
239 
240  // reimplemented from StanzaExtension
241  virtual StanzaExtension* newInstance( const Tag* tag ) const
242  {
243  return new Jingle( tag );
244  }
245 
246  // reimplemented from StanzaExtension
247  virtual Tag* tag() const;
248 
249  // reimplemented from StanzaExtension
250  virtual StanzaExtension* clone() const;
251 
252 #ifdef JINGLE_TEST
253  public:
254 #else
255  private:
256 #endif
257 
265  Jingle( Action action, const JID& initiator,
266  const PluginList& plugins, const std::string& sid );
267 
276  Jingle( Action action, const JID& initiator,
277  const Plugin* plugin, const std::string& sid );
278 
283  Jingle( const Jingle& right );
284 
285  Action m_action;
286  std::string m_sid;
287  JID m_initiator;
288  JID m_responder;
289  PluginList m_plugins;
290 
291  };
292 
299  Session( ClientBase* parent, const JID& callee, SessionHandler* jsh );
300 
308  Session( ClientBase* parent, const Session::Jingle* jingle,
309  SessionHandler* jsh );
310 
314  virtual ~Session();
315 
321  bool initiate( const PluginList& plugins );
322 
329  bool accept( const Content* content );
330 
338  bool inform( Action action, const Plugin* plugin );
339 
345  bool terminate( Reason* reason );
346 
351  State state() const { return m_state; }
352 
357  const std::string& sid() const { return m_sid; }
358 
359  // reimplemented from IqHandler
360  virtual bool handleIq( const IQ& iq );
361 
362  // reimplemented from IqHandler
363  virtual void handleIqID( const IQ& iq, int context );
364 
365 #ifdef JINGLE_TEST
366  public:
367 #else
368  private:
369 #endif
370  ClientBase* m_parent;
371  State m_state;
372  JID m_callee;
373  JID m_initiator;
374  SessionHandler* m_handler;
375  std::string m_sid;
376  bool m_valid;
377 
378  };
379 
380  }
381 
382 }
383 
384 #endif // JINGLESESSION_H__