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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include "ugc/api.hpp"
#include "indexer/feature_data.hpp"
#include "base/assert.hpp"
#include <utility>
using namespace std;
using namespace ugc;
namespace ugc
{
Api::Api(DataSource const & dataSource, NumberOfUnsynchronizedCallback const & callback)
: m_storage(dataSource), m_loader(dataSource)
{
m_thread.Push([this, callback] {
m_storage.Load();
callback(m_storage.GetNumberOfUnsynchronized());
});
}
void Api::GetUGC(FeatureID const & id, UGCCallbackUnsafe const & callback)
{
m_thread.Push([=] { GetUGCImpl(id, callback); });
}
void Api::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc,
OnResultCallback const & callback /* nullptr */)
{
m_thread.Push([=] {
auto const res = SetUGCUpdateImpl(id, ugc);
if (callback)
callback(res);
});
}
void Api::GetUGCToSend(UGCJsonToSendCallback const & callback)
{
m_thread.Push([callback, this] { GetUGCToSendImpl(callback); });
}
void Api::HasUGCForPlace(uint32_t bestType, m2::PointD const & point,
HasUGCForPlaceCallback const & callback)
{
m_thread.Push([=]() mutable
{
HasUGCForPlaceImpl(bestType, point, callback);
});
}
void Api::SendingCompleted()
{
m_thread.Push([this] { SendingCompletedImpl(); });
}
void Api::SaveUGCOnDisk()
{
m_thread.Push([this] { SaveUGCOnDiskImpl(); });
}
Loader & Api::GetLoader()
{
return m_loader;
}
void Api::GetUGCImpl(FeatureID const & id, UGCCallbackUnsafe const & callback)
{
CHECK(callback, ());
if (!id.IsValid())
{
callback({}, {});
return;
}
auto const update = m_storage.GetUGCUpdate(id);
auto const ugc = m_loader.GetUGC(id);
callback(ugc, update);
}
Storage::SettingResult Api::SetUGCUpdateImpl(FeatureID const & id, UGCUpdate const & ugc)
{
return m_storage.SetUGCUpdate(id, ugc);
}
void Api::GetUGCToSendImpl(UGCJsonToSendCallback const & callback)
{
CHECK(callback, ());
auto json = m_storage.GetUGCToSend();
callback(move(json), m_storage.GetNumberOfUnsynchronized());
}
void Api::HasUGCForPlaceImpl(uint32_t bestType, m2::PointD const & point,
HasUGCForPlaceCallback const & callback) const
{
callback(m_storage.HasUGCForPlace(bestType, point));
}
void Api::SendingCompletedImpl()
{
m_storage.MarkAllAsSynchronized();
}
void Api::SaveUGCOnDiskImpl()
{
m_storage.SaveIndex();
}
} // namespace ugc
|