MessageQueue: squash into TileQueue.
Avoids unhelpful virtual methods which are not used anywhere, simplifies several code-paths, improves readability, and perhaps performance. Signed-off-by: Michael Meeks <michael.meeks@collabora.com> Change-Id: I7528fab77698546545bf81d7ccacdda9a0002833private/caolan/emplace_back
parent
466c31d59a
commit
aacc957f23
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
void TileQueue::put_impl(const Payload& value)
|
void TileQueue::put_impl(const Payload& value)
|
||||||
{
|
{
|
||||||
|
StringVector tokens = StringVector::tokenize(value.data(), value.size());
|
||||||
|
|
||||||
const std::string firstToken = COOLProtocol::getFirstToken(value);
|
const std::string firstToken = COOLProtocol::getFirstToken(value);
|
||||||
|
|
||||||
if (firstToken == "tilecombine")
|
if (firstToken == "tilecombine")
|
||||||
|
@ -40,34 +42,42 @@ void TileQueue::put_impl(const Payload& value)
|
||||||
|
|
||||||
removeTileDuplicate(newMsg);
|
removeTileDuplicate(newMsg);
|
||||||
|
|
||||||
MessageQueue::put_impl(Payload(newMsg.data(), newMsg.data() + newMsg.size()));
|
_queue.emplace_back(newMsg.data(), newMsg.data() + newMsg.size());
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (firstToken == "tile")
|
else if (firstToken == "tile")
|
||||||
{
|
{
|
||||||
removeTileDuplicate(std::string(value.data(), value.size()));
|
removeTileDuplicate(std::string(value.data(), value.size()));
|
||||||
|
|
||||||
MessageQueue::put_impl(value);
|
_queue.push_back(value);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (firstToken == "callback")
|
else if (firstToken == "callback")
|
||||||
{
|
{
|
||||||
const std::string newMsg = removeCallbackDuplicate(std::string(value.data(), value.size()));
|
const std::string newMsg = removeCallbackDuplicate(std::string(value.data(), value.size()));
|
||||||
|
|
||||||
if (newMsg.empty())
|
if (newMsg.empty())
|
||||||
{
|
_queue.push_back(value);
|
||||||
MessageQueue::put_impl(value);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
_queue.emplace_back(newMsg.data(), newMsg.data() + newMsg.size());
|
||||||
MessageQueue::put_impl(Payload(newMsg.data(), newMsg.data() + newMsg.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if (tokens.equals(1, "textinput"))
|
||||||
MessageQueue::put_impl(value);
|
{
|
||||||
|
const std::string newMsg = combineTextInput(tokens);
|
||||||
|
if (!newMsg.empty())
|
||||||
|
_queue.emplace_back(newMsg.data(), newMsg.data() + newMsg.size());
|
||||||
|
else
|
||||||
|
_queue.emplace_back(value);
|
||||||
|
}
|
||||||
|
else if (tokens.equals(1, "removetextcontext"))
|
||||||
|
{
|
||||||
|
const std::string newMsg = combineRemoveText(tokens);
|
||||||
|
if (!newMsg.empty())
|
||||||
|
_queue.emplace_back(newMsg.data(), newMsg.data() + newMsg.size());
|
||||||
|
else
|
||||||
|
_queue.emplace_back(value);
|
||||||
|
}
|
||||||
|
else // not so special
|
||||||
|
_queue.emplace_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileQueue::removeTileDuplicate(const std::string& tileMsg)
|
void TileQueue::removeTileDuplicate(const std::string& tileMsg)
|
||||||
|
@ -656,11 +666,6 @@ void TileQueue::dumpState(std::ostream& oss)
|
||||||
}
|
}
|
||||||
oss << "]\n";
|
oss << "]\n";
|
||||||
|
|
||||||
MessageQueue::dumpState(oss);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MessageQueue::dumpState(std::ostream& oss)
|
|
||||||
{
|
|
||||||
oss << "\tQueue size: " << _queue.size() << "\n";
|
oss << "\tQueue size: " << _queue.size() << "\n";
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (Payload &it : _queue)
|
for (Payload &it : _queue)
|
||||||
|
|
|
@ -21,23 +21,25 @@
|
||||||
#include "Log.hpp"
|
#include "Log.hpp"
|
||||||
#include "Protocol.hpp"
|
#include "Protocol.hpp"
|
||||||
|
|
||||||
/// Message queue (FIFO).
|
/// Queue for handling the Kit's messaging needs
|
||||||
class MessageQueue
|
class TileQueue
|
||||||
{
|
{
|
||||||
|
friend class TileQueueTests;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::vector<char> Payload;
|
typedef std::vector<char> Payload;
|
||||||
|
|
||||||
MessageQueue()
|
TileQueue()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MessageQueue()
|
virtual ~TileQueue()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageQueue(const MessageQueue&) = delete;
|
TileQueue(const TileQueue&) = delete;
|
||||||
MessageQueue& operator=(const MessageQueue&) = delete;
|
TileQueue& operator=(const TileQueue&) = delete;
|
||||||
|
|
||||||
/// insert the message.
|
/// insert the message.
|
||||||
void put(const Payload& value)
|
void put(const Payload& value)
|
||||||
|
@ -85,46 +87,19 @@ public:
|
||||||
/// Removal of all the pending messages.
|
/// Removal of all the pending messages.
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
clear_impl();
|
_queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dumpState(std::ostream& oss);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void put_impl(const Payload& value)
|
void put_impl(const Payload& value);
|
||||||
{
|
Payload get_impl();
|
||||||
StringVector tokens = StringVector::tokenize(value.data(), value.size());
|
/* {
|
||||||
if (tokens.equals(1, "textinput"))
|
|
||||||
{
|
|
||||||
const std::string newMsg = combineTextInput(tokens);
|
|
||||||
if (!newMsg.empty())
|
|
||||||
{
|
|
||||||
_queue.push_back(Payload(newMsg.data(), newMsg.data() + newMsg.size()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (tokens.equals(1, "removetextcontext"))
|
|
||||||
{
|
|
||||||
const std::string newMsg = combineRemoveText(tokens);
|
|
||||||
if (!newMsg.empty())
|
|
||||||
{
|
|
||||||
_queue.push_back(Payload(newMsg.data(), newMsg.data() + newMsg.size()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_queue.emplace_back(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Payload get_impl()
|
|
||||||
{
|
|
||||||
Payload result = _queue.front();
|
Payload result = _queue.front();
|
||||||
_queue.erase(_queue.begin());
|
_queue.erase(_queue.begin());
|
||||||
return result;
|
return result;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void clear_impl()
|
|
||||||
{
|
|
||||||
_queue.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Payload>& getQueue() { return _queue; }
|
std::vector<Payload>& getQueue() { return _queue; }
|
||||||
|
|
||||||
|
@ -254,17 +229,6 @@ protected:
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpState(std::ostream& oss);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<Payload> _queue;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// MessageQueue specialized for priority handling of tiles.
|
|
||||||
class TileQueue : public MessageQueue
|
|
||||||
{
|
|
||||||
friend class TileQueueTests;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class CursorPosition
|
class CursorPosition
|
||||||
{
|
{
|
||||||
|
@ -330,13 +294,6 @@ public:
|
||||||
_cursorPositions.erase(viewId);
|
_cursorPositions.erase(viewId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpState(std::ostream& oss);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void put_impl(const Payload& value) override;
|
|
||||||
|
|
||||||
virtual Payload get_impl() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Search the queue for a duplicate tile and remove it (if present).
|
/// Search the queue for a duplicate tile and remove it (if present).
|
||||||
void removeTileDuplicate(const std::string& tileMsg);
|
void removeTileDuplicate(const std::string& tileMsg);
|
||||||
|
@ -359,6 +316,9 @@ private:
|
||||||
int priority(const std::string& tileMsg);
|
int priority(const std::string& tileMsg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// The underlying queue
|
||||||
|
std::vector<Payload> _queue;
|
||||||
|
|
||||||
std::map<int, CursorPosition> _cursorPositions;
|
std::map<int, CursorPosition> _cursorPositions;
|
||||||
|
|
||||||
/// Check the views in the order of how the editing (cursor movement) has
|
/// Check the views in the order of how the editing (cursor movement) has
|
||||||
|
|
Loading…
Reference in New Issue