summaryrefslogtreecommitdiffstats
path: root/src/jabber_whiteboard/session-manager.h
blob: 53cc8f5b4e53f71539800558a2064f45eb677853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
 * Whiteboard session manager
 *
 * Authors: 
 * David Yip <yipdw@rose-hulman.edu>
 * Bob Jamison (Pedro port)
 *
 * Copyright (c) 2005 Authors
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#ifndef __INKSCAPE_WHITEBOARD_SESSION_MANAGER_H__
#define __INKSCAPE_WHITEBOARD_SESSION_MANAGER_H__

#include <glibmm.h>

#include <list>
#include <bitset>

#include "desktop.h"

#include "jabber_whiteboard/pedrogui.h"
#include "jabber_whiteboard/message-queue.h"
#include "jabber_whiteboard/defines.h"

#include "gc-alloc.h"

class SPDocument;
class SPDesktop;


namespace Inkscape {

namespace Whiteboard {

class InkboardDocument;

typedef Glib::ustring from,sessionId;
typedef std::pair< Glib::ustring, InkboardDocument* > WhiteboardRecord;
typedef std::vector< WhiteboardRecord, GC::Alloc< WhiteboardRecord, GC::MANUAL > > WhiteboardList;

typedef std::pair< from, sessionId > Invitation;
typedef std::list< Invitation > InvitationList;

class SessionManager : public Pedro::XmppEventListener 
{

public:

    SessionManager();

    virtual ~SessionManager();

    static void             showClient();
    static SessionManager&  instance();

    virtual Pedro::XmppClient &getClient()
        { return gui.client; }

    /**
     * Handles all incoming XMPP events associated with this document
     * apart from CONNECT_REQUEST, which is handled in SessionManager
     */
    virtual void processXmppEvent(const Pedro::XmppEvent &event);


    /**
     * Initiates a shared session with a user or conference room.
     * 
     * \param to The recipient to which this desktop will be linked, specified as a JID.
     * \param type Type of the session; i.e. private message or group chat.
     */
    virtual void initialiseSession(Glib::ustring const& to, State::SessionType type);

    /**
     * Terminates an Inkboard session to a given recipient.  If the session to be
     * terminated does not exist, does nothing.
     *
     * \param sessionId The session identifier to be terminated.
     */
    virtual void terminateSession(Glib::ustring const& sessionId);

    /**
     * Adds a session to whiteboard
     *
     * \param sessionId The session identifier to be terminated.
     */
    virtual void addSession(WhiteboardRecord whiteboard);

    /**
     * Locates an Inkboard session by recipient JID.  
     *
     * \param to The recipient JID identifying the session to be located.
     * \return A pointer to the InkboardDocument associated with the Inkboard session,
     * or NULL if no such session exists.
     */
    InkboardDocument* getInkboardSession(Glib::ustring const& to);


    void operator=(XmppEventListener const& /*other*/)
	    {}

private:

    Pedro::PedroGui     gui;
    WhiteboardList      whiteboards;
    InvitationList      invitations;
    sigc::connection    CheckPendingInvitations;

    void    processWhiteboardEvent(Pedro::XmppEvent const& event);

    void    handleIncomingInvitation(Invitation invitation);

    bool    checkInvitationQueue();

    char*   createSessionId(int size);

};

SPDocument* makeInkboardDocument(int code, gchar const* rootname, 
    State::SessionType type, Glib::ustring const& to);

SPDesktop*  makeInkboardDesktop(SPDocument* doc);

}  // namespace Whiteboard

}  // namespace Inkscape

#endif  /* __SESSION_MANAGER_H__ */

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :