platform header file

This commit is contained in:
Robin Müller 2021-05-12 16:47:53 +02:00
parent d27f49c968
commit 1626b266d7
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
10 changed files with 42 additions and 48 deletions

View File

@ -1,10 +1,9 @@
#include "TcpIpBase.h" #include "TcpIpBase.h"
#include "../../platform.h"
#ifdef __unix__ #ifdef PLATFORM_UNIX
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
TcpIpBase::TcpIpBase() { TcpIpBase::TcpIpBase() {
@ -37,17 +36,17 @@ TcpIpBase::~TcpIpBase() {
} }
int TcpIpBase::closeSocket(socket_t socket) { int TcpIpBase::closeSocket(socket_t socket) {
#ifdef _WIN32 #ifdef PLATFORM_WIN
return closesocket(socket); return closesocket(socket);
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
return close(socket); return close(socket);
#endif #endif
} }
int TcpIpBase::getLastSocketError() { int TcpIpBase::getLastSocketError() {
#ifdef _WIN32 #ifdef PLATFORM_WIN
return WSAGetLastError(); return WSAGetLastError();
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
return errno; return errno;
#endif #endif
} }

View File

@ -1,13 +1,14 @@
#ifndef FSFW_OSAL_COMMON_TCPIPIF_H_ #ifndef FSFW_OSAL_COMMON_TCPIPIF_H_
#define FSFW_OSAL_COMMON_TCPIPIF_H_ #define FSFW_OSAL_COMMON_TCPIPIF_H_
#include <fsfw/returnvalues/HasReturnvaluesIF.h> #include "../../returnvalues/HasReturnvaluesIF.h"
#include "../../platform.h"
#ifdef _WIN32 #ifdef PLATFORM_WIN
#include <winsock2.h> #include <winsock2.h>
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
#include <sys/socket.h> #include <sys/socket.h>
@ -16,7 +17,7 @@
class TcpIpBase { class TcpIpBase {
protected: protected:
#ifdef _WIN32 #ifdef PLATFORM_WIN
static constexpr int SHUT_RECV = SD_RECEIVE; static constexpr int SHUT_RECV = SD_RECEIVE;
static constexpr int SHUT_SEND = SD_SEND; static constexpr int SHUT_SEND = SD_SEND;
static constexpr int SHUT_BOTH = SD_BOTH; static constexpr int SHUT_BOTH = SD_BOTH;

View File

@ -1,15 +1,13 @@
#include "TcpTmTcServer.h" #include "TcpTmTcServer.h"
#include "tcpipHelpers.h" #include "tcpipHelpers.h"
#include "../../platform.h"
#include "../../serviceinterface/ServiceInterface.h" #include "../../serviceinterface/ServiceInterface.h"
#ifdef _WIN32 #ifdef PLATFORM_WIN
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#elif defined(PLATFORM_UNIX)
#elif defined(__unix__)
#include <netdb.h> #include <netdb.h>
#endif #endif
const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7301"; const std::string TcpTmTcServer::DEFAULT_TCP_SERVER_PORT = "7301";

View File

@ -2,10 +2,11 @@
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ #define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
#include "TcpIpBase.h" #include "TcpIpBase.h"
#include "../../platform.h"
#include "../../objectmanager/SystemObject.h" #include "../../objectmanager/SystemObject.h"
#include "../../tasks/ExecutableObjectIF.h" #include "../../tasks/ExecutableObjectIF.h"
#ifdef __unix__ #ifdef PLATFORM_UNIX
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif

View File

@ -1,17 +1,14 @@
#include "UdpTcPollingTask.h" #include "UdpTcPollingTask.h"
#include "tcpipHelpers.h" #include "tcpipHelpers.h"
#include "../../platform.h"
#include "../../globalfunctions/arrayprinter.h" #include "../../globalfunctions/arrayprinter.h"
#include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../serviceinterface/ServiceInterfaceStream.h"
#ifdef _WIN32 #ifdef PLATFORM_WIN
#include <winsock2.h> #include <winsock2.h>
#elif defined(PLATFORM_UNIX)
#else
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif
//! Debugging preprocessor define. //! Debugging preprocessor define.
@ -155,7 +152,7 @@ ReturnValue_t UdpTcPollingTask::initializeAfterTaskCreation() {
} }
void UdpTcPollingTask::setTimeout(double timeoutSeconds) { void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
#ifdef _WIN32 #ifdef PLATFORM_WIN
DWORD timeoutMs = timeoutSeconds * 1000.0; DWORD timeoutMs = timeoutSeconds * 1000.0;
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO, int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD)); reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD));
@ -165,7 +162,7 @@ void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
"receive timeout failed with " << strerror(errno) << std::endl; "receive timeout failed with " << strerror(errno) << std::endl;
#endif #endif
} }
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
timeval tval; timeval tval;
tval = timevalOperations::toTimeval(timeoutSeconds); tval = timevalOperations::toTimeval(timeoutSeconds);
int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO, int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,

View File

@ -1,18 +1,15 @@
#include "UdpTmTcBridge.h"
#include "tcpipHelpers.h" #include "tcpipHelpers.h"
#include <fsfw/serviceinterface/ServiceInterface.h> #include "../../platform.h"
#include <fsfw/ipc/MutexGuard.h> #include "../../serviceinterface/ServiceInterface.h"
#include <fsfw/osal/common/UdpTmTcBridge.h> #include "../../ipc/MutexGuard.h"
#ifdef _WIN32
#ifdef PLATFORM_WIN
#include <ws2tcpip.h> #include <ws2tcpip.h>
#elif defined(PLATFORM_UNIX)
#elif defined(__unix__)
#include <netdb.h> #include <netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
//! Debugging preprocessor define. //! Debugging preprocessor define.

View File

@ -2,16 +2,13 @@
#define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_ #define FSFW_OSAL_WINDOWS_TMTCWINUDPBRIDGE_H_
#include "TcpIpBase.h" #include "TcpIpBase.h"
#include "../../platform.h"
#include "../../tmtcservices/TmTcBridge.h" #include "../../tmtcservices/TmTcBridge.h"
#ifdef _WIN32 #ifdef PLATFORM_WIN
#include <ws2tcpip.h> #include <ws2tcpip.h>
#elif defined(PLATFORM_UNIX)
#elif defined(__unix__)
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif
#include <string> #include <string>

View File

@ -1,10 +1,12 @@
#include "../../serviceinterface/ServiceInterface.h" #include "../../serviceinterface/ServiceInterface.h"
#include "../../timemanager/Clock.h" #include "../../timemanager/Clock.h"
#include "../../platform.h"
#include <chrono> #include <chrono>
#if defined(_WIN32)
#if defined(PLATFORM_WIN)
#include <sysinfoapi.h> #include <sysinfoapi.h>
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
#include <fstream> #include <fstream>
#endif #endif

View File

@ -1,4 +1,5 @@
#include "taskHelpers.h" #include "taskHelpers.h"
#include "../../platform.h"
#include "../../osal/host/FixedTimeslotTask.h" #include "../../osal/host/FixedTimeslotTask.h"
#include "../../ipc/MutexFactory.h" #include "../../ipc/MutexFactory.h"
#include "../../osal/host/Mutex.h" #include "../../osal/host/Mutex.h"
@ -9,10 +10,10 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#if defined(WIN32) #if defined(PLATFORM_WIN)
#include <windows.h> #include <windows.h>
#include "../windows/winTaskHelpers.h" #include "../windows/winTaskHelpers.h"
#elif defined(LINUX) #elif defined(PLATFORM_UNIX)
#include <pthread.h> #include <pthread.h>
#endif #endif

View File

@ -2,6 +2,7 @@
#include "PeriodicTask.h" #include "PeriodicTask.h"
#include "taskHelpers.h" #include "taskHelpers.h"
#include "../../platform.h"
#include "../../ipc/MutexFactory.h" #include "../../ipc/MutexFactory.h"
#include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../tasks/ExecutableObjectIF.h" #include "../../tasks/ExecutableObjectIF.h"
@ -9,10 +10,10 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#if defined(WIN32) #if defined(PLATFORM_WIN)
#include <processthreadsapi.h> #include <processthreadsapi.h>
#include <fsfw/osal/windows/winTaskHelpers.h> #include <fsfw/osal/windows/winTaskHelpers.h>
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -24,9 +25,9 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
// It is probably possible to set task priorities by using the native // It is probably possible to set task priorities by using the native
// task handles for Windows / Linux // task handles for Windows / Linux
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this); mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
#if defined(_WIN32) #if defined(PLATFORM_WIN)
tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority); tasks::setTaskPriority(reinterpret_cast<HANDLE>(mainThread.native_handle()), setPriority);
#elif defined(__unix__) #elif defined(PLATFORM_UNIX)
// TODO: We could reuse existing code here. // TODO: We could reuse existing code here.
#endif #endif
tasks::insertTaskName(mainThread.get_id(), taskName); tasks::insertTaskName(mainThread.get_id(), taskName);