diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-10-25 14:45:23 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-10-27 11:56:47 +0300 |
commit | bf4d27098b2610d93104d5b2347738e1f15d1476 (patch) | |
tree | b6a9b14bc53ef1ef215f281ea2c63b42887250f6 /drape_frontend/drape_api.cpp | |
parent | 5ebfedc13345cf679f1d341640e6a757d08d43e2 (diff) |
Added Drape API
Diffstat (limited to 'drape_frontend/drape_api.cpp')
-rw-r--r-- | drape_frontend/drape_api.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/drape_frontend/drape_api.cpp b/drape_frontend/drape_api.cpp new file mode 100644 index 0000000000..8e00a22b8f --- /dev/null +++ b/drape_frontend/drape_api.cpp @@ -0,0 +1,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 |