some more preprocessor replacements
This commit is contained in:
parent
14027e449c
commit
4095be449a
@ -5,13 +5,9 @@
|
|||||||
#include "../../platform.h"
|
#include "../../platform.h"
|
||||||
|
|
||||||
#ifdef PLATFORM_WIN
|
#ifdef PLATFORM_WIN
|
||||||
|
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
||||||
#elif defined(PLATFORM_UNIX)
|
#elif defined(PLATFORM_UNIX)
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class TcpIpBase {
|
class TcpIpBase {
|
||||||
@ -23,7 +19,7 @@ protected:
|
|||||||
static constexpr int SHUT_BOTH = SD_BOTH;
|
static constexpr int SHUT_BOTH = SD_BOTH;
|
||||||
|
|
||||||
using socket_t = SOCKET;
|
using socket_t = SOCKET;
|
||||||
#elif defined(__unix__)
|
#elif defined(PLATFORM_UNIX)
|
||||||
using socket_t = int;
|
using socket_t = int;
|
||||||
|
|
||||||
static constexpr int INVALID_SOCKET = -1;
|
static constexpr int INVALID_SOCKET = -1;
|
||||||
|
@ -48,7 +48,7 @@ ReturnValue_t Clock::setClock(const timeval* time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||||
#if defined(_WIN32)
|
#if defined(PLATFORM_WIN)
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
||||||
auto epoch = now.time_since_epoch();
|
auto epoch = now.time_since_epoch();
|
||||||
@ -56,7 +56,7 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
|||||||
auto fraction = now - secondsChrono;
|
auto fraction = now - secondsChrono;
|
||||||
time->tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(fraction).count();
|
time->tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(fraction).count();
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
#elif defined(__unix__)
|
#elif defined(PLATFORM_UNIX)
|
||||||
timespec timeUnix;
|
timespec timeUnix;
|
||||||
int status = clock_gettime(CLOCK_REALTIME,&timeUnix);
|
int status = clock_gettime(CLOCK_REALTIME,&timeUnix);
|
||||||
if(status!=0){
|
if(status!=0){
|
||||||
@ -87,14 +87,14 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
|||||||
|
|
||||||
timeval Clock::getUptime() {
|
timeval Clock::getUptime() {
|
||||||
timeval timeval;
|
timeval timeval;
|
||||||
#if defined(_WIN32)
|
#if defined(PLATFORM_WIN)
|
||||||
auto uptime = std::chrono::milliseconds(GetTickCount64());
|
auto uptime = std::chrono::milliseconds(GetTickCount64());
|
||||||
auto secondsChrono = std::chrono::duration_cast<std::chrono::seconds>(uptime);
|
auto secondsChrono = std::chrono::duration_cast<std::chrono::seconds>(uptime);
|
||||||
timeval.tv_sec = secondsChrono.count();
|
timeval.tv_sec = secondsChrono.count();
|
||||||
auto fraction = uptime - secondsChrono;
|
auto fraction = uptime - secondsChrono;
|
||||||
timeval.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
|
timeval.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||||
fraction).count();
|
fraction).count();
|
||||||
#elif defined(__unix__)
|
#elif defined(PLATFORM_UNIX)
|
||||||
double uptimeSeconds;
|
double uptimeSeconds;
|
||||||
if (std::ifstream("/proc/uptime", std::ios::in) >> 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;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
|
||||||
/* Do some magic with chrono (C++20!) */
|
/* Do some magic with chrono (C++20!) */
|
||||||
/* Right now, the library doesn't have the new features to get the required values yet.
|
/* Right now, the library doesn't have the new features to get the required values yet.
|
||||||
so we work around that for now. */
|
so we work around that for now. */
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
#define FSFW_PLATFORM_H_
|
#define FSFW_PLATFORM_H_
|
||||||
|
|
||||||
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
|
#if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
|
||||||
|
|
||||||
#define PLATFORM_UNIX
|
#define PLATFORM_UNIX
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
#define PLATFORM_WIN
|
#define PLATFORM_WIN
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSFW_PLATFORM_H_ */
|
#endif /* FSFW_PLATFORM_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user