Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -71,9 +71,8 @@ std::vector<std::string> FilesAccumulator::PrepareArchives(std::string const & p
{
if (it.second.m_files.empty())
continue;
std::string const archivePath =
base::JoinPath(path, base::GetNameFromFullPathWithoutExt(it.second.m_files[0]) +
ARCHIVE_TRACKS_ZIPPED_FILE_EXTENSION);
std::string const archivePath = base::JoinPath(
path, base::GetNameFromFullPathWithoutExt(it.second.m_files[0]) + ARCHIVE_TRACKS_ZIPPED_FILE_EXTENSION);
if (CreateZipFromFiles(it.second.m_files, archivePath, CompressionLevel::NoCompression))
archives.emplace_back(archivePath);
@@ -89,10 +88,8 @@ std::vector<std::string> FilesAccumulator::PrepareArchives(std::string const & p
void FilesAccumulator::DeleteProcessedFiles()
{
for (auto const & it : m_filesByType)
{
for (auto const & file : it.second.m_files)
base::DeleteFileX(file);
}
}
std::string GetArchiveFilename(uint8_t protocolVersion, std::chrono::seconds timestamp,
@@ -101,9 +98,8 @@ std::string GetArchiveFilename(uint8_t protocolVersion, std::chrono::seconds tim
std::string filename;
size_t constexpr kTrackFilenameSize = 20;
filename.reserve(kTrackFilenameSize); // All filename parts have fixed length.
filename = std::to_string(protocolVersion) + kDelimiter + std::to_string(timestamp.count()) +
kDelimiter + std::to_string(static_cast<uint8_t>(trackType)) +
ARCHIVE_TRACKS_FILE_EXTENSION;
filename = std::to_string(protocolVersion) + kDelimiter + std::to_string(timestamp.count()) + kDelimiter +
std::to_string(static_cast<uint8_t>(trackType)) + ARCHIVE_TRACKS_FILE_EXTENSION;
CHECK_EQUAL(filename.size(), kTrackFilenameSize, ());
return filename;
}
@@ -123,10 +119,8 @@ FileInfo ParseArchiveFilename(std::string const & fileName)
{
FileInfo res;
res.m_protocolVersion = static_cast<uint32_t>(std::stoul(metaData.substr(0, indexFirstDelim)));
res.m_timestamp =
std::stoul(metaData.substr(indexFirstDelim + 1, indexLastDelim - indexFirstDelim - 1));
res.m_trackType =
static_cast<routing::RouterType>(std::stoul(metaData.substr(indexLastDelim + 1)));
res.m_timestamp = std::stoul(metaData.substr(indexFirstDelim + 1, indexLastDelim - indexFirstDelim - 1));
res.m_trackType = static_cast<routing::RouterType>(std::stoul(metaData.substr(indexLastDelim + 1)));
return res;
}
catch (std::exception const & e)

View File

@@ -41,16 +41,16 @@ ArchivalManager::ArchivalManager(std::string const & url)
: m_url(url)
, m_tracksDir(GetTracksDirectory())
, m_timestampFile(GetTimestampFile(m_tracksDir))
{}
void ArchivalManager::SetSettings(ArchivingSettings const & settings)
{
m_settings = settings;
}
void ArchivalManager::SetSettings(ArchivingSettings const & settings) { m_settings = settings; }
std::optional<FileWriter> ArchivalManager::GetFileWriter(
routing::RouterType const & trackType) const
std::optional<FileWriter> ArchivalManager::GetFileWriter(routing::RouterType const & trackType) const
{
std::string const fileName =
archival_file::GetArchiveFilename(m_settings.m_version, GetTimestamp(), trackType);
std::string const fileName = archival_file::GetArchiveFilename(m_settings.m_version, GetTimestamp(), trackType);
try
{
return std::optional<FileWriter>(base::JoinPath(m_tracksDir, fileName));
@@ -71,10 +71,12 @@ bool ArchivalManager::CreateTracksDir() const
return true;
}
size_t ArchivalManager::IntervalBetweenDumpsSeconds() { return m_settings.m_dumpIntervalSeconds; }
size_t ArchivalManager::IntervalBetweenDumpsSeconds()
{
return m_settings.m_dumpIntervalSeconds;
}
std::vector<std::string> ArchivalManager::GetFilesOrderedByCreation(
std::string const & extension) const
std::vector<std::string> ArchivalManager::GetFilesOrderedByCreation(std::string const & extension) const
{
Platform::FilesList files;
Platform::GetFilesByExt(m_tracksDir, extension, files);
@@ -175,10 +177,8 @@ void ArchivalManager::DeleteOldDataByExtension(std::string const & extension) co
auto const files = GetFilesOrderedByCreation(extension);
auto const maxCount = GetMaxSavedFilesCount(extension);
if (files.size() > maxCount)
{
for (size_t i = 0; i < files.size() - maxCount; ++i)
base::DeleteFileX(files[i]);
}
}
void ArchivalManager::WriteTimestamp(std::string const & filePath)

View File

@@ -21,8 +21,7 @@ ArchivalReporter::ArchivalReporter(std::string const & host)
, m_manager(host)
, m_isAlive(true)
, m_threadDump([this] { Run(); })
{
}
{}
ArchivalReporter::~ArchivalReporter()
{

View File

@@ -20,29 +20,27 @@ Limits GetLimits(bool isDelta)
}
return {ms::LatLon::kMinLat, ms::LatLon::kMaxLat, ms::LatLon::kMinLon, ms::LatLon::kMaxLon};
}
} // namespace helpers
} // namespace helpers
Packet::Packet() : m_lat(0.0), m_lon(0.0), m_timestamp(0) {}
Packet::Packet(location::GpsInfo const & info)
: m_lat(info.m_latitude), m_lon(info.m_longitude), m_timestamp(info.m_timestamp)
{
}
: m_lat(info.m_latitude)
, m_lon(info.m_longitude)
, m_timestamp(info.m_timestamp)
{}
Packet::Packet(double lat, double lon, uint32_t timestamp)
: m_lat(lat), m_lon(lon), m_timestamp(timestamp)
{
}
Packet::Packet(double lat, double lon, uint32_t timestamp) : m_lat(lat), m_lon(lon), m_timestamp(timestamp) {}
PacketCar::PacketCar() : m_speedGroup(traffic::SpeedGroup::Unknown) {}
PacketCar::PacketCar(location::GpsInfo const & info, traffic::SpeedGroup const & speedGroup)
: Packet(info), m_speedGroup(speedGroup)
{
}
: Packet(info)
, m_speedGroup(speedGroup)
{}
PacketCar::PacketCar(double lat, double lon, uint32_t timestamp, traffic::SpeedGroup speed)
: Packet(lat, lon, timestamp), m_speedGroup(speed)
{
}
: Packet(lat, lon, timestamp)
, m_speedGroup(speed)
{}
} // namespace tracking

View File

@@ -29,7 +29,6 @@
#pragma clang diagnostic pop
#endif
namespace tracking
{
namespace helpers
@@ -51,7 +50,7 @@ struct Limits
};
Limits GetLimits(bool isDelta);
} // namespace helpers
} // namespace helpers
struct Packet
{
@@ -100,8 +99,7 @@ private:
// Abstract packet traits.
template <typename Pack>
struct TraitsPacket
{
};
{};
template <>
struct TraitsPacket<Packet>
@@ -123,10 +121,8 @@ struct TraitsPacket<Packet>
{
auto const lim = helpers::GetLimits(isDelta);
double const lat =
Uint32ToDouble(ReadVarUint<uint32_t>(src), lim.m_minLat, lim.m_maxLat, kCoordBits);
double const lon =
Uint32ToDouble(ReadVarUint<uint32_t>(src), lim.m_minLon, lim.m_maxLon, kCoordBits);
double const lat = Uint32ToDouble(ReadVarUint<uint32_t>(src), lim.m_minLat, lim.m_maxLat, kCoordBits);
double const lon = Uint32ToDouble(ReadVarUint<uint32_t>(src), lim.m_minLon, lim.m_maxLon, kCoordBits);
uint32_t const timestamp = ReadVarUint<uint32_t>(src);
return Packet(lat, lon, timestamp);
}
@@ -147,10 +143,7 @@ struct TraitsPacket<Packet>
return Packet(lat, lon, timestamp);
}
static traffic::SpeedGroup GetSpeedGroup(Packet const & packet)
{
return traffic::SpeedGroup::Unknown;
}
static traffic::SpeedGroup GetSpeedGroup(Packet const & packet) { return traffic::SpeedGroup::Unknown; }
};
template <>
@@ -160,8 +153,7 @@ struct TraitsPacket<PacketCar>
static void Write(Writer & writer, PacketCar const & packet, bool isDelta)
{
TraitsPacket<Packet>::Write(writer, packet, isDelta);
static_assert(
std::is_same<uint8_t, std::underlying_type_t<decltype(packet.m_speedGroup)>>::value, "");
static_assert(std::is_same<uint8_t, std::underlying_type_t<decltype(packet.m_speedGroup)>>::value, "");
WriteVarUint(writer, static_cast<uint8_t>(packet.m_speedGroup));
}
@@ -185,10 +177,7 @@ struct TraitsPacket<PacketCar>
return PacketCar(base.m_lat, base.m_lon, base.m_timestamp, delta.m_speedGroup);
}
static traffic::SpeedGroup GetSpeedGroup(PacketCar const & packet)
{
return packet.m_speedGroup;
}
static traffic::SpeedGroup GetSpeedGroup(PacketCar const & packet) { return packet.m_speedGroup; }
};
template <typename Reader>
@@ -206,8 +195,7 @@ std::vector<uint8_t> InflateToBuffer(Reader & src)
template <typename Writer>
void DeflateToDst(Writer & dst, std::vector<uint8_t> const & buf)
{
coding::ZLib::Deflate deflate(coding::ZLib::Deflate::Format::ZLib,
coding::ZLib::Deflate::Level::BestCompression);
coding::ZLib::Deflate deflate(coding::ZLib::Deflate::Format::ZLib, coding::ZLib::Deflate::Level::BestCompression);
std::vector<uint8_t> deflatedBuf;
deflate(buf.data(), buf.size(), std::back_inserter(deflatedBuf));
dst.Write(deflatedBuf.data(), deflatedBuf.size());
@@ -215,9 +203,9 @@ void DeflateToDst(Writer & dst, std::vector<uint8_t> const & buf)
template <typename Pack>
BasicArchive<Pack>::BasicArchive(size_t maxSize, double minDelaySeconds)
: m_buffer(maxSize), m_minDelaySeconds(minDelaySeconds)
{
}
: m_buffer(maxSize)
, m_minDelaySeconds(minDelaySeconds)
{}
template <typename Pack>
template <typename... PackParameters>
@@ -306,7 +294,7 @@ bool BasicArchive<Pack>::Read(Reader & src)
// Read with delta.
while (reader.Size() > 0)
{
Pack const delta = TraitsPacket<Pack>::Read(reader, true /* isDelta */);
Pack const delta = TraitsPacket<Pack>::Read(reader, true /* isDelta */);
m_buffer.push_back(TraitsPacket<Pack>::Combine(m_buffer.back(), delta));
}
return true;

View File

@@ -12,9 +12,11 @@ uint32_t constexpr kSocketTimeoutMs = 10000;
namespace tracking
{
Connection::Connection(std::unique_ptr<platform::Socket> socket, std::string const & host,
uint16_t port, bool isHistorical)
: m_socket(std::move(socket)), m_host(host), m_port(port)
Connection::Connection(std::unique_ptr<platform::Socket> socket, std::string const & host, uint16_t port,
bool isHistorical)
: m_socket(std::move(socket))
, m_host(host)
, m_port(port)
{
if (!m_socket)
return;
@@ -40,8 +42,7 @@ bool Connection::Reconnect()
return false;
std::string check(std::begin(Protocol::kFail), std::end(Protocol::kFail));
bool const isSuccess =
m_socket->Read(reinterpret_cast<uint8_t *>(&check[0]), static_cast<uint32_t>(check.size()));
bool const isSuccess = m_socket->Read(reinterpret_cast<uint8_t *>(&check[0]), static_cast<uint32_t>(check.size()));
if (!isSuccess || check != std::string(std::begin(Protocol::kOk), std::end(Protocol::kOk)))
return false;

View File

@@ -15,7 +15,10 @@
#pragma clang diagnostic pop
#endif
namespace platform { class Socket; }
namespace platform
{
class Socket;
}
namespace tracking
{
@@ -24,8 +27,7 @@ using DataPoint = coding::TrafficGPSEncoder::DataPoint;
class Connection final
{
public:
Connection(std::unique_ptr<platform::Socket> socket, std::string const & host, uint16_t port,
bool isHistorical);
Connection(std::unique_ptr<platform::Socket> socket, std::string const & host, uint16_t port, bool isHistorical);
bool Reconnect();
void Shutdown();
bool Send(boost::circular_buffer<DataPoint> const & points);

View File

@@ -14,8 +14,7 @@ using namespace std;
namespace
{
template <typename Container>
vector<uint8_t> CreateDataPacketImpl(Container const & points,
tracking::Protocol::PacketType const type)
vector<uint8_t> CreateDataPacketImpl(Container const & points, tracking::Protocol::PacketType const type)
{
vector<uint8_t> buffer;
MemWriter<decltype(buffer)> writer(buffer);
@@ -101,9 +100,7 @@ string Protocol::DecodeAuthPacket(Protocol::PacketType type, vector<uint8_t> con
case Protocol::PacketType::AuthV0: return string(begin(data), end(data));
case Protocol::PacketType::Error:
case Protocol::PacketType::DataV0:
case Protocol::PacketType::DataV1:
LOG(LERROR, ("Error decoding AUTH packet. PacketType =", type));
break;
case Protocol::PacketType::DataV1: LOG(LERROR, ("Error decoding AUTH packet. PacketType =", type)); break;
}
return string();
}
@@ -118,16 +115,10 @@ Protocol::DataElementsVec Protocol::DecodeDataPacket(PacketType type, vector<uin
{
switch (type)
{
case Protocol::PacketType::DataV0:
Encoder::DeserializeDataPoints(0 /* version */, src, points);
break;
case Protocol::PacketType::DataV1:
Encoder::DeserializeDataPoints(1 /* version */, src, points);
break;
case Protocol::PacketType::DataV0: Encoder::DeserializeDataPoints(0 /* version */, src, points); break;
case Protocol::PacketType::DataV1: Encoder::DeserializeDataPoints(1 /* version */, src, points); break;
case Protocol::PacketType::Error:
case Protocol::PacketType::AuthV0:
LOG(LERROR, ("Error decoding DATA packet. PacketType =", type));
return {};
case Protocol::PacketType::AuthV0: LOG(LERROR, ("Error decoding DATA packet. PacketType =", type)); return {};
}
return points;
}

View File

@@ -11,7 +11,6 @@
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
BOOST_PYTHON_MODULE(pytracking)
{
using namespace boost::python;
@@ -24,12 +23,9 @@ BOOST_PYTHON_MODULE(pytracking)
to_python_converter<std::vector<uint8_t>, vector_uint8t_to_str>();
vector_uint8t_from_python_str();
class_<Protocol::DataElementsVec>("DataElementsVec")
.def(vector_indexing_suite<Protocol::DataElementsVec>());
class_<Protocol::DataElementsVec>("DataElementsVec").def(vector_indexing_suite<Protocol::DataElementsVec>());
class_<ms::LatLon>("LatLon")
.def_readwrite("lat", &ms::LatLon::m_lat)
.def_readwrite("lon", &ms::LatLon::m_lon);
class_<ms::LatLon>("LatLon").def_readwrite("lat", &ms::LatLon::m_lat).def_readwrite("lon", &ms::LatLon::m_lon);
class_<coding::TrafficGPSEncoder::DataPoint>("DataPoint")
.def(init<uint64_t, ms::LatLon const &, uint8_t>())
@@ -45,11 +41,9 @@ BOOST_PYTHON_MODULE(pytracking)
.value("CurrentAuth", Protocol::PacketType::CurrentAuth)
.value("CurrentData", Protocol::PacketType::CurrentData);
std::vector<uint8_t> (*CreateDataPacket1)(Protocol::DataElementsCirc const &,
tracking::Protocol::PacketType) =
std::vector<uint8_t> (*CreateDataPacket1)(Protocol::DataElementsCirc const &, tracking::Protocol::PacketType) =
&Protocol::CreateDataPacket;
std::vector<uint8_t> (*CreateDataPacket2)(Protocol::DataElementsVec const &,
tracking::Protocol::PacketType) =
std::vector<uint8_t> (*CreateDataPacket2)(Protocol::DataElementsVec const &, tracking::Protocol::PacketType) =
&Protocol::CreateDataPacket;
class_<Protocol>("Protocol")

View File

@@ -22,25 +22,23 @@ double constexpr kReconnectDelaySeconds = 40.0;
double constexpr kNotChargingEventPeriod = 5 * 60.0;
static_assert(kMinDelaySeconds != 0, "");
} // namespace
} // namespace
namespace tracking
{
const char Reporter::kEnableTrackingKey[] = "StatisticsEnabled";
char const Reporter::kEnableTrackingKey[] = "StatisticsEnabled";
// static
milliseconds const Reporter::kPushDelayMs = milliseconds(20000);
// Set m_points size to be enough to keep all points even if one reconnect attempt failed.
Reporter::Reporter(unique_ptr<platform::Socket> socket, string const & host, uint16_t port,
milliseconds pushDelay)
Reporter::Reporter(unique_ptr<platform::Socket> socket, string const & host, uint16_t port, milliseconds pushDelay)
: m_allowSendingPoints(true)
, m_realtimeSender(std::move(socket), host, port, false)
, m_pushDelay(pushDelay)
, m_points(ceil(duration_cast<seconds>(pushDelay).count() + kReconnectDelaySeconds) / kMinDelaySeconds)
, m_thread([this] { Run(); })
{
}
{}
Reporter::~Reporter()
{
@@ -73,9 +71,8 @@ void Reporter::AddLocation(location::GpsInfo const & info, traffic::SpeedGroup t
}
m_lastGpsTime = info.m_timestamp;
m_input.push_back(
DataPoint(info.m_timestamp, ms::LatLon(info.m_latitude, info.m_longitude),
static_cast<std::underlying_type<traffic::SpeedGroup>::type>(traffic)));
m_input.push_back(DataPoint(info.m_timestamp, ms::LatLon(info.m_latitude, info.m_longitude),
static_cast<std::underlying_type<traffic::SpeedGroup>::type>(traffic)));
}
void Reporter::Run()
@@ -94,19 +91,14 @@ void Reporter::Run()
lock.unlock();
if (m_points.empty() && m_idleFn)
{
m_idleFn();
}
else
{
if (SendPoints())
m_points.clear();
}
else if (SendPoints())
m_points.clear();
lock.lock();
auto const passedMs = duration_cast<milliseconds>(steady_clock::now() - startTime);
if (passedMs < m_pushDelay)
m_cv.wait_for(lock, m_pushDelay - passedMs, [this]{return m_isFinished;});
m_cv.wait_for(lock, m_pushDelay - passedMs, [this] { return m_isFinished; });
}
LOG(LINFO, ("Tracking Reporter finished"));

View File

@@ -41,7 +41,7 @@ class Reporter final
{
public:
static std::chrono::milliseconds const kPushDelayMs;
static const char kEnableTrackingKey[];
static char const kEnableTrackingKey[];
Reporter(std::unique_ptr<platform::Socket> socket, std::string const & host, uint16_t port,
std::chrono::milliseconds pushDelay);

View File

@@ -57,8 +57,8 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const * data, size_t size)
Protocol::DataElementsCirc dataElementsCirc(dataElementsVec.cbegin(), dataElementsVec.cend());
Protocol::DecodeHeader(dataVec);
for (auto const type : {Protocol::PacketType::Error, Protocol::PacketType::AuthV0,
Protocol::PacketType::DataV0, Protocol::PacketType::DataV1})
for (auto const type : {Protocol::PacketType::Error, Protocol::PacketType::AuthV0, Protocol::PacketType::DataV0,
Protocol::PacketType::DataV1})
{
Protocol::CreateDataPacket(dataElementsVec, type);
Protocol::CreateDataPacket(dataElementsCirc, type);

View File

@@ -147,8 +147,7 @@ UNIT_TEST(ArchiveName_Create)
routing::RouterType const routerType = routing::RouterType::Pedestrian;
uint32_t const version = 1;
std::chrono::seconds const timestamp(1573635326);
std::string const filename =
tracking::archival_file::GetArchiveFilename(version, timestamp, routerType);
std::string const filename = tracking::archival_file::GetArchiveFilename(version, timestamp, routerType);
CHECK_EQUAL(filename, "1_1573635326_1.track", ());
}

View File

@@ -102,8 +102,7 @@ void DecodeDataPacketVersionTest(Container const & points, Protocol::PacketType
TEST_EQUAL(points.size(), result.size(), ());
for (size_t i = 0; i < points.size(); ++i)
{
TEST_EQUAL(points[i].m_timestamp, result[i].m_timestamp,
(points[i].m_timestamp, result[i].m_timestamp));
TEST_EQUAL(points[i].m_timestamp, result[i].m_timestamp, (points[i].m_timestamp, result[i].m_timestamp));
TEST(AlmostEqualAbsOrRel(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat, kEps),
(points[i].m_latLon.m_lat, result[i].m_latLon.m_lat));
TEST(AlmostEqualAbsOrRel(points[i].m_latLon.m_lon, result[i].m_latLon.m_lon, kEps),

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "tracking/reporter.hpp"
#include "tracking/protocol.hpp"
#include "tracking/reporter.hpp"
#include "coding/traffic.hpp"
@@ -25,8 +25,8 @@ using namespace platform::tests_support;
namespace
{
void TransferLocation(Reporter & reporter, TestSocket & testSocket, double timestamp,
double latidute, double longtitude)
void TransferLocation(Reporter & reporter, TestSocket & testSocket, double timestamp, double latidute,
double longtitude)
{
location::GpsInfo gpsInfo;
gpsInfo.m_timestamp = timestamp;
@@ -60,15 +60,15 @@ void TransferLocation(Reporter & reporter, TestSocket & testSocket, double times
break;
}
}
} while (readSize);
}
while (readSize);
TEST(!buffer.empty(), ());
vector<coding::TrafficGPSEncoder::DataPoint> points;
MemReader memReader(buffer.data(), buffer.size());
ReaderSource<MemReader> src(memReader);
src.Skip(sizeof(uint32_t /* header */));
coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src,
points);
coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src, points);
TEST_EQUAL(points.size(), 1, ());
auto const & point = points[0];
@@ -76,7 +76,7 @@ void TransferLocation(Reporter & reporter, TestSocket & testSocket, double times
TEST(AlmostEqualAbs(point.m_latLon.m_lat, latidute, 0.001), ());
TEST(AlmostEqualAbs(point.m_latLon.m_lon, longtitude, 0.001), ());
}
}
} // namespace
UNIT_TEST(Reporter_Smoke)
{