106 lines
3.5 KiB
C++
106 lines
3.5 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivFramework/ISocketEventManagee.h
|
|
*
|
|
* @brief Header file for ISocketEventManagee and derived classes.
|
|
*/
|
|
|
|
#if (!defined ACTIV_FRAMEWORK_I_SOCKET_EVENT_MANAGEE_H)
|
|
#define ACTIV_FRAMEWORK_I_SOCKET_EVENT_MANAGEE_H
|
|
|
|
#include "ActivMiddleware/ActivFramework/External.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/Ip/IpAddress.h"
|
|
#include "ActivMiddleware/ActivBase/Ip/UdpDatagramInfo.h"
|
|
#include "ActivMiddleware/CxxYZ/functional.h"
|
|
#include "ActivMiddleware/Misc/CrtHelper.h"
|
|
|
|
#include ACTIV_BOOST_INCLUDE(smart_ptr/intrusive_ptr.hpp)
|
|
#include ACTIV_BOOST_INCLUDE(smart_ptr/intrusive_ref_counter.hpp)
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
// Forward declarations.
|
|
class IpAddress;
|
|
class ManagedEndPoint;
|
|
|
|
// Declare smart pointer.
|
|
class ISocketEventManagee;
|
|
typedef Boost::intrusive_ptr<ISocketEventManagee> ISocketEventManageePointer;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Interface class to hook a local datagram socket in to an endpoint's EventManager.
|
|
*
|
|
* If there is intention to destroy a ISocketEventManagee inside the context of the OnEvents() callback, then it should be
|
|
* referenced counted with ISocketEventManageePointer.
|
|
*/
|
|
class ISocketEventManagee : public Boost::intrusive_ref_counter<ISocketEventManagee, Boost::thread_unsafe_counter>
|
|
{
|
|
public:
|
|
//! OnDatagram callback function definition.
|
|
typedef UdpDatagramCallbackFunction CallbackFunction;
|
|
|
|
/**
|
|
* @brief Create a ISocketEventManagee.
|
|
*
|
|
* @param managedEndPoint
|
|
* @param callbackFunction
|
|
* @param socket the socket handle to process events on. This will be cloned.
|
|
* @param maximumReadBytes the maximum number of bytes to read from the socket in one event. 0 for no limit.
|
|
*
|
|
* @return A pointer to the ISocketEventManagee, always valid.
|
|
*
|
|
* @throw StatusCodeException
|
|
*/
|
|
ACTIV_FRAMEWORK_API static ISocketEventManageePointer Create(ManagedEndPoint &managedEndPoint,
|
|
const CallbackFunction &callbackFunction, const SOCKET socket, const size_t maximumReadBytes);
|
|
|
|
//! Destructor.
|
|
ACTIV_FRAMEWORK_API virtual ~ISocketEventManagee();
|
|
|
|
/**
|
|
* @brief Initiate a read on the socket.
|
|
*
|
|
* The socket receive buffer is emptied first (without invoking OnDatagram()). This is to avoid issues with receive buffer
|
|
* overflows between socket creation and calling this function (which might cause retransmissions, for example).
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or an error value.
|
|
*/
|
|
ACTIV_FRAMEWORK_API virtual StatusCode InitiateRead() = 0;
|
|
|
|
/**
|
|
* @brief Do a blocking send of some data to a specified ip address.
|
|
*
|
|
* @param ipAddress destination ip address.
|
|
* @param pData pointer to data to send.
|
|
* @param dataLength length of data to send.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or an error value.
|
|
*/
|
|
ACTIV_FRAMEWORK_API virtual StatusCode PostData(const IpAddress &ipAddress, const void * const pData,
|
|
const size_t dataLength) = 0;
|
|
|
|
//! Get the source IpAddress.
|
|
const IpAddress &GetSourceIpAddress() const;
|
|
|
|
//! Is timestamping enabled?
|
|
ACTIV_FRAMEWORK_API virtual bool IsTimeStampingEnabled() const = 0;
|
|
|
|
protected:
|
|
UdpDatagramInfo m_udpDatagramInfo;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const IpAddress &ISocketEventManagee::GetSourceIpAddress() const
|
|
{
|
|
return m_udpDatagramInfo.m_sourceIpAddress;
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_FRAMEWORK_I_SOCKET_EVENT_MANAGEE_H)
|