Welcome to mirror list, hosted at ThFree Co, Russian Federation.

message_acceptor.hpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d2e2f14e8616fd572296245edccdc6e0f0e2347b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include "drape_frontend/message_queue.hpp"

#include "drape/pointers.hpp"

#include "std/atomic.hpp"

namespace df
{

class Message;

class MessageAcceptor
{
protected:
  MessageAcceptor();
  virtual ~MessageAcceptor(){}

  virtual void AcceptMessage(ref_ptr<Message> message) = 0;

  /// Must be called by subclass on message target thread
  bool ProcessSingleMessage(bool waitForMessage = true);

  void CancelMessageWaiting();

  void CloseQueue();

  bool IsInInfinityWaiting() const;

#ifdef DEBUG_MESSAGE_QUEUE
  bool IsQueueEmpty() const;
  size_t GetQueueSize() const;
#endif

  using TFilterMessageFn = function<bool (ref_ptr<Message>)>;
  void EnableMessageFiltering(TFilterMessageFn needFilterMessageFn);
  void DisableMessageFiltering();

private:
  friend class ThreadsCommutator;

  void PostMessage(drape_ptr<Message> && message, MessagePriority priority);

  MessageQueue m_messageQueue;
  atomic<bool> m_infinityWaiting;
  TFilterMessageFn m_needFilterMessageFn;
};

} // namespace df