Code

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