some more preprocessor replacements

This commit is contained in:
Robin Müller 2021-05-12 17:32:40 +02:00
parent 14027e449c
commit 4095be449a
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 6 additions and 15 deletions

View File

@ -5,13 +5,9 @@
#include "../../platform.h"
#ifdef PLATFORM_WIN
#include <winsock2.h>
#elif defined(PLATFORM_UNIX)
#include <sys/socket.h>
#endif
class TcpIpBase {
@ -23,7 +19,7 @@ protected:
static constexpr int SHUT_BOTH = SD_BOTH;
using socket_t = SOCKET;
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
using socket_t = int;
static constexpr int INVALID_SOCKET = -1;

View File

@ -48,7 +48,7 @@ ReturnValue_t Clock::setClock(const timeval* time) {
}
ReturnValue_t Clock::getClock_timeval(timeval* time) {
#if defined(_WIN32)
#if defined(PLATFORM_WIN)
auto now = std::chrono::system_clock::now();
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
auto epoch = now.time_since_epoch();
@ -56,7 +56,7 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
auto fraction = now - secondsChrono;
time->tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(fraction).count();
return HasReturnvaluesIF::RETURN_OK;
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
timespec timeUnix;
int status = clock_gettime(CLOCK_REALTIME,&timeUnix);
if(status!=0){
@ -87,14 +87,14 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
timeval Clock::getUptime() {
timeval timeval;
#if defined(_WIN32)
#if defined(PLATFORM_WIN)
auto uptime = std::chrono::milliseconds(GetTickCount64());
auto secondsChrono = std::chrono::duration_cast<std::chrono::seconds>(uptime);
timeval.tv_sec = secondsChrono.count();
auto fraction = uptime - secondsChrono;
timeval.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
fraction).count();
#elif defined(__unix__)
#elif defined(PLATFORM_UNIX)
double uptimeSeconds;
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds)
{
@ -121,7 +121,7 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
/* Do some magic with chrono (C++20!) */
/* Right now, the library doesn't have the new features to get the required values yet.
so we work around that for now. */

View File

@ -2,14 +2,9 @@
#define FSFW_PLATFORM_H_
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
#define PLATFORM_UNIX
#elif defined(_WIN32)
#define PLATFORM_WIN
#endif
#endif /* FSFW_PLATFORM_H_ */