134 lines
4.1 KiB
C++
134 lines
4.1 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivBase/Ip/IpSocket.h
|
|
*
|
|
* @brief Header file for ip socket class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_BASE_IP_IP_SOCKET_H)
|
|
#define ACTIV_BASE_IP_IP_SOCKET_H
|
|
|
|
#include "ActivMiddleware/ActivBase/External.h"
|
|
|
|
#if (defined ACTIV_PLATFORM_WINDOWS)
|
|
#include "../Windows/Ip/IpSocket.h"
|
|
#elif (defined ACTIV_PLATFORM_POSIX)
|
|
#include "../Posix/Ip/IpSocket.h"
|
|
#else
|
|
#error No IpSocket.h for this platform yet.
|
|
#endif
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
inline void IpSocket::AppendRxBuffer(void *pData, const size_t dataLength)
|
|
{
|
|
return m_rxBuffers.Append(pData, dataLength);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline IpBufferHelper &IpSocket::GetRxBuffers()
|
|
{
|
|
return m_rxBuffers;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const IpBufferHelper &IpSocket::GetRxBuffers() const
|
|
{
|
|
return m_rxBuffers;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void IpSocket::EnableCustomRx()
|
|
{
|
|
m_isCustomRx = true;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void IpSocket::AppendTxBuffer(const void *pData, const size_t dataLength)
|
|
{
|
|
return m_txBuffers.Append(const_cast<void *>(pData), dataLength);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline IpBufferHelper &IpSocket::GetTxBuffers()
|
|
{
|
|
return m_txBuffers;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const IpBufferHelper &IpSocket::GetTxBuffers() const
|
|
{
|
|
return m_txBuffers;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void IpSocket::EnableCustomTx()
|
|
{
|
|
m_isCustomTx = true;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline IpManager &IpSocket::GetIpManager() const
|
|
{
|
|
return m_ipManager;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool IpSocket::IsInCallback() const
|
|
{
|
|
return (0 != m_inCallbackCount);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline IpSocket::ScopedIsInCallback::ScopedIsInCallback(IpSocket &ipSocket) :
|
|
m_ipSocket(ipSocket)
|
|
{
|
|
++m_ipSocket.m_inCallbackCount;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline IpSocket::ScopedIsInCallback::~ScopedIsInCallback()
|
|
{
|
|
--m_ipSocket.m_inCallbackCount;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename SOCKET_TYPE>
|
|
typename SOCKET_TYPE::Stats IpSocket::Stats::Get(const SOCKET_TYPE &socket)
|
|
{
|
|
const IpSocket &ipSocket = socket;
|
|
ScopedMutexLocker scopedMutexLocker(ipSocket.m_pMutex);
|
|
|
|
return typename SOCKET_TYPE::Stats(socket);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
template<typename SOCKET_TYPE>
|
|
typename SOCKET_TYPE::Stats *IpSocket::Stats::Create(const SOCKET_TYPE &socket)
|
|
{
|
|
const IpSocket &ipSocket = socket;
|
|
ScopedMutexLocker scopedMutexLocker(ipSocket.m_pMutex);
|
|
|
|
return new typename SOCKET_TYPE::Stats(socket);
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_BASE_IP_IP_SOCKET_H)
|