Code

applied JID patch by Alexander Darovsky
[inkscape.git] / src / jabber_whiteboard / message-aggregator.h
1 /**
2  * Aggregates individual serialized XML::Events into larger packages 
3  * for more efficient delivery
4  *
5  * Authors:
6  * David Yip <yipdw@rose-hulman.edu>
7  *
8  * Copyright (c) 2005 Authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #ifndef __WHITEBOARD_MESSAGE_AGGREGATOR_H__
14 #define __WHITEBOARD_MESSAGE_AGGREGATOR_H__
16 #include <glibmm.h>
18 namespace Inkscape {
20 namespace Whiteboard {
22 /**
23  * Aggregates individual serialized XML::Events into larger messages for increased
24  * efficiency.
25  *
26  * \see Inkscape::Whiteboard::Serializer
27  */
28 class MessageAggregator {
29 public:
30         // TODO: This should be user-configurable; perhaps an option in Inkscape Preferences...
31         /// Maximum size of aggregates in kilobytes; ULONG_MAX = no limit.
32         static unsigned int const MAX_SIZE = 16384;
34         MessageAggregator() { }
35         ~MessageAggregator() { }
37         /**
38          * Return the instance of this class.
39          *
40          * \return MessageAggregator instance.
41          */
42         static MessageAggregator& instance()
43         {
44                 static MessageAggregator singleton;
45                 return singleton;
46         }
48         /**
49          * Adds one message to the aggregate 
50          * using a user-provided buffer.  Returns true if more messages can be
51          * added to the buffer; false otherwise.
52          *
53          * \param msg The message to add to the aggregate.
54          * \param buf The aggregate buffer.
55          * \return Whether or not more messages can be added to the buffer.
56          */
57         bool addOne(Glib::ustring const& msg, Glib::ustring& buf);
59         /**
60          * Adds one message to the aggregate using the internal buffer.  
61          * Note that since this class is designed to be a singleton class, usage of the internal
62          * buffer is not thread-safe.  Use the above method if this matters to you
63          * (it currently shouldn't matter, but in future...)
64          *
65          * Also note that usage of the internal buffer means that you will have to manually
66          * clear the internal buffer; use reset() for that.
67          *
68          * \param msg The message to add to the aggregate.
69          * \return Whether or not more messages can be added to the buffer.
70          */
71         bool addOne(Glib::ustring const& msg);
73         /**
74          * Return the aggregate message.
75          *
76          * Because this method returns a reference to a string, it is not safe for use 
77          * across multiple invocations of this Deserializer.
78          *
79          * \return A reference to the aggregate message.
80          */
81         Glib::ustring const& getAggregate()
82         {
83                 return this->_buf;
84         }
86         /**
87          * Return the aggregate message.
88          *
89          * \return The aggregate message.
90          */
91         Glib::ustring const getAggregateCopy()
92         {
93                 return this->_buf;
94         }
96         /**
97          * Return the aggregate message and clear the internal buffer.
98          *
99          * \return The aggregate message.
100          */
101         Glib::ustring const detachAggregate()
102         {
103                 Glib::ustring ret = this->_buf;
104                 this->_buf.clear();
105                 return ret;
106         }
108         /**
109          * Clear the internal buffer.
110          */
111         void reset()
112         {
113                 this->_buf.clear();
114         }
116 private:
117         Glib::ustring _buf;
118 };
124 #endif
126 /*
127   Local Variables:
128   mode:c++
129   c-file-style:"stroustrup"
130   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
131   indent-tabs-mode:nil
132   fill-column:99
133   End:
134 */
135 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :