Code

880049db883cdd5219e2b02bcb9cb865373c4717
[inkscape.git] / src / jabber_whiteboard / session-manager.h
1 /**
2  * Whiteboard session manager
3  *
4  * Authors: 
5  * David Yip <yipdw@rose-hulman.edu>
6  * Bob Jamison (Pedro port)
7  *
8  * Copyright (c) 2005 Authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifndef __INKSCAPE_WHITEBOARD_SESSION_MANAGER_H__
14 #define __INKSCAPE_WHITEBOARD_SESSION_MANAGER_H__
16 #include "jabber_whiteboard/pedrogui.h"
18 #include <glibmm.h>
20 #include <list>
21 #include <bitset>
23 #include "jabber_whiteboard/message-queue.h"
24 #include "jabber_whiteboard/defines.h"
25 #include "jabber_whiteboard/internal-constants.h"
26 #include "jabber_whiteboard/inkboard-session.h"
28 #include "gc-alloc.h"
30 class SPDesktop;
32 namespace Inkscape {
34 namespace Whiteboard {
36 enum SessionType {
37     INKBOARD_PRIVATE,
38     INKBOARD_MUC
39 };
41 class SessionManager;
42 class InkboardDocument;
44 class SessionManager : public Pedro::XmppEventListener {
45 public:
47     /**
48      *
49      */
50     SessionManager();
51     
52     /**
53      *
54      */
55     virtual ~SessionManager();
56         
57         
58     static void showClient();
59     static SessionManager& instance();
60     
61     /**
62      *
63      */
64     unsigned long getSequenceNumber();
66     /**
67      *
68      */
69     virtual Pedro::XmppClient &getClient()
70         { return gui.client; }
72     /**
73      *
74      */
75     virtual bool send(const Glib::ustring &destJid, 
76                       const MessageType type,
77                       const Glib::ustring &data);
79     /**
80      *
81      */
82     virtual bool sendGroup(const Glib::ustring &destJid,
83                            const MessageType type,
84                            const Glib::ustring &data);
85     /**
86      *
87      */
88     virtual void processXmppEvent(const Pedro::XmppEvent &event);
90     /**
91      * The session handling has been broken out into a subclass of XML::Session.  See
92      * Whiteboard::InkboardSession and Whiteboard::InkboardDocument, both of which
93      * are still under heavy construction.  Don't expect them to work just yet.
94      *
95      * This (should) allow us to substitute an InkboardDocument for an
96      * XML::SimpleDocument (InkboardDocument uses InkboardSession), which, I think, should 
97      * lead to a very clean way of integrating Inkboard.  It should also
98      * give us a cleaner way of handling node tracking.  Finally,
99      * it'll let us experiment with data models that may be more appropriate for Inkboard.
100      *
101      * SessionManager still manages sessions insofar as it receives XMPP data from Pedro and
102      * sends it off to the correct InkboardSession.  I'd like to have it still manage
103      * user sessions, which is what the user sees; however, that can be confusing from
104      * a programmer's standpoint.  This class might therefore need to be renamed 
105      * or something.
106      *
107      * Creation of an Inkboard session should be handled in some fashion similar
108      * to this:
109      *
110      * (1) The user chooses a chat room or user with which she wants to share a whiteboard.
111      *
112      * (2) This invokes the appropriate doShare() method in Pedro's GUI.
113      *
114      * (3) doShare() invokes code to create a new Inkscape desktop with a blank document.
115      * This desktop will use InkboardDocument (and hence InkboardSession) for transaction
116      * management.
117          *
118      * (4) Inkboard setup and operation proceeds as it did in the Loudmouth-based code.
119      *
120      * (3) and (4) will probably need tweaking (for example, it's probably a bad idea to
121      * open up a new desktop if an invitation is refused).   Actually, really, nothing
122      * here is set in stone.  Feel free to modify.              -- dwyip 2005-11-21
123      * 
124      */
126     /**
127      * Initiates a shared session with a user or conference room.
128      * 
129      * \param to The recipient to which this desktop will be linked, specified as a JID.
130      * \param type Type of the session; i.e. private message or group chat.
131      */
132     virtual void doShare(Glib::ustring const& to, SessionType type);
134     /**
135      * Creates a new desktop with an InkboardDocument.
136      *
137      * An InkboardDocument (and hence desktop)
138      * is identified by the recipient of the document, be it a 
139      * conference room or another user.  If an existing document is found, it will be
140      * returned.
141      *
142      * \param to The recipient to which this desktop will be linked, specified as a JID.
143      * \param type Type of the session; i.e. private message or group chat.
144      * \return A pointer to the created SPDesktop.
145      */
146     virtual SPDesktop* createInkboardDesktop(Glib::ustring const& to, SessionType type);
148     /**
149      * Terminates an Inkboard session to a given recipient.  If the session to be
150      * terminated does not exist, does nothing.
151      *
152      * \param to The recipient JID identifying the session to be terminated.
153      */
154     virtual void terminateInkboardSession(Glib::ustring const& to);
156     /**
157      * Locates an Inkboard session by recipient JID.  
158      *
159      * \param to The recipient JID identifying the session to be located.
160      * \return A pointer to the InkboardDocument associated with the Inkboard session,
161      * or NULL if no such session exists.
162      */
163     InkboardDocument* getInkboardSession(Glib::ustring const& to);
165         void operator=(XmppEventListener const& other) {
167         }
168 private:
169         // types
170     typedef std::pair< Glib::ustring, InkboardDocument* > Inkboard_record_type;
171     typedef std::vector< Inkboard_record_type, GC::Alloc< Inkboard_record_type, GC::MANUAL > > Inkboards_type;
173         typedef std::list< Glib::ustring > Pending_invitations_type;
175         typedef std::pair< Glib::ustring, InvitationResponses > Invitation_response_type;
176         typedef std::list< Invitation_response_type > Invitation_responses_type;
178         // functors
179         struct CheckInvitationSender {
180         public:
181                 CheckInvitationSender(Glib::ustring const& x) : x(x) { }
182                 ~CheckInvitationSender() { }
184                 bool operator()(SessionManager::Invitation_response_type const& y) const {
185                         return (x == y.first);
186                 }
187         private:
188                 Glib::ustring const& x;
189         };
191         // objects 
192     Pedro::PedroGui gui;
193     SendMessageQueue sendMessageQueue;
194     ReceiveMessageQueue receiveMessageQueue;
196         // members
197     unsigned long sequenceNumber;
198     Inkboards_type _inkboards;
199         Pending_invitations_type _pending_invitations;
200         Invitation_responses_type _invitation_responses;
202         sigc::connection _check_pending_invitations;
203         sigc::connection _check_invitation_responses;
205         // methods
206     void _processInkboardEvent(Pedro::XmppEvent const& event);
207         void _handleSessionEvent(MessageType mtype, Pedro::XmppEvent const& event);
208     void _handleIncomingInvitation(Glib::ustring const& from);
209         void _handleInvitationResponse(Glib::ustring const& from, InvitationResponses resp);
211         // methods handled externally
212         bool _checkInvitationQueue();
213         bool _checkInvitationResponseQueue();
214 };
216 }  // namespace Whiteboard
218 }  // namespace Inkscape
220 #endif  /* __SESSION_MANAGER_H__ */
222 /*
223   Local Variables:
224   mode:c++
225   c-file-style:"stroustrup"
226   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
227   indent-tabs-mode:nil
228   fill-column:99
229   End:
230 */
231 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :