Code

Refactoring Session Establishment
[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);
78     /**
79      *
80      */
81     virtual bool sendProtocol(const Glib::ustring &destJid, 
82                       const MessageType type);
84     /**
85      *
86      */
87     virtual bool sendGroup(const Glib::ustring &destJid,
88                            const MessageType type,
89                            const Glib::ustring &data);
90     /**
91      *
92      */
93     virtual void processXmppEvent(const Pedro::XmppEvent &event);
95     /**
96      * The session handling has been broken out into a subclass of XML::Session.  See
97      * Whiteboard::InkboardSession and Whiteboard::InkboardDocument, both of which
98      * are still under heavy construction.  Don't expect them to work just yet.
99      *
100      * This (should) allow us to substitute an InkboardDocument for an
101      * XML::SimpleDocument (InkboardDocument uses InkboardSession), which, I think, should 
102      * lead to a very clean way of integrating Inkboard.  It should also
103      * give us a cleaner way of handling node tracking.  Finally,
104      * it'll let us experiment with data models that may be more appropriate for Inkboard.
105      *
106      * SessionManager still manages sessions insofar as it receives XMPP data from Pedro and
107      * sends it off to the correct InkboardSession.  I'd like to have it still manage
108      * user sessions, which is what the user sees; however, that can be confusing from
109      * a programmer's standpoint.  This class might therefore need to be renamed 
110      * or something.
111      *
112      * Creation of an Inkboard session should be handled in some fashion similar
113      * to this:
114      *
115      * (1) The user chooses a chat room or user with which she wants to share a whiteboard.
116      *
117      * (2) This invokes the appropriate doShare() method in Pedro's GUI.
118      *
119      * (3) doShare() invokes code to create a new Inkscape desktop with a blank document.
120      * This desktop will use InkboardDocument (and hence InkboardSession) for transaction
121      * management.
122          *
123      * (4) Inkboard setup and operation proceeds as it did in the Loudmouth-based code.
124      *
125      * (3) and (4) will probably need tweaking (for example, it's probably a bad idea to
126      * open up a new desktop if an invitation is refused).   Actually, really, nothing
127      * here is set in stone.  Feel free to modify.              -- dwyip 2005-11-21
128      * 
129      */
131     /**
132      * Initiates a shared session with a user or conference room.
133      * 
134      * \param to The recipient to which this desktop will be linked, specified as a JID.
135      * \param type Type of the session; i.e. private message or group chat.
136      */
137     virtual void doShare(Glib::ustring const& to, SessionType type);
139     /**
140      * Creates a new desktop with an InkboardDocument.
141      *
142      * An InkboardDocument (and hence desktop)
143      * is identified by the recipient of the document, be it a 
144      * conference room or another user.  If an existing document is found, it will be
145      * returned.
146      *
147      * \param to The recipient to which this desktop will be linked, specified as a JID.
148      * \param type Type of the session; i.e. private message or group chat.
149      * \return A pointer to the created SPDesktop.
150      */
151     virtual SPDesktop* createInkboardDesktop(Glib::ustring const& to, SessionType type);
153     /**
154      * Terminates an Inkboard session to a given recipient.  If the session to be
155      * terminated does not exist, does nothing.
156      *
157      * \param to The recipient JID identifying the session to be terminated.
158      */
159     virtual void terminateInkboardSession(Glib::ustring const& to);
161     /**
162      * Locates an Inkboard session by recipient JID.  
163      *
164      * \param to The recipient JID identifying the session to be located.
165      * \return A pointer to the InkboardDocument associated with the Inkboard session,
166      * or NULL if no such session exists.
167      */
168     InkboardDocument* getInkboardSession(Glib::ustring const& to);
170         void operator=(XmppEventListener const& other) {
172         }
173 private:
174         // types
175     typedef std::pair< Glib::ustring, InkboardDocument* > Inkboard_record_type;
176     typedef std::vector< Inkboard_record_type, GC::Alloc< Inkboard_record_type, GC::MANUAL > > Inkboards_type;
178         typedef std::list< Glib::ustring > Pending_invitations_type;
180         typedef std::pair< Glib::ustring, InvitationResponses > Invitation_response_type;
181         typedef std::list< Invitation_response_type > Invitation_responses_type;
183         // functors
184         struct CheckInvitationSender {
185         public:
186                 CheckInvitationSender(Glib::ustring const& x) : x(x) { }
187                 ~CheckInvitationSender() { }
189                 bool operator()(SessionManager::Invitation_response_type const& y) const {
190                         return (x == y.first);
191                 }
192         private:
193                 Glib::ustring const& x;
194         };
196         // objects 
197     Pedro::PedroGui gui;
198     SendMessageQueue sendMessageQueue;
199     ReceiveMessageQueue receiveMessageQueue;
201         // members
202     unsigned long sequenceNumber;
203     Inkboards_type _inkboards;
204         Pending_invitations_type _pending_invitations;
205         Invitation_responses_type _invitation_responses;
207         sigc::connection _check_pending_invitations;
208         sigc::connection _check_invitation_responses;
210         // methods
211     void _processInkboardEvent(Pedro::XmppEvent const& event);
212         void _handleSessionEvent(MessageType mtype, Pedro::XmppEvent const& event);
213     void _handleIncomingInvitation(Glib::ustring const& from);
214         void _handleInvitationResponse(Glib::ustring const& from, InvitationResponses resp);
216         // methods handled externally
217         bool _checkInvitationQueue();
218         bool _checkInvitationResponseQueue();
219 };
221 }  // namespace Whiteboard
223 }  // namespace Inkscape
225 #endif  /* __SESSION_MANAGER_H__ */
227 /*
228   Local Variables:
229   mode:c++
230   c-file-style:"stroustrup"
231   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
232   indent-tabs-mode:nil
233   fill-column:99
234   End:
235 */
236 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :