Remove ixWebSocket
This commit is contained in:
+26
-26
@@ -12,36 +12,36 @@
|
||||
|
||||
namespace config
|
||||
{
|
||||
static inline std::map<std::string, std::string>
|
||||
readConfig(const std::string &file)
|
||||
{
|
||||
std::ifstream config(file);
|
||||
std::map<std::string, std::string> settings;
|
||||
static inline std::map<std::string, std::string>
|
||||
readConfig(const std::string &file)
|
||||
{
|
||||
std::ifstream config(file);
|
||||
std::map<std::string, std::string> settings;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(config, line)) {
|
||||
std::vector<std::string> fields = split(line, '=');
|
||||
if (fields.size() >= 2) {
|
||||
trim(fields[0]);
|
||||
trim(fields[1]);
|
||||
settings[fields[0]] = fields[1];
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
return settings;
|
||||
std::string line;
|
||||
while (std::getline(config, line)) {
|
||||
std::vector<std::string> fields = split(line, '=');
|
||||
if (fields.size() >= 2) {
|
||||
trim(fields[0]);
|
||||
trim(fields[1]);
|
||||
settings[fields[0]] = fields[1];
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
static inline void
|
||||
writeConfig(const std::map<std::string, std::string> &config,
|
||||
const std::string &file)
|
||||
{
|
||||
std::ofstream cfg(file);
|
||||
for (const std::pair<const std::string, std::string> &entry : config) {
|
||||
cfg << entry.first << '=' << entry.second << '\n';
|
||||
}
|
||||
cfg.close();
|
||||
|
||||
static inline void
|
||||
writeConfig(const std::map<std::string, std::string> &config,
|
||||
const std::string &file)
|
||||
{
|
||||
std::ofstream cfg(file);
|
||||
for (const std::pair<const std::string, std::string> &entry : config) {
|
||||
cfg << entry.first << '=' << entry.second << '\n';
|
||||
}
|
||||
cfg.close();
|
||||
}
|
||||
} // namespace config
|
||||
#endif
|
||||
|
||||
+25
-26
@@ -21,36 +21,35 @@
|
||||
*/
|
||||
class Gate
|
||||
{
|
||||
private:
|
||||
std::string designator;
|
||||
double latitude;
|
||||
double longitude;
|
||||
std::vector<std::uint8_t> file;
|
||||
private:
|
||||
std::string designator;
|
||||
double latitude;
|
||||
double longitude;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
Gate(const std::string &designator, double latitude, double longitude)
|
||||
{
|
||||
public:
|
||||
Gate(const std::string &designator, double latitude, double longitude)
|
||||
{
|
||||
|
||||
this->designator = designator;
|
||||
this->latitude = latitude;
|
||||
this->longitude = longitude;
|
||||
this->designator = designator;
|
||||
this->latitude = latitude;
|
||||
this->longitude = longitude;
|
||||
|
||||
file = std::vector<std::uint8_t>(18 + this->designator.length(), 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memset(bufPtr,
|
||||
static_cast<std::uint8_t>(this->designator.length()),
|
||||
sizeof(std::uint8_t));
|
||||
bufPtr++; // Designator length
|
||||
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
||||
bufPtr +=
|
||||
this->designator.length() + 1; // Designator plus null termination
|
||||
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
|
||||
bufPtr += 8; // Latitude
|
||||
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
|
||||
}
|
||||
file = std::vector<std::uint8_t>(18 + this->designator.length(), 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memset(bufPtr,
|
||||
static_cast<std::uint8_t>(this->designator.length()),
|
||||
sizeof(std::uint8_t));
|
||||
bufPtr++; // Designator length
|
||||
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
||||
bufPtr += this->designator.length() + 1; // Designator plus null termination
|
||||
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
|
||||
bufPtr += 8; // Latitude
|
||||
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
|
||||
}
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
+38
-39
@@ -11,47 +11,46 @@
|
||||
*/
|
||||
class PathSegment
|
||||
{
|
||||
private:
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
double latitude = 0;
|
||||
double longitude = 0;
|
||||
std::vector<std::uint8_t> file;
|
||||
private:
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
double latitude = 0;
|
||||
double longitude = 0;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
PathSegment() = default;
|
||||
PathSegment(std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
double latitude,
|
||||
double longitude)
|
||||
{
|
||||
this->altitude = altitude;
|
||||
this->groundSpeed = groundSpeed;
|
||||
this->latitude = latitude;
|
||||
this->longitude = longitude;
|
||||
public:
|
||||
PathSegment() = default;
|
||||
PathSegment(std::uint16_t altitude,
|
||||
std::uint16_t groundSpeed,
|
||||
double latitude,
|
||||
double longitude)
|
||||
{
|
||||
this->altitude = altitude;
|
||||
this->groundSpeed = groundSpeed;
|
||||
this->latitude = latitude;
|
||||
this->longitude = longitude;
|
||||
|
||||
file = std::vector<std::uint8_t>(20, 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
|
||||
bufPtr += sizeof(this->altitude);
|
||||
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
|
||||
bufPtr += sizeof(this->groundSpeed);
|
||||
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
|
||||
bufPtr += sizeof(this->latitude);
|
||||
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
|
||||
}
|
||||
file = std::vector<std::uint8_t>(20, 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
|
||||
bufPtr += sizeof(this->altitude);
|
||||
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
|
||||
bufPtr += sizeof(this->groundSpeed);
|
||||
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
|
||||
bufPtr += sizeof(this->latitude);
|
||||
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
|
||||
}
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
|
||||
friend bool operator==(const PathSegment &lhs, const PathSegment &rhs)
|
||||
{
|
||||
return lhs.altitude == rhs.altitude &&
|
||||
lhs.groundSpeed == rhs.groundSpeed &&
|
||||
lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude;
|
||||
}
|
||||
friend bool operator!=(const PathSegment &lhs, const PathSegment &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
friend bool operator==(const PathSegment &lhs, const PathSegment &rhs)
|
||||
{
|
||||
return lhs.altitude == rhs.altitude && lhs.groundSpeed == rhs.groundSpeed &&
|
||||
lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude;
|
||||
}
|
||||
friend bool operator!=(const PathSegment &lhs, const PathSegment &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
+13
-13
@@ -6,19 +6,19 @@
|
||||
|
||||
class Path
|
||||
{
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file;
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
void addSegment(PathSegment segment)
|
||||
{
|
||||
file.resize(file.size() + segment.getBinaryLength());
|
||||
std::uint8_t *bufPtr = file.data() + count * segment.getBinaryLength();
|
||||
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
||||
count++;
|
||||
}
|
||||
public:
|
||||
void addSegment(PathSegment segment)
|
||||
{
|
||||
file.resize(file.size() + segment.getBinaryLength());
|
||||
std::uint8_t *bufPtr = file.data() + count * segment.getBinaryLength();
|
||||
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
|
||||
count++;
|
||||
}
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
};
|
||||
+80
-81
@@ -23,92 +23,91 @@
|
||||
*/
|
||||
class Runway
|
||||
{
|
||||
private:
|
||||
std::string designator;
|
||||
double latitudeStart;
|
||||
double longitudeStart;
|
||||
std::uint8_t width;
|
||||
std::uint16_t length;
|
||||
std::uint16_t trueHeading;
|
||||
std::vector<std::uint8_t> file;
|
||||
private:
|
||||
std::string designator;
|
||||
double latitudeStart;
|
||||
double longitudeStart;
|
||||
std::uint8_t width;
|
||||
std::uint16_t length;
|
||||
std::uint16_t trueHeading;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
Runway(std::string designator,
|
||||
double latitudeStart,
|
||||
double longitudeStart,
|
||||
double latitudeEnd,
|
||||
double longitudeEnd,
|
||||
double width)
|
||||
{
|
||||
this->designator = std::move(designator);
|
||||
this->latitudeStart = latitudeStart;
|
||||
this->longitudeStart = longitudeStart;
|
||||
this->width = (std::uint8_t)std::round(util::to_feet(width));
|
||||
double dist = util::distanceEarth(latitudeStart,
|
||||
longitudeStart,
|
||||
latitudeEnd,
|
||||
longitudeEnd);
|
||||
this->length = (std::uint16_t)std::round(util::to_feet(dist));
|
||||
this->trueHeading =
|
||||
(std::uint16_t)std::round(util::bearing(latitudeStart,
|
||||
longitudeStart,
|
||||
latitudeEnd,
|
||||
longitudeEnd));
|
||||
public:
|
||||
Runway(std::string designator,
|
||||
double latitudeStart,
|
||||
double longitudeStart,
|
||||
double latitudeEnd,
|
||||
double longitudeEnd,
|
||||
double width)
|
||||
{
|
||||
this->designator = std::move(designator);
|
||||
this->latitudeStart = latitudeStart;
|
||||
this->longitudeStart = longitudeStart;
|
||||
this->width = (std::uint8_t)std::round(util::to_feet(width));
|
||||
double dist = util::distanceEarth(latitudeStart,
|
||||
longitudeStart,
|
||||
latitudeEnd,
|
||||
longitudeEnd);
|
||||
this->length = (std::uint16_t)std::round(util::to_feet(dist));
|
||||
this->trueHeading = (std::uint16_t)std::round(util::bearing(latitudeStart,
|
||||
longitudeStart,
|
||||
latitudeEnd,
|
||||
longitudeEnd));
|
||||
|
||||
file = std::vector<std::uint8_t>(23 + this->designator.length(), 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memset(bufPtr,
|
||||
static_cast<std::uint8_t>(this->designator.length()),
|
||||
sizeof(std::uint8_t));
|
||||
bufPtr++;
|
||||
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
||||
bufPtr += this->designator.length() + 1;
|
||||
memcpy(bufPtr, &this->latitudeStart, sizeof(this->latitudeStart));
|
||||
bufPtr += sizeof(this->latitudeStart);
|
||||
memcpy(bufPtr, &this->longitudeStart, sizeof(this->longitudeStart));
|
||||
bufPtr += sizeof(this->longitudeStart);
|
||||
memcpy(bufPtr, &this->width, sizeof(this->width));
|
||||
bufPtr += sizeof(this->width);
|
||||
memcpy(bufPtr, &this->length, sizeof(this->length));
|
||||
bufPtr += sizeof(this->length);
|
||||
memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading));
|
||||
}
|
||||
file = std::vector<std::uint8_t>(23 + this->designator.length(), 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memset(bufPtr,
|
||||
static_cast<std::uint8_t>(this->designator.length()),
|
||||
sizeof(std::uint8_t));
|
||||
bufPtr++;
|
||||
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
||||
bufPtr += this->designator.length() + 1;
|
||||
memcpy(bufPtr, &this->latitudeStart, sizeof(this->latitudeStart));
|
||||
bufPtr += sizeof(this->latitudeStart);
|
||||
memcpy(bufPtr, &this->longitudeStart, sizeof(this->longitudeStart));
|
||||
bufPtr += sizeof(this->longitudeStart);
|
||||
memcpy(bufPtr, &this->width, sizeof(this->width));
|
||||
bufPtr += sizeof(this->width);
|
||||
memcpy(bufPtr, &this->length, sizeof(this->length));
|
||||
bufPtr += sizeof(this->length);
|
||||
memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading));
|
||||
}
|
||||
|
||||
Runway(std::string designator,
|
||||
double latitudeStart,
|
||||
double longitudeStart,
|
||||
std::uint8_t width,
|
||||
std::uint16_t length,
|
||||
std::uint16_t trueHeading)
|
||||
{
|
||||
this->designator = std::move(designator);
|
||||
this->latitudeStart = latitudeStart;
|
||||
this->longitudeStart = longitudeStart;
|
||||
this->width = width;
|
||||
this->length = length;
|
||||
this->trueHeading = trueHeading;
|
||||
Runway(std::string designator,
|
||||
double latitudeStart,
|
||||
double longitudeStart,
|
||||
std::uint8_t width,
|
||||
std::uint16_t length,
|
||||
std::uint16_t trueHeading)
|
||||
{
|
||||
this->designator = std::move(designator);
|
||||
this->latitudeStart = latitudeStart;
|
||||
this->longitudeStart = longitudeStart;
|
||||
this->width = width;
|
||||
this->length = length;
|
||||
this->trueHeading = trueHeading;
|
||||
|
||||
file = std::vector<std::uint8_t>(23 + this->designator.length(), 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memset(bufPtr,
|
||||
static_cast<std::uint8_t>(this->designator.length()),
|
||||
sizeof(std::uint8_t));
|
||||
bufPtr++;
|
||||
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
||||
bufPtr += this->designator.length() + 1;
|
||||
memcpy(bufPtr, &this->latitudeStart, sizeof(this->latitudeStart));
|
||||
bufPtr += sizeof(this->latitudeStart);
|
||||
memcpy(bufPtr, &this->longitudeStart, sizeof(this->longitudeStart));
|
||||
bufPtr += sizeof(this->longitudeStart);
|
||||
memcpy(bufPtr, &this->width, sizeof(this->width));
|
||||
bufPtr += sizeof(this->width);
|
||||
memcpy(bufPtr, &this->length, sizeof(this->length));
|
||||
bufPtr += sizeof(this->length);
|
||||
memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading));
|
||||
}
|
||||
file = std::vector<std::uint8_t>(23 + this->designator.length(), 0);
|
||||
std::uint8_t *bufPtr = file.data();
|
||||
memset(bufPtr,
|
||||
static_cast<std::uint8_t>(this->designator.length()),
|
||||
sizeof(std::uint8_t));
|
||||
bufPtr++;
|
||||
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
||||
bufPtr += this->designator.length() + 1;
|
||||
memcpy(bufPtr, &this->latitudeStart, sizeof(this->latitudeStart));
|
||||
bufPtr += sizeof(this->latitudeStart);
|
||||
memcpy(bufPtr, &this->longitudeStart, sizeof(this->longitudeStart));
|
||||
bufPtr += sizeof(this->longitudeStart);
|
||||
memcpy(bufPtr, &this->width, sizeof(this->width));
|
||||
bufPtr += sizeof(this->width);
|
||||
memcpy(bufPtr, &this->length, sizeof(this->length));
|
||||
bufPtr += sizeof(this->length);
|
||||
memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading));
|
||||
}
|
||||
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
std::uint8_t *getBinaryData() { return file.data(); }
|
||||
std::size_t getBinaryLength() { return file.size(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
+137
-145
@@ -32,160 +32,152 @@
|
||||
|
||||
namespace simulatorDatabase
|
||||
{
|
||||
static inline void toFile(
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
&airports,
|
||||
const std::string &file)
|
||||
{
|
||||
std::uint8_t null = 0;
|
||||
std::ofstream out(file, std::fstream::binary);
|
||||
static inline void toFile(
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
&airports,
|
||||
const std::string &file)
|
||||
{
|
||||
std::uint8_t null = 0;
|
||||
std::ofstream out(file, std::fstream::binary);
|
||||
|
||||
// File Header
|
||||
std::uint8_t header[] = {'V', 'G', 'A', 'S', 0, CURRENT_VERSION};
|
||||
out.write(reinterpret_cast<const char *>(header), 6);
|
||||
// Num Airports
|
||||
std::uint16_t numAirports = airports.size();
|
||||
out.write(reinterpret_cast<const char *>(&numAirports),
|
||||
sizeof(numAirports));
|
||||
// Airport
|
||||
for (const std::pair<const std::string,
|
||||
std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
&airport : airports) {
|
||||
std::string icao = airport.first;
|
||||
std::vector<Gate> gates = airport.second.first;
|
||||
std::vector<Runway> runways = airport.second.second;
|
||||
// ICAO
|
||||
std::uint8_t icaoLength = icao.length();
|
||||
out.write(reinterpret_cast<const char *>(&icaoLength),
|
||||
sizeof(icaoLength));
|
||||
out.write(icao.c_str(), icaoLength);
|
||||
out.write(reinterpret_cast<const char *>(&null), sizeof(null));
|
||||
// Gates
|
||||
std::uint16_t numGates = gates.size();
|
||||
out.write(reinterpret_cast<const char *>(&numGates),
|
||||
sizeof(numGates));
|
||||
for (Gate &gate : gates) {
|
||||
out.write(reinterpret_cast<const char *>(gate.getBinaryData()),
|
||||
(std::streamsize)gate.getBinaryLength());
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways = runways.size();
|
||||
out.write(reinterpret_cast<const char *>(&numRunways),
|
||||
sizeof(numRunways));
|
||||
for (Runway &runway : runways) {
|
||||
out.write(
|
||||
reinterpret_cast<const char *>(runway.getBinaryData()),
|
||||
(std::streamsize)runway.getBinaryLength());
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
// File Header
|
||||
std::uint8_t header[] = {'V', 'G', 'A', 'S', 0, CURRENT_VERSION};
|
||||
out.write(reinterpret_cast<const char *>(header), 6);
|
||||
// Num Airports
|
||||
std::uint16_t numAirports = airports.size();
|
||||
out.write(reinterpret_cast<const char *>(&numAirports),
|
||||
sizeof(numAirports));
|
||||
// Airport
|
||||
for (const std::pair<const std::string,
|
||||
std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
&airport : airports) {
|
||||
std::string icao = airport.first;
|
||||
std::vector<Gate> gates = airport.second.first;
|
||||
std::vector<Runway> runways = airport.second.second;
|
||||
// ICAO
|
||||
std::uint8_t icaoLength = icao.length();
|
||||
out.write(reinterpret_cast<const char *>(&icaoLength),
|
||||
sizeof(icaoLength));
|
||||
out.write(icao.c_str(), icaoLength);
|
||||
out.write(reinterpret_cast<const char *>(&null), sizeof(null));
|
||||
// Gates
|
||||
std::uint16_t numGates = gates.size();
|
||||
out.write(reinterpret_cast<const char *>(&numGates), sizeof(numGates));
|
||||
for (Gate &gate : gates) {
|
||||
out.write(reinterpret_cast<const char *>(gate.getBinaryData()),
|
||||
(std::streamsize)gate.getBinaryLength());
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways = runways.size();
|
||||
out.write(reinterpret_cast<const char *>(&numRunways),
|
||||
sizeof(numRunways));
|
||||
for (Runway &runway : runways) {
|
||||
out.write(reinterpret_cast<const char *>(runway.getBinaryData()),
|
||||
(std::streamsize)runway.getBinaryLength());
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
||||
static inline std::map<std::string,
|
||||
std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
readVersion1(std::ifstream &in)
|
||||
{
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
airports;
|
||||
|
||||
std::uint16_t numAirports;
|
||||
in.read(reinterpret_cast<char *>(&numAirports), sizeof(numAirports));
|
||||
|
||||
for (int i = 0; i < numAirports; i++) {
|
||||
// ICAO
|
||||
std::uint8_t icaoLength;
|
||||
in.read(reinterpret_cast<char *>(&icaoLength), sizeof(icaoLength));
|
||||
char *icao = static_cast<char *>(calloc(icaoLength + 1, sizeof(char)));
|
||||
in.read(icao, icaoLength + 1);
|
||||
// Gates
|
||||
std::uint16_t numGates;
|
||||
in.read(reinterpret_cast<char *>(&numGates), sizeof(numGates));
|
||||
for (int j = 0; j < numGates; j++) {
|
||||
// ICAO
|
||||
std::uint8_t designatorLength;
|
||||
in.read(reinterpret_cast<char *>(&designatorLength),
|
||||
sizeof(designatorLength));
|
||||
char *designator =
|
||||
static_cast<char *>(calloc(designatorLength + 1, sizeof(char)));
|
||||
in.read(designator, designatorLength + 1);
|
||||
// Latitude
|
||||
double latitude;
|
||||
in.read(reinterpret_cast<char *>(&latitude), sizeof(latitude));
|
||||
// Latitude
|
||||
double longitude;
|
||||
in.read(reinterpret_cast<char *>(&longitude), sizeof(longitude));
|
||||
|
||||
airports[icao].first.emplace_back(designator, latitude, longitude);
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways;
|
||||
in.read(reinterpret_cast<char *>(&numRunways), sizeof(numRunways));
|
||||
for (int j = 0; j < numRunways; j++) {
|
||||
// ICAO
|
||||
std::uint8_t designatorLength;
|
||||
in.read(reinterpret_cast<char *>(&designatorLength),
|
||||
sizeof(designatorLength));
|
||||
char *designator =
|
||||
static_cast<char *>(calloc(designatorLength + 1, sizeof(char)));
|
||||
in.read(designator, designatorLength + 1);
|
||||
// Latitude
|
||||
double latitude;
|
||||
in.read(reinterpret_cast<char *>(&latitude), sizeof(latitude));
|
||||
// Latitude
|
||||
double longitude;
|
||||
in.read(reinterpret_cast<char *>(&longitude), sizeof(longitude));
|
||||
// Width
|
||||
std::uint8_t width;
|
||||
in.read(reinterpret_cast<char *>(&width), sizeof(width));
|
||||
// Length
|
||||
std::uint16_t length;
|
||||
in.read(reinterpret_cast<char *>(&length), sizeof(length));
|
||||
// True Heading
|
||||
std::uint16_t trueHeading;
|
||||
in.read(reinterpret_cast<char *>(&trueHeading), sizeof(trueHeading));
|
||||
|
||||
airports[icao].second.emplace_back(designator,
|
||||
latitude,
|
||||
longitude,
|
||||
width,
|
||||
length,
|
||||
trueHeading);
|
||||
}
|
||||
}
|
||||
|
||||
static inline std::map<std::string,
|
||||
std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
readVersion1(std::ifstream &in)
|
||||
{
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
airports;
|
||||
in.close();
|
||||
|
||||
std::uint16_t numAirports;
|
||||
in.read(reinterpret_cast<char *>(&numAirports), sizeof(numAirports));
|
||||
return airports;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numAirports; i++) {
|
||||
// ICAO
|
||||
std::uint8_t icaoLength;
|
||||
in.read(reinterpret_cast<char *>(&icaoLength), sizeof(icaoLength));
|
||||
char *icao =
|
||||
static_cast<char *>(calloc(icaoLength + 1, sizeof(char)));
|
||||
in.read(icao, icaoLength + 1);
|
||||
// Gates
|
||||
std::uint16_t numGates;
|
||||
in.read(reinterpret_cast<char *>(&numGates), sizeof(numGates));
|
||||
for (int j = 0; j < numGates; j++) {
|
||||
// ICAO
|
||||
std::uint8_t designatorLength;
|
||||
in.read(reinterpret_cast<char *>(&designatorLength),
|
||||
sizeof(designatorLength));
|
||||
char *designator = static_cast<char *>(
|
||||
calloc(designatorLength + 1, sizeof(char)));
|
||||
in.read(designator, designatorLength + 1);
|
||||
// Latitude
|
||||
double latitude;
|
||||
in.read(reinterpret_cast<char *>(&latitude), sizeof(latitude));
|
||||
// Latitude
|
||||
double longitude;
|
||||
in.read(reinterpret_cast<char *>(&longitude),
|
||||
sizeof(longitude));
|
||||
static inline std::map<std::string,
|
||||
std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
fromFile(const std::string &file)
|
||||
{
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
airports;
|
||||
std::ifstream in(file);
|
||||
|
||||
airports[icao].first.emplace_back(designator,
|
||||
latitude,
|
||||
longitude);
|
||||
}
|
||||
// Runways
|
||||
std::uint8_t numRunways;
|
||||
in.read(reinterpret_cast<char *>(&numRunways), sizeof(numRunways));
|
||||
for (int j = 0; j < numRunways; j++) {
|
||||
// ICAO
|
||||
std::uint8_t designatorLength;
|
||||
in.read(reinterpret_cast<char *>(&designatorLength),
|
||||
sizeof(designatorLength));
|
||||
char *designator = static_cast<char *>(
|
||||
calloc(designatorLength + 1, sizeof(char)));
|
||||
in.read(designator, designatorLength + 1);
|
||||
// Latitude
|
||||
double latitude;
|
||||
in.read(reinterpret_cast<char *>(&latitude), sizeof(latitude));
|
||||
// Latitude
|
||||
double longitude;
|
||||
in.read(reinterpret_cast<char *>(&longitude),
|
||||
sizeof(longitude));
|
||||
// Width
|
||||
std::uint8_t width;
|
||||
in.read(reinterpret_cast<char *>(&width), sizeof(width));
|
||||
// Length
|
||||
std::uint16_t length;
|
||||
in.read(reinterpret_cast<char *>(&length), sizeof(length));
|
||||
// True Heading
|
||||
std::uint16_t trueHeading;
|
||||
in.read(reinterpret_cast<char *>(&trueHeading),
|
||||
sizeof(trueHeading));
|
||||
|
||||
airports[icao].second.emplace_back(designator,
|
||||
latitude,
|
||||
longitude,
|
||||
width,
|
||||
length,
|
||||
trueHeading);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
return airports;
|
||||
// File Header
|
||||
char ident[5];
|
||||
in.read(ident, 5);
|
||||
if (strcmp(ident, "VGAS") != 0) {
|
||||
throw std::invalid_argument("Wrong file");
|
||||
}
|
||||
std::uint8_t version;
|
||||
in.read(reinterpret_cast<char *>(&version), 1);
|
||||
|
||||
static inline std::map<std::string,
|
||||
std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
fromFile(const std::string &file)
|
||||
{
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
airports;
|
||||
std::ifstream in(file);
|
||||
|
||||
// File Header
|
||||
char ident[5];
|
||||
in.read(ident, 5);
|
||||
if (strcmp(ident, "VGAS") != 0) {
|
||||
throw std::invalid_argument("Wrong file");
|
||||
}
|
||||
std::uint8_t version;
|
||||
in.read(reinterpret_cast<char *>(&version), 1);
|
||||
|
||||
if (version == 1) {
|
||||
return readVersion1(in);
|
||||
}
|
||||
return airports;
|
||||
if (version == 1) {
|
||||
return readVersion1(in);
|
||||
}
|
||||
return airports;
|
||||
}
|
||||
} // namespace simulatorDatabase
|
||||
|
||||
#endif
|
||||
|
||||
+19
-19
@@ -9,45 +9,45 @@
|
||||
// trim from start (in place)
|
||||
static inline void ltrim(std::string &s)
|
||||
{
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
}
|
||||
|
||||
// trim from end (in place)
|
||||
static inline void rtrim(std::string &s)
|
||||
{
|
||||
s.erase(std::find_if(s.rbegin(),
|
||||
s.rend(),
|
||||
[](unsigned char ch) { return !std::isspace(ch); })
|
||||
.base(),
|
||||
s.end());
|
||||
s.erase(std::find_if(s.rbegin(),
|
||||
s.rend(),
|
||||
[](unsigned char ch) { return !std::isspace(ch); })
|
||||
.base(),
|
||||
s.end());
|
||||
}
|
||||
|
||||
static inline std::string rtrim_copy(std::string s)
|
||||
{
|
||||
rtrim(s);
|
||||
return s;
|
||||
rtrim(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
// trim from both ends (in place)
|
||||
static inline void trim(std::string &s)
|
||||
{
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
static inline std::vector<std::string> split(const std::string &s, char delim)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
std::vector<std::string> result;
|
||||
std::stringstream ss(s);
|
||||
std::string item;
|
||||
|
||||
while (getline(ss, item, delim)) {
|
||||
result.push_back(item);
|
||||
}
|
||||
while (getline(ss, item, delim)) {
|
||||
result.push_back(item);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
+198
-204
@@ -39,264 +39,258 @@
|
||||
|
||||
namespace util
|
||||
{
|
||||
static inline double to_feet(double value) { return value * 3.280839895; }
|
||||
static inline double to_feet(double value) { return value * 3.280839895; }
|
||||
|
||||
static inline double to_degrees(double value) { return value * 180 / M_PI; }
|
||||
static inline double to_degrees(double value) { return value * 180 / M_PI; }
|
||||
|
||||
static inline double to_radians(double value) { return value * M_PI / 180; }
|
||||
static inline double to_radians(double value) { return value * M_PI / 180; }
|
||||
|
||||
static inline double normalize(double value)
|
||||
{
|
||||
return fmod(value + 360, 360);
|
||||
}
|
||||
static inline double normalize(double value)
|
||||
{
|
||||
return fmod(value + 360, 360);
|
||||
}
|
||||
|
||||
static inline double bearing(double fromLatitude,
|
||||
double fromLongitude,
|
||||
double toLatitude,
|
||||
double toLongitude)
|
||||
{
|
||||
double y = sin(to_radians(toLongitude) - to_radians(fromLongitude)) *
|
||||
cos(to_radians(toLatitude));
|
||||
double x = cos(to_radians(fromLatitude)) * sin(to_radians(toLatitude)) -
|
||||
sin(to_radians(fromLatitude)) * cos(to_radians(toLatitude)) *
|
||||
cos(to_radians(toLongitude) - to_radians(fromLongitude));
|
||||
static inline double bearing(double fromLatitude,
|
||||
double fromLongitude,
|
||||
double toLatitude,
|
||||
double toLongitude)
|
||||
{
|
||||
double y = sin(to_radians(toLongitude) - to_radians(fromLongitude)) *
|
||||
cos(to_radians(toLatitude));
|
||||
double x = cos(to_radians(fromLatitude)) * sin(to_radians(toLatitude)) -
|
||||
sin(to_radians(fromLatitude)) * cos(to_radians(toLatitude)) *
|
||||
cos(to_radians(toLongitude) - to_radians(fromLongitude));
|
||||
|
||||
return normalize(to_degrees(atan2(y, x)));
|
||||
}
|
||||
return normalize(to_degrees(atan2(y, x)));
|
||||
}
|
||||
|
||||
static inline double distanceEarth(double fromLatitude,
|
||||
double fromLongitude,
|
||||
double toLatitude,
|
||||
double toLongitude)
|
||||
{
|
||||
double lat1r, lon1r, lat2r, lon2r, u, v;
|
||||
lat1r = to_radians(fromLatitude);
|
||||
lon1r = to_radians(fromLongitude);
|
||||
lat2r = to_radians(toLatitude);
|
||||
lon2r = to_radians(toLongitude);
|
||||
u = sin((lat2r - lat1r) / 2);
|
||||
v = sin((lon2r - lon1r) / 2);
|
||||
return 2.0 * EARTH_M *
|
||||
asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v));
|
||||
}
|
||||
static inline double distanceEarth(double fromLatitude,
|
||||
double fromLongitude,
|
||||
double toLatitude,
|
||||
double toLongitude)
|
||||
{
|
||||
double lat1r, lon1r, lat2r, lon2r, u, v;
|
||||
lat1r = to_radians(fromLatitude);
|
||||
lon1r = to_radians(fromLongitude);
|
||||
lat2r = to_radians(toLatitude);
|
||||
lon2r = to_radians(toLongitude);
|
||||
u = sin((lat2r - lat1r) / 2);
|
||||
v = sin((lon2r - lon1r) / 2);
|
||||
return 2.0 * EARTH_M * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline std::vector<T>
|
||||
select_T(const std::vector<T> &inVec,
|
||||
std::function<bool(const T &)> predicate)
|
||||
{
|
||||
std::vector<T> result;
|
||||
copy_if(inVec.begin(), inVec.end(), back_inserter(result), predicate);
|
||||
return result;
|
||||
}
|
||||
template <typename T>
|
||||
static inline std::vector<T>
|
||||
select_T(const std::vector<T> &inVec,
|
||||
std::function<bool(const T &)> predicate)
|
||||
{
|
||||
std::vector<T> result;
|
||||
copy_if(inVec.begin(), inVec.end(), back_inserter(result), predicate);
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined APL || defined LIN
|
||||
static unsigned long get_size_by_fd(int fd)
|
||||
{
|
||||
struct stat buf {
|
||||
};
|
||||
if (fstat(fd, &buf) < 0)
|
||||
return 0;
|
||||
return buf.st_size;
|
||||
}
|
||||
static unsigned long get_size_by_fd(int fd)
|
||||
{
|
||||
struct stat buf {
|
||||
};
|
||||
if (fstat(fd, &buf) < 0)
|
||||
return 0;
|
||||
return buf.st_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void to_hex(const char *hash, char *buffer)
|
||||
{
|
||||
for (int i = 0; i < MD5LEN; i++) {
|
||||
if (buffer != nullptr) {
|
||||
sprintf(&buffer[2 * i], "%02x", hash[i] & 0xff);
|
||||
}
|
||||
}
|
||||
static void to_hex(const char *hash, char *buffer)
|
||||
{
|
||||
for (int i = 0; i < MD5LEN; i++) {
|
||||
if (buffer != nullptr) {
|
||||
sprintf(&buffer[2 * i], "%02x", hash[i] & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef IBM
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *lastHash,
|
||||
const std::function<void(const std::string)> toLog)
|
||||
{
|
||||
BOOL bResult = FALSE;
|
||||
HCRYPTPROV hProv = 0;
|
||||
HCRYPTHASH hHash = 0;
|
||||
HANDLE hFile;
|
||||
BYTE rgbFile[BUFSIZE] = {0};
|
||||
DWORD cbRead = 0;
|
||||
BYTE rgbHash[MD5LEN] = {0};
|
||||
DWORD cbHash = 0;
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *lastHash,
|
||||
const std::function<void(const std::string)> toLog)
|
||||
{
|
||||
BOOL bResult = FALSE;
|
||||
HCRYPTPROV hProv = 0;
|
||||
HCRYPTHASH hHash = 0;
|
||||
HANDLE hFile;
|
||||
BYTE rgbFile[BUFSIZE] = {0};
|
||||
DWORD cbRead = 0;
|
||||
BYTE rgbHash[MD5LEN] = {0};
|
||||
DWORD cbHash = 0;
|
||||
|
||||
// Logic to check usage goes here.
|
||||
hFile = CreateFile(filepath,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_SEQUENTIAL_SCAN,
|
||||
nullptr);
|
||||
// Logic to check usage goes here.
|
||||
hFile = CreateFile(filepath,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_SEQUENTIAL_SCAN,
|
||||
nullptr);
|
||||
|
||||
// Get handle to the crypto provider
|
||||
if (!CryptAcquireContext(&hProv,
|
||||
nullptr,
|
||||
nullptr,
|
||||
PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptAcquireContext returned with error "
|
||||
<< GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
// Get handle to the crypto provider
|
||||
if (!CryptAcquireContext(&hProv,
|
||||
nullptr,
|
||||
nullptr,
|
||||
PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptAcquireContext returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
|
||||
CloseHandle(hFile);
|
||||
return 1;
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptCreateHash returned with error "
|
||||
<< GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptCreateHash returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
|
||||
CloseHandle(hFile);
|
||||
CryptReleaseContext(hProv, 0);
|
||||
return 1;
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
CryptReleaseContext(hProv, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (
|
||||
(bResult = ReadFile(hFile, rgbFile, BUFSIZE, &cbRead, nullptr))) {
|
||||
if (0 == cbRead) {
|
||||
break;
|
||||
}
|
||||
while ((bResult = ReadFile(hFile, rgbFile, BUFSIZE, &cbRead, nullptr))) {
|
||||
if (0 == cbRead) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!CryptHashData(hHash, rgbFile, cbRead, 0)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptHashData returned with error "
|
||||
<< GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
if (!CryptHashData(hHash, rgbFile, cbRead, 0)) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptHashData returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CryptDestroyHash(hHash);
|
||||
CloseHandle(hFile);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bResult) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "ReadFile returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CryptDestroyHash(hHash);
|
||||
CloseHandle(hFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cbHash = MD5LEN;
|
||||
if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) {
|
||||
to_hex((char *)rgbHash, lastHash);
|
||||
} else {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptGetHashParam returned with error "
|
||||
<< GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
}
|
||||
|
||||
CryptDestroyHash(hHash);
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CryptDestroyHash(hHash);
|
||||
CloseHandle(hFile);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bResult) {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "ReadFile returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CryptDestroyHash(hHash);
|
||||
CloseHandle(hFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cbHash = MD5LEN;
|
||||
if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)) {
|
||||
to_hex((char *)rgbHash, lastHash);
|
||||
} else {
|
||||
std::stringstream debug_msg;
|
||||
debug_msg << "CryptGetHashParam returned with error " << GetLastError();
|
||||
toLog(debug_msg.str());
|
||||
}
|
||||
|
||||
CryptDestroyHash(hHash);
|
||||
CryptReleaseContext(hProv, 0);
|
||||
CloseHandle(hFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef APL
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *lastHash,
|
||||
const std::function<void(const std::string)> &toLog)
|
||||
{
|
||||
int file_descript;
|
||||
unsigned long file_size;
|
||||
char *file_buffer;
|
||||
unsigned char result[MD5LEN];
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *lastHash,
|
||||
const std::function<void(const std::string)> &toLog)
|
||||
{
|
||||
int file_descript;
|
||||
unsigned long file_size;
|
||||
char *file_buffer;
|
||||
unsigned char result[MD5LEN];
|
||||
|
||||
file_descript = open(filepath, O_RDONLY);
|
||||
if (file_descript < 0)
|
||||
return 1;
|
||||
file_descript = open(filepath, O_RDONLY);
|
||||
if (file_descript < 0)
|
||||
return 1;
|
||||
|
||||
file_size = get_size_by_fd(file_descript);
|
||||
file_size = get_size_by_fd(file_descript);
|
||||
|
||||
file_buffer =
|
||||
(char *)mmap(0, file_size, PROT_READ, MAP_SHARED, file_descript, 0);
|
||||
file_buffer =
|
||||
(char *)mmap(0, file_size, PROT_READ, MAP_SHARED, file_descript, 0);
|
||||
|
||||
CC_MD5_CTX context;
|
||||
CC_MD5_Init(&context);
|
||||
CC_MD5_Update(&context, file_buffer, (CC_LONG)file_size);
|
||||
CC_MD5_Final(result, &context);
|
||||
CC_MD5_CTX context;
|
||||
CC_MD5_Init(&context);
|
||||
CC_MD5_Update(&context, file_buffer, (CC_LONG)file_size);
|
||||
CC_MD5_Final(result, &context);
|
||||
|
||||
munmap(file_buffer, file_size);
|
||||
close(file_descript);
|
||||
munmap(file_buffer, file_size);
|
||||
close(file_descript);
|
||||
|
||||
to_hex((char *)result, lastHash);
|
||||
return 0;
|
||||
}
|
||||
to_hex((char *)result, lastHash);
|
||||
return 0;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
#ifdef LIN
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *buffer,
|
||||
const std::function<void(const std::string)> &toLog)
|
||||
{
|
||||
int file_descriptor;
|
||||
unsigned long file_size;
|
||||
char *file_buffer;
|
||||
unsigned char result[MD5LEN];
|
||||
static inline int
|
||||
generateMD5(const char *filepath,
|
||||
char *buffer,
|
||||
const std::function<void(const std::string)> &toLog)
|
||||
{
|
||||
int file_descriptor;
|
||||
unsigned long file_size;
|
||||
char *file_buffer;
|
||||
unsigned char result[MD5LEN];
|
||||
|
||||
file_descriptor = open(filepath, O_RDONLY);
|
||||
if (file_descriptor < 0)
|
||||
return 1;
|
||||
file_descriptor = open(filepath, O_RDONLY);
|
||||
if (file_descriptor < 0)
|
||||
return 1;
|
||||
|
||||
file_size = get_size_by_fd(file_descriptor);
|
||||
if (file_size == 0)
|
||||
return 1;
|
||||
file_size = get_size_by_fd(file_descriptor);
|
||||
if (file_size == 0)
|
||||
return 1;
|
||||
|
||||
file_buffer = (char *)
|
||||
mmap(nullptr, file_size, PROT_READ, MAP_SHARED, file_descriptor, 0);
|
||||
file_buffer = (char *)
|
||||
mmap(nullptr, file_size, PROT_READ, MAP_SHARED, file_descriptor, 0);
|
||||
|
||||
MD5((unsigned char *)file_buffer, file_size, result);
|
||||
MD5((unsigned char *)file_buffer, file_size, result);
|
||||
|
||||
munmap(file_buffer, file_size);
|
||||
close(file_descriptor);
|
||||
munmap(file_buffer, file_size);
|
||||
close(file_descriptor);
|
||||
|
||||
to_hex((char *)result, buffer);
|
||||
return 0;
|
||||
}
|
||||
to_hex((char *)result, buffer);
|
||||
return 0;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
static inline void setThreadName(const std::string &name)
|
||||
{
|
||||
static inline void setThreadName(const std::string &name)
|
||||
{
|
||||
#ifdef APL
|
||||
//
|
||||
// Apple reserves 16 bytes for its thread names
|
||||
// Notice that the Apple version of pthread_setname_np
|
||||
// does not take a pthread_t argument
|
||||
//
|
||||
pthread_setname_np(name.substr(0, 63).c_str());
|
||||
//
|
||||
// Apple reserves 16 bytes for its thread names
|
||||
// Notice that the Apple version of pthread_setname_np
|
||||
// does not take a pthread_t argument
|
||||
//
|
||||
pthread_setname_np(name.substr(0, 63).c_str());
|
||||
#endif
|
||||
#ifdef LIN
|
||||
//
|
||||
// Linux only reserves 16 bytes for its thread names
|
||||
// See prctl and PR_SET_NAME property in
|
||||
// http://man7.org/linux/man-pages/man2/prctl.2.html
|
||||
//
|
||||
pthread_setname_np(pthread_self(), name.substr(0, 15).c_str());
|
||||
//
|
||||
// Linux only reserves 16 bytes for its thread names
|
||||
// See prctl and PR_SET_NAME property in
|
||||
// http://man7.org/linux/man-pages/man2/prctl.2.html
|
||||
//
|
||||
pthread_setname_np(pthread_self(), name.substr(0, 15).c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
} // namespace util
|
||||
|
||||
Reference in New Issue
Block a user