gloox  1.0
messagesession.h
1 /*
2  Copyright (c) 2005-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 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:
168  MessageSession( ClientBase* parent, const JID& jid, bool wantUpgrade = true, int types = 0, bool honorTID = true );
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 
203  bool honorThreadID() const { return m_honorThreadID; }
204 
211  void registerMessageHandler( MessageHandler* mh )
212  { m_messageHandler = mh; }
213 
218  void removeMessageHandler()
219  { m_messageHandler = 0; }
220 
229  virtual void send( const std::string& message, const std::string& subject = EmptyString,
230  const StanzaExtensionList& sel = StanzaExtensionList() );
231 
240  void registerMessageFilter( MessageFilter* mf )
241  { m_messageFilterList.push_back( mf ); }
242 
248  void removeMessageFilter( MessageFilter* mf )
249  { m_messageFilterList.remove( mf ); }
250 
256  void disposeMessageFilter( MessageFilter* mf );
257 
262  int types() const { return m_types; }
263 
270  void resetResource();
271 
277  virtual void handleMessage( Message& msg );
278 
279  protected:
286  virtual void send( const Message& msg );
287  void decorate( Message& msg );
288 
289  ClientBase* m_parent;
290  JID m_target;
291  MessageHandler* m_messageHandler;
292 
293  private:
294  void setResource( const std::string& resource );
295 
296  typedef std::list<MessageFilter*> MessageFilterList;
297  MessageFilterList m_messageFilterList;
298 
299  std::string m_thread;
300  int m_types;
301  bool m_wantUpgrade;
302  bool m_hadMessages;
303  bool m_honorThreadID;
304 
305  };
306 
307 }
308 
309 #endif // MESSAGESESSION_H__