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 #include <glibmm.h>
14 #include "jabber_whiteboard/message-aggregator.h"
16 namespace Inkscape {
18 namespace Whiteboard {
20 bool
21 MessageAggregator::addOne(Glib::ustring const& msg, Glib::ustring& buf)
22 {
23 // 1. If msg.bytes() > maximum size and the buffer is clear,
24 // then we have to send an oversize packet --
25 // we won't be able to deliver the message any other way.
26 // Add it to the buffer and return true. Any further attempt to
27 // aggregate a message will be handled by condition #2.
28 if (msg.bytes() > MessageAggregator::MAX_SIZE && buf.empty()) {
29 buf += msg;
30 return true;
31 }
33 // 2. If msg.bytes() + buf.bytes() > maximum size, return false.
34 // The user of this class is responsible for retrieving the aggregated message,
35 // doing something with it, clearing the buffer, and trying again.
36 // Otherwise, append the message to the buffer and return true.
37 if (msg.bytes() + buf.bytes() > MessageAggregator::MAX_SIZE) {
38 return false;
39 } else {
40 buf += msg;
41 return true;
42 }
43 }
45 bool
46 MessageAggregator::addOne(Glib::ustring const& msg)
47 {
48 return this->addOne(msg, this->_buf);
49 }
51 }
53 }
55 /*
56 Local Variables:
57 mode:c++
58 c-file-style:"stroustrup"
59 c-file-offsets:((innamespace . 0)(inline-open . 0))
60 indent-tabs-mode:nil
61 fill-column:99
62 End:
63 */
64 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :