gloox  0.9.9.12
messagesession.h
1 /*
2  Copyright (c) 2005-2008 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 MESSAGESESSION_H__
15 #define MESSAGESESSION_H__
16 
17 #include "jid.h"
18 
19 #include <string>
20 #include <list>
21 
22 namespace gloox
23 {
24 
25  class ClientBase;
26  class Tag;
27  class MessageFilter;
28  class MessageHandler;
29  class Stanza;
30 
146  class GLOOX_API MessageSession
147  {
148 
149  friend class MessageFilter;
150 
151  public:
168  MessageSession( ClientBase *parent, const JID& jid, bool wantUpgrade = true, int types = 0 );
169 
176  virtual ~MessageSession();
177 
182  const JID& target() const { return m_target; }
183 
189  const std::string& threadID() const { return m_thread; }
190 
196  void setThreadID( const std::string& thread ) { m_thread = thread; }
197 
204  void registerMessageHandler( MessageHandler *mh );
205 
210  void removeMessageHandler();
211 
218  virtual void send( const std::string& message, const std::string& subject = "" );
219 
228  void registerMessageFilter( MessageFilter *mf );
229 
235  void removeMessageFilter( MessageFilter *mf );
236 
242  void disposeMessageFilter( MessageFilter *mf );
243 
249  int types() const { return m_types; }
250 
258  void resetResource();
259 
260  // re-implemented from MessageHandler
261  virtual void handleMessage( Stanza *stanza );
262 
263  protected:
270  virtual void send( Tag *tag );
271  void decorate( Tag *tag );
272 
273  ClientBase *m_parent;
274  JID m_target;
275  MessageHandler *m_messageHandler;
276 
277  private:
278  void setResource( const std::string& resource );
279 
280  typedef std::list<MessageFilter*> MessageFilterList;
281  MessageFilterList m_messageFilterList;
282 
283  std::string m_thread;
284  int m_types;
285  bool m_wantUpgrade;
286  bool m_hadMessages;
287 
288  };
289 
290 }
291 
292 #endif // MESSAGESESSION_H__