gloox  1.0.10
messagesession.h
1 /*
2  Copyright (c) 2005-2013 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 #include "gloox.h"
19 
20 #include <string>
21 #include <list>
22 
23 namespace gloox
24 {
25 
26  class ClientBase;
27  class MessageFilter;
28  class MessageHandler;
29  class Message;
30 
145  class GLOOX_API MessageSession
146  {
147 
148  friend class MessageFilter;
149 
150  public:
169  MessageSession( ClientBase* parent, const JID& jid, bool wantUpgrade = true, int types = 0, bool honorTID = true );
170 
177  virtual ~MessageSession();
178 
183  const JID& target() const { return m_target; }
184 
190  const std::string& threadID() const { return m_thread; }
191 
197  void setThreadID( const std::string& thread ) { m_thread = thread; }
198 
204  bool honorThreadID() const { return m_honorThreadID; }
205 
212  void registerMessageHandler( MessageHandler* mh )
213  { m_messageHandler = mh; }
214 
219  void removeMessageHandler()
220  { m_messageHandler = 0; }
221 
226  virtual void send( const std::string& message );
227 
236  virtual void send( const std::string& message, const std::string& subject,
237  const StanzaExtensionList& sel = StanzaExtensionList() );
238 
247  void registerMessageFilter( MessageFilter* mf )
248  { m_messageFilterList.push_back( mf ); }
249 
255  void removeMessageFilter( MessageFilter* mf )
256  { m_messageFilterList.remove( mf ); }
257 
263  void disposeMessageFilter( MessageFilter* mf );
264 
269  int types() const { return m_types; }
270 
279  void resetResource();
280 
286  virtual void handleMessage( Message& msg );
287 
288  protected:
295  virtual void send( const Message& msg );
296  void decorate( Message& msg );
297 
298  ClientBase* m_parent;
299  JID m_target;
300  MessageHandler* m_messageHandler;
301 
302  private:
303  void setResource( const std::string& resource );
304 
305  typedef std::list<MessageFilter*> MessageFilterList;
306  MessageFilterList m_messageFilterList;
307 
308  std::string m_thread;
309  int m_types;
310  bool m_wantResourceTracking;
311  bool m_hadMessages;
312  bool m_honorThreadID;
313 
314  };
315 
316 }
317 
318 #endif // MESSAGESESSION_H__