Code

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