[Libreoffice-commits] online.git: common/MessageQueue.cpp common/MessageQueue.hpp test/TileQueueTests.cpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Nov 16 08:06:39 UTC 2018
common/MessageQueue.cpp | 64 ++++++++++++++++++++++++------------------------
common/MessageQueue.hpp | 4 +--
test/TileQueueTests.cpp | 22 ++++++++--------
3 files changed, 45 insertions(+), 45 deletions(-)
New commits:
commit d52cf35418d1c8e80dafa2dba6048bf8a30d2f7b
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Nov 16 09:06:08 2018 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Nov 16 09:06:17 2018 +0100
MessageQueueBase: make members private
Change-Id: I65360bc23475b25b2c626ea75186e8863fc74b8f
diff --git a/common/MessageQueue.cpp b/common/MessageQueue.cpp
index a86bc7d59..0a473d0e4 100644
--- a/common/MessageQueue.cpp
+++ b/common/MessageQueue.cpp
@@ -31,10 +31,10 @@ void TileQueue::put_impl(const Payload& value)
if (firstToken == "canceltiles")
{
- LOG_TRC("Processing [" << msg << "]. Before canceltiles have " << _queue.size() << " in queue.");
+ LOG_TRC("Processing [" << msg << "]. Before canceltiles have " << getQueue().size() << " in queue.");
const std::string seqs = msg.substr(12);
StringTokenizer tokens(seqs, ",", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- _queue.erase(std::remove_if(_queue.begin(), _queue.end(),
+ getQueue().erase(std::remove_if(getQueue().begin(), getQueue().end(),
[&tokens](const Payload& v)
{
const std::string s(v.data(), v.size());
@@ -52,10 +52,10 @@ void TileQueue::put_impl(const Payload& value)
return false;
- }), _queue.end());
+ }), getQueue().end());
// Don't push canceltiles into the queue.
- LOG_TRC("After canceltiles have " << _queue.size() << " in queue.");
+ LOG_TRC("After canceltiles have " << getQueue().size() << " in queue.");
return;
}
else if (firstToken == "tilecombine")
@@ -113,14 +113,14 @@ void TileQueue::removeTileDuplicate(const std::string& tileMsg)
newMsgPos = tileMsg.size() - 1;
}
- for (size_t i = 0; i < _queue.size(); ++i)
+ for (size_t i = 0; i < getQueue().size(); ++i)
{
- auto& it = _queue[i];
+ auto& it = getQueue()[i];
if (it.size() > newMsgPos &&
strncmp(tileMsg.data(), it.data(), newMsgPos) == 0)
{
LOG_TRC("Remove duplicate tile request: " << std::string(it.data(), it.size()) << " -> " << tileMsg);
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
break;
}
}
@@ -210,9 +210,9 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
// we always travel the entire queue
size_t i = 0;
- while (i < _queue.size())
+ while (i < getQueue().size())
{
- auto& it = _queue[i];
+ auto& it = getQueue()[i];
std::vector<std::string> queuedTokens = LOOLProtocol::tokenize(it.data(), it.size());
if (queuedTokens.size() < 3)
@@ -250,7 +250,7 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
tokens[0] << " " << tokens[1] << " " << tokens[2] << " " << msgX << " " << msgY << " " << msgW << " " << msgH << " " << msgPart);
// remove from the queue
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
continue;
}
@@ -282,7 +282,7 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
performedMerge = true;
// remove from the queue
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
continue;
}
@@ -315,9 +315,9 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
return std::string();
// remove obsolete states of the same .uno: command
- for (size_t i = 0; i < _queue.size(); ++i)
+ for (size_t i = 0; i < getQueue().size(); ++i)
{
- auto& it = _queue[i];
+ auto& it = getQueue()[i];
std::vector<std::string> queuedTokens = LOOLProtocol::tokenize(it.data(), it.size());
if (queuedTokens.size() < 4)
@@ -335,7 +335,7 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
if (unoCommand == queuedUnoCommand)
{
LOG_TRC("Remove obsolete uno command: " << std::string(it.data(), it.size()) << " -> " << callbackMsg);
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
break;
}
}
@@ -357,9 +357,9 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
viewId = extractViewId(callbackMsg, tokens);
}
- for (size_t i = 0; i < _queue.size(); ++i)
+ for (size_t i = 0; i < getQueue().size(); ++i)
{
- auto& it = _queue[i];
+ auto& it = getQueue()[i];
// skip non-callbacks quickly
if (!LOOLProtocol::matchPrefix("callback", it))
@@ -372,7 +372,7 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
if (!isViewCallback && (queuedTokens[1] == tokens[1] && queuedTokens[2] == tokens[2]))
{
LOG_TRC("Remove obsolete callback: " << std::string(it.data(), it.size()) << " -> " << callbackMsg);
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
break;
}
else if (isViewCallback && (queuedTokens[1] == tokens[1] && queuedTokens[2] == tokens[2]))
@@ -385,7 +385,7 @@ std::string TileQueue::removeCallbackDuplicate(const std::string& callbackMsg)
if (viewId == queuedViewId)
{
LOG_TRC("Remove obsolete view callback: " << std::string(it.data(), it.size()) << " -> " << callbackMsg);
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
break;
}
}
@@ -412,9 +412,9 @@ int TileQueue::priority(const std::string& tileMsg)
void TileQueue::deprioritizePreviews()
{
- for (size_t i = 0; i < _queue.size(); ++i)
+ for (size_t i = 0; i < getQueue().size(); ++i)
{
- const Payload front = _queue.front();
+ const Payload front = getQueue().front();
const std::string message(front.data(), front.size());
// stop at the first non-tile or non-'id' (preview) message
@@ -425,16 +425,16 @@ void TileQueue::deprioritizePreviews()
break;
}
- _queue.erase(_queue.begin());
- _queue.push_back(front);
+ getQueue().erase(getQueue().begin());
+ getQueue().push_back(front);
}
}
TileQueue::Payload TileQueue::get_impl()
{
- LOG_TRC("MessageQueue depth: " << _queue.size());
+ LOG_TRC("MessageQueue depth: " << getQueue().size());
- const Payload front = _queue.front();
+ const Payload front = getQueue().front();
std::string msg(front.data(), front.size());
@@ -445,7 +445,7 @@ TileQueue::Payload TileQueue::get_impl()
{
// Don't combine non-tiles or tiles with id.
LOG_TRC("MessageQueue res: " << msg);
- _queue.erase(_queue.begin());
+ getQueue().erase(getQueue().begin());
// de-prioritize the other tiles with id - usually the previews in
// Impress
@@ -459,9 +459,9 @@ TileQueue::Payload TileQueue::get_impl()
// position, otherwise handle the one that is at the front
int prioritized = 0;
int prioritySoFar = -1;
- for (size_t i = 0; i < _queue.size(); ++i)
+ for (size_t i = 0; i < getQueue().size(); ++i)
{
- auto& it = _queue[i];
+ auto& it = getQueue()[i];
const std::string prio(it.data(), it.size());
// avoid starving - stop the search when we reach a non-tile,
@@ -488,15 +488,15 @@ TileQueue::Payload TileQueue::get_impl()
}
}
- _queue.erase(_queue.begin() + prioritized);
+ getQueue().erase(getQueue().begin() + prioritized);
std::vector<TileDesc> tiles;
tiles.emplace_back(TileDesc::parse(msg));
// Combine as many tiles as possible with the top one.
- for (size_t i = 0; i < _queue.size(); )
+ for (size_t i = 0; i < getQueue().size(); )
{
- auto& it = _queue[i];
+ auto& it = getQueue()[i];
msg = std::string(it.data(), it.size());
if (!LOOLProtocol::matchPrefix("tile", msg) ||
LOOLProtocol::getTokenStringFromMessage(msg, "id", id))
@@ -513,7 +513,7 @@ TileQueue::Payload TileQueue::get_impl()
if (tiles[0].onSameRow(tile2))
{
tiles.emplace_back(tile2);
- _queue.erase(_queue.begin() + i);
+ getQueue().erase(getQueue().begin() + i);
}
else
{
@@ -521,7 +521,7 @@ TileQueue::Payload TileQueue::get_impl()
}
}
- LOG_TRC("Combined " << tiles.size() << " tiles, leaving " << _queue.size() << " in queue.");
+ LOG_TRC("Combined " << tiles.size() << " tiles, leaving " << getQueue().size() << " in queue.");
if (tiles.size() == 1)
{
diff --git a/common/MessageQueue.hpp b/common/MessageQueue.hpp
index 16711adbd..d0a7e8054 100644
--- a/common/MessageQueue.hpp
+++ b/common/MessageQueue.hpp
@@ -119,10 +119,10 @@ protected:
/// Get the queue lock when accessing members of derived classes.
std::unique_lock<std::mutex> getLock() { return std::unique_lock<std::mutex>(_mutex); }
-protected:
- std::vector<Payload> _queue;
+ std::vector<Payload>& getQueue() { return _queue; }
private:
+ std::vector<Payload> _queue;
mutable std::mutex _mutex;
std::condition_variable _cv;
diff --git a/test/TileQueueTests.cpp b/test/TileQueueTests.cpp
index 8c0cbd6d3..6ca1bf22f 100644
--- a/test/TileQueueTests.cpp
+++ b/test/TileQueueTests.cpp
@@ -163,7 +163,7 @@ void TileQueueTests::testTileRecombining()
queue.put("tilecombine part=0 width=256 height=256 tileposx=0,3840 tileposy=0,0 tilewidth=3840 tileheight=3840");
// the tilecombine's get merged, resulting in 3 "tile" messages
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(queue.getQueue().size()));
// but when we later extract that, it is just one "tilecombine" message
std::string message(payloadAsString(queue.get()));
@@ -171,7 +171,7 @@ void TileQueueTests::testTileRecombining()
CPPUNIT_ASSERT_EQUAL(std::string("tilecombine part=0 width=256 height=256 tileposx=7680,0,3840 tileposy=0,0,0 imgsize=0,0,0 tilewidth=3840 tileheight=3840 ver=-1,-1,-1 oldwid=0,0,0 wid=0,0,0"), message);
// and nothing remains in the queue
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
}
void TileQueueTests::testViewOrder()
@@ -197,7 +197,7 @@ void TileQueueTests::testViewOrder()
for (auto &tile : tiles)
queue.put(tile);
- CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(queue.getQueue().size()));
// should result in the 3, 2, 1, 0 order of the tiles thanks to the cursor
// positions
@@ -229,7 +229,7 @@ void TileQueueTests::testPreviewsDeprioritization()
}
// stays empty after all is done
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
// re-ordering case - put previews and normal tiles to the queue and get
// everything back again but this time the tiles have to interleave with
@@ -256,7 +256,7 @@ void TileQueueTests::testPreviewsDeprioritization()
CPPUNIT_ASSERT_EQUAL(previews[3], payloadAsString(queue.get()));
// stays empty after all is done
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
// cursor positioning case - the cursor position should not prioritize the
// previews
@@ -269,7 +269,7 @@ void TileQueueTests::testPreviewsDeprioritization()
CPPUNIT_ASSERT_EQUAL(previews[0], payloadAsString(queue.get()));
// stays empty after all is done
- CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(queue.getQueue().size()));
}
void TileQueueTests::testSenderQueue()
@@ -428,7 +428,7 @@ void TileQueueTests::testCallbackInvalidation()
queue.put("callback all 0 284, 1418, 11105, 275, 0");
queue.put("callback all 0 4299, 1418, 7090, 275, 0");
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
CPPUNIT_ASSERT_EQUAL(std::string("callback all 0 284, 1418, 11105, 275, 0"), payloadAsString(queue.get()));
@@ -438,11 +438,11 @@ void TileQueueTests::testCallbackInvalidation()
queue.put("callback all 0 4299, 10418, 7090, 275, 0");
queue.put("callback all 0 4299, 20418, 7090, 275, 0");
- CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(4, static_cast<int>(queue.getQueue().size()));
queue.put("callback all 0 EMPTY, 0");
- CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(queue.getQueue().size()));
CPPUNIT_ASSERT_EQUAL(std::string("callback all 0 4299, 1418, 7090, 275, 1"), payloadAsString(queue.get()));
CPPUNIT_ASSERT_EQUAL(std::string("callback all 0 EMPTY, 0"), payloadAsString(queue.get()));
}
@@ -455,7 +455,7 @@ void TileQueueTests::testCallbackIndicatorValue()
queue.put("callback all 10 25");
queue.put("callback all 10 50");
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
CPPUNIT_ASSERT_EQUAL(std::string("callback all 10 50"), payloadAsString(queue.get()));
}
@@ -467,7 +467,7 @@ void TileQueueTests::testCallbackPageSize()
queue.put("callback all 13 12474, 188626");
queue.put("callback all 13 12474, 205748");
- CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(queue._queue.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(queue.getQueue().size()));
CPPUNIT_ASSERT_EQUAL(std::string("callback all 13 12474, 205748"), payloadAsString(queue.get()));
}
More information about the Libreoffice-commits
mailing list