Code

applied JID patch by Alexander Darovsky
[inkscape.git] / src / jabber_whiteboard / message-queue.h
1 /**
2  * Whiteboard message queue 
3  * 
4  * Authors:
5  * David Yip <yipdw@rose-hulman.edu>
6  *
7  * Copyright (c) 2005 Authors
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifndef __WHITEBOARD_MESSAGE_QUEUE_H__
13 #define __WHITEBOARD_MESSAGE_QUEUE_H__
15 #include <list>
16 #include <map>
18 #include "gc-alloc.h"
20 #include "gc-managed.h"
22 #include "util/list-container.h"
24 namespace Inkscape {
26 namespace Whiteboard {
28 class SessionManager;
29 class MessageNode;
31 /// Definition of the basic message node queue
32 typedef std::list< MessageNode*, GC::Alloc< MessageNode*, GC::MANUAL > > MessageQueueBuffer;
34 /**
35  * MessageQueue interface.
36  *
37  * A message queue is used to queue up document change messages for sending and receiving.
38  *
39  * Message queues exist to allow us to send/process messages at a given rate rather than
40  * immediately: this allows us to avoid flooding Jabber servers and clients.
41  *
42  * Only one message queue should be created per sender.  Message queues store MessageNodes.
43  *
44  * \see Inkscape::Whiteboard::MessageNode
45  */
46 class MessageQueue {
47 public:
48         /**
49          * Constructor.
50          *
51          * \param sm The SessionManager to associate this MessageQueue with. 
52          */
53         MessageQueue(SessionManager *sm);
54         virtual ~MessageQueue();
56         /**
57          * Retrieve the MessageNode at the front of the queue.
58          */
59         MessageNode* first();
61         /**
62          * Remove the element at the front of the queue. 
63          */
64         void popFront();
66         /**
67          * Get the size of the queue.
68          *
69          * \return The size of the queue.
70          */
71         unsigned int size();
73         /**
74          * Returns whether or not the queue is empty.
75          *
76          * \return Whether or not the queue is empty.
77          */
78         bool empty();
80         /**
81          * Clear the queue.
82          */
83         void clear();
85         /**
86          * The insertion method.  The insertion procedure must be defined
87          * by a subclass.
88          *
89          * \param msg The MessageNode to insert.
90          */
91         virtual void insert(MessageNode* msg) = 0;
93 protected:
94         /**
95          * Implementation of the queue.
96          */
97         MessageQueueBuffer _queue;
99         /**
100          * Pointer to SessionManager.
101          */
102         SessionManager* _sm;
103 };
106 /**
107  * MessageQueue subclass designed to queue up received messages.
108  * Received messages are dispatched for processing on a periodic basis by a timeout.
109  *
110  * \see Inkscape::Whiteboard::Callbacks::dispatchReceiveQueue
111  */
112 class ReceiveMessageQueue : public MessageQueue, public GC::Managed<> {
113 public:
114         ReceiveMessageQueue(SessionManager* sm);
116         /**
117          * Insert a message into the queue.  
118          * Late messages (out-of-sequence messages) will be discarded.
119          *
120          * \param msg The message node to insert.
121          */
122         void insert(MessageNode* msg);
124         /**
125          * Insert a message into the deferred queue.
126          * The deferred message queue is used for messages that are not discarded,
127          * but cannot yet be processed due to missing dependencies.
128          *
129          * \param msg The message node to insert.
130          */
131         void insertDeferred(MessageNode* msg);
133         /**
134          * Update the latest processed packet count for this message queue.
135          *
136          * \param seq The sequence number of the latest processed packet.
137          */
138         void setLatestProcessedPacket(unsigned int seq);
139 private:
140         MessageQueueBuffer _deferred;
141         unsigned int _latest;
142 };
144 /**
145  * MessageQueue subclass designed to queue up messages for sending.
146  * Messages in this queue are dispatched on a periodic basis by a timeout.
147  *
148  * \see Inkscape::Whiteboard::Callbacks::dispatchSendQueue
149  */
150 class SendMessageQueue : public MessageQueue {
151 public:
152         SendMessageQueue(SessionManager* sm);
154         /**
155          * Insert a message into the queue.  
156          *
157          * \param msg The message node to insert.
158          */
159         void insert(MessageNode* msg);
160 };
166 #endif
168 /*
169   Local Variables:
170   mode:c++
171   c-file-style:"stroustrup"
172   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
173   indent-tabs-mode:nil
174   fill-column:99
175   End:
176 */
177 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :