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

drape_api.cpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e00a22b8f5526e26481fda8695eb9569be53075 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "drape_frontend/drape_api.hpp"
#include "drape_frontend/drape_engine.hpp"
#include "drape_frontend/message_subclasses.hpp"

namespace df
{

void DrapeApi::SetEngine(ref_ptr<DrapeEngine> engine)
{
  m_engine = engine;
}

void DrapeApi::AddLine(string const & id, DrapeApiLineData const & data)
{
  lock_guard<mutex> lock(m_mutex);

  if (m_engine == nullptr)
    return;

  auto it = m_lines.find(id);
  if (it != m_lines.end())
  {
    m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
                                              make_unique_dp<DrapeApiRemoveMessage>(id),
                                              MessagePriority::Normal);
  }

  m_lines[id] = data;

  TLines lines;
  lines.insert(make_pair(id, data));
  m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
                                            make_unique_dp<DrapeApiAddLinesMessage>(lines),
                                            MessagePriority::Normal);
}

void DrapeApi::RemoveLine(string const & id)
{
  lock_guard<mutex> lock(m_mutex);

  if (m_engine == nullptr)
    return;

  m_lines.erase(id);
  m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
                                            make_unique_dp<DrapeApiRemoveMessage>(id),
                                            MessagePriority::Normal);
}

void DrapeApi::Clear()
{
  lock_guard<mutex> lock(m_mutex);

  if (m_engine == nullptr)
    return;

  m_lines.clear();
  m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
                                            make_unique_dp<DrapeApiRemoveMessage>("", true /* remove all */),
                                            MessagePriority::Normal);
}

void DrapeApi::Invalidate()
{
  lock_guard<mutex> lock(m_mutex);

  if (m_engine == nullptr)
    return;

  m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
                                            make_unique_dp<DrapeApiRemoveMessage>("", true /* remove all */),
                                            MessagePriority::Normal);

  m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
                                            make_unique_dp<DrapeApiAddLinesMessage>(m_lines),
                                            MessagePriority::Normal);
}

} // namespace df