1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2010-2012 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Please refer to the COPYRIGHT file distributed with this source
6  * distribution for the names of the individual contributors.
7  *
8  * Licq is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Licq is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Licq; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22 
23 #ifndef LICQJABBER_SESSIONMANAGER_H
24 #define LICQJABBER_SESSIONMANAGER_H
25 
26 #include <boost/noncopyable.hpp>
27 #include <gloox/chatstatehandler.h>
28 #include <gloox/messagehandler.h>
29 #include <gloox/messagesessionhandler.h>
30 #include <map>
31 
32 namespace gloox
33 {
34 class ChatStateFilter;
35 class Client;
36 }
37 
38 namespace LicqJabber
39 {
40 
41 class Handler;
42 
43 class SessionManager : private boost::noncopyable,
44                        public gloox::MessageSessionHandler,
45                        public gloox::MessageHandler,
46                        public gloox::ChatStateHandler
47 {
48 public:
49   SessionManager(gloox::Client& client, Handler& handler);
50   ~SessionManager();
51 
52   void sendMessage(const std::string& user, const std::string& message,
53       bool urgent);
54   void notifyTyping(const std::string& user, bool active);
55 
56   // gloox::MessageSessionHandler
57   void handleMessageSession(gloox::MessageSession* session);
58 
59   // gloox::MessageHandler
60   void handleMessage(const gloox::Message& message,
61                      gloox::MessageSession* session);
62 
63   // gloox::ChatStateHandler
64   void handleChatState(const gloox::JID& from, gloox::ChatStateType state);
65 
66 private:
67   gloox::Client& myClient;
68   Handler& myHandler;
69 
70   struct Session
71   {
72     gloox::MessageSession* mySession;
73     gloox::ChatStateFilter* myChatStateFilter;
74   };
75 
76   typedef std::map<std::string, Session> Sessions;
77   Sessions mySessions;
78 
79   Session& findSession(const std::string& user);
80 };
81 
82 } // namespace LicqJabber
83 
84 #endif
85