Files
comaps/drape_frontend/message_queue.hpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

50 lines
1.2 KiB
C++

#pragma once
#include "drape_frontend/message.hpp"
#include "drape/drape_diagnostics.hpp"
#include "drape/pointers.hpp"
#include <condition_variable>
#include <deque>
#include <functional>
#include <mutex>
namespace df
{
class MessageQueue
{
public:
MessageQueue();
~MessageQueue();
// If the queue is empty then it returns nullptr or wait for a message.
drape_ptr<Message> PopMessage(bool waitForMessage);
void PushMessage(drape_ptr<Message> && message, MessagePriority priority);
void CancelWait();
void ClearQuery();
using FilterMessageFn = std::function<bool(ref_ptr<Message>)>;
void EnableMessageFiltering(FilterMessageFn && filter);
void DisableMessageFiltering();
void InstantFilter(FilterMessageFn && filter);
#ifdef DEBUG_MESSAGE_QUEUE
bool IsEmpty() const;
size_t GetSize() const;
#endif
private:
void FilterMessagesImpl();
void CancelWaitImpl();
mutable std::mutex m_mutex;
std::condition_variable m_condition;
bool m_isWaiting;
using TMessageNode = std::pair<drape_ptr<Message>, MessagePriority>;
std::deque<TMessageNode> m_messages;
std::deque<drape_ptr<Message>> m_lowPriorityMessages;
FilterMessageFn m_filter;
};
} // namespace df