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 to assume
77 * that its contents will remain untouched across two calls to this MessageAggregator.
78 * If you require that guarantee, make a copy.
79 *
80 * \return A reference to the aggregate message.
81 */
82 Glib::ustring const& getAggregate()
83 {
84 return this->_buf;
85 }
87 /**
88 * Return the aggregate message.
89 *
90 * \return The aggregate message.
91 */
92 Glib::ustring const getAggregateCopy()
93 {
94 return this->_buf;
95 }
97 /**
98 * Return the aggregate message and clear the internal buffer.
99 *
100 * \return The aggregate message.
101 */
102 Glib::ustring const detachAggregate()
103 {
104 Glib::ustring ret = this->_buf;
105 this->_buf.clear();
106 return ret;
107 }
109 /**
110 * Clear the internal buffer.
111 */
112 void reset()
113 {
114 this->_buf.clear();
115 }
117 private:
118 Glib::ustring _buf;
119 };
121 }
123 }
125 #endif
127 /*
128 Local Variables:
129 mode:c++
130 c-file-style:"stroustrup"
131 c-file-offsets:((innamespace . 0)(inline-open . 0))
132 indent-tabs-mode:nil
133 fill-column:99
134 End:
135 */
136 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :