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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorДобрый Ээх <bukharaev@gmail.com>2016-10-07 17:17:03 +0300
committerДобрый Ээх <bukharaev@gmail.com>2016-10-13 21:25:22 +0300
commita65d86ebcf216bd0480c7f576d0eff60df44a160 (patch)
tree0ba4b8802b4d60179190523d327b2246966fc1b8 /tracking/connection.cpp
parenta8067e8826da51278fa78ce652b80cec2848536b (diff)
gps tracking reporter
Diffstat (limited to 'tracking/connection.cpp')
-rw-r--r--tracking/connection.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tracking/connection.cpp b/tracking/connection.cpp
new file mode 100644
index 0000000000..09a78a1f41
--- /dev/null
+++ b/tracking/connection.cpp
@@ -0,0 +1,44 @@
+#include "connection.hpp"
+
+#include "platform/socket.hpp"
+
+namespace
+{
+uint32_t constexpr kSocketTimeoutMs = 10000;
+} // namespace
+
+namespace tracking
+{
+// static
+const char Connection::kHost[] = "gps.host"; // TODO change to real host value
+uint16_t Connection::kPort = 666; // TODO change to real port value
+
+Connection::Connection(unique_ptr<platform::Socket> socket, string const & host, uint16_t port,
+ bool isHistorical)
+ : m_socket(move(socket)), m_host(host), m_port(port)
+{
+ ASSERT(m_socket.get() != nullptr, ());
+
+ m_socket->SetTimeout(kSocketTimeoutMs);
+}
+
+// TODO: implement handshake
+bool Connection::Reconnect()
+{
+ m_socket->Close();
+ return m_socket->Open(m_host, m_port);
+}
+
+// TODO: implement historical
+bool Connection::Send(boost::circular_buffer<DataPoint> const & points)
+{
+ ASSERT(m_buffer.empty(), ());
+
+ MemWriter<decltype(m_buffer)> writer(m_buffer);
+ coding::TrafficGPSEncoder::SerializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, writer,
+ points);
+ bool isSuccess = m_socket->Write(m_buffer.data(), m_buffer.size());
+ m_buffer.clear();
+ return isSuccess;
+}
+} // namespace tracking