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

api.cpp « ugc - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ea6954324361f1ebafc0b6acd45293f62417469 (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
#include "ugc/api.hpp"

#include "platform/platform.hpp"

#include <utility>

using namespace std;
using namespace ugc;

namespace ugc
{
Api::Api(Index const & index) : m_storage(index), m_loader(index)
{
  m_thread.Push([this] { m_storage.Load(); });
}

void Api::GetUGC(FeatureID const & id, UGCCallback callback)
{
  m_thread.Push([=] { GetUGCImpl(id, callback); });
}

void Api::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
{
  m_thread.Push([=] { SetUGCUpdateImpl(id, ugc); });
}

void Api::GetUGCToSend(UGCJsonToSendCallback const & fn)
{
  m_thread.Push([fn, this] { GetUGCToSendImpl(fn); });
}

void Api::SendingCompleted()
{
  m_thread.Push([this] { SendingCompletedImpl(); });
}

void Api::SaveUGCOnDisk()
{
  m_thread.Push([this] { SaveUGCOnDiskImpl(); });
}

void Api::GetUGCImpl(FeatureID const & id, UGCCallback callback)
{
  if (!id.IsValid())
  {
    GetPlatform().RunOnGuiThread([callback] { callback({}, {}); });
    return;
  }

  auto const update = m_storage.GetUGCUpdate(id);
  auto const ugc = m_loader.GetUGC(id);

  GetPlatform().RunOnGuiThread([ugc, update, callback] { callback(ugc, update); });
}

void Api::SetUGCUpdateImpl(FeatureID const & id, UGCUpdate const & ugc)
{
  m_storage.SetUGCUpdate(id, ugc);
}

void Api::GetUGCToSendImpl(UGCJsonToSendCallback const & fn)
{
  auto json = m_storage.GetUGCToSend();
  fn(move(json));
}

void Api::SendingCompletedImpl()
{
  m_storage.MarkAllAsSynchronized();
}

void Api::SaveUGCOnDiskImpl()
{
  m_storage.SaveIndex();
}
}  // namespace ugc