~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/jabber_whiteboard/message-aggregator.cpp

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
12
 
 
13
#include <glibmm.h>
 
14
#include "jabber_whiteboard/message-aggregator.h"
 
15
 
 
16
namespace Inkscape {
 
17
 
 
18
namespace Whiteboard {
 
19
 
 
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
        }
 
32
 
 
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
}
 
44
 
 
45
bool
 
46
MessageAggregator::addOne(Glib::ustring const& msg)
 
47
{
 
48
        return this->addOne(msg, this->_buf);
 
49
}
 
50
 
 
51
}
 
52
 
 
53
}
 
54
 
 
55
/*
 
56
  Local Variables:
 
57
  mode:c++
 
58
  c-file-style:"stroustrup"
 
59
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
60
  indent-tabs-mode:nil
 
61
  fill-column:99
 
62
  End:
 
63
*/
 
64
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :