gloox  1.0.1
messagesession.h
1 /*
2  Copyright (c) 2005-2012 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 
230  virtual void send( const std::string& message, const std::string& subject = EmptyString,
231  const StanzaExtensionList& sel = StanzaExtensionList() );
232 
241  void registerMessageFilter( MessageFilter* mf )
242  { m_messageFilterList.push_back( mf ); }
243 
249  void removeMessageFilter( MessageFilter* mf )
250  { m_messageFilterList.remove( mf ); }
251 
257  void disposeMessageFilter( MessageFilter* mf );
258 
263  int types() const { return m_types; }
264 
273  void resetResource();
274 
280  virtual void handleMessage( Message& msg );
281 
282  protected:
289  virtual void send( const Message& msg );
290  void decorate( Message& msg );
291 
292  ClientBase* m_parent;
293  JID m_target;
294  MessageHandler* m_messageHandler;
295 
296  private:
297  void setResource( const std::string& resource );
298 
299  typedef std::list<MessageFilter*> MessageFilterList;
300  MessageFilterList m_messageFilterList;
301 
302  std::string m_thread;
303  int m_types;
304  bool m_wantResourceTracking;
305  bool m_hadMessages;
306  bool m_honorThreadID;
307 
308  };
309 
310 }
311 
312 #endif // MESSAGESESSION_H__