Files
externals/linux/include/ActivMiddleware/ActivFramework/PostMessageHelper.h
T
2023-12-15 13:15:08 -05:00

848 lines
33 KiB
C++

/**
* @file include/ActivMiddleware/ActivFramework/PostMessageHelper.h
*
* @brief Header file for PostMessageHelper.
*/
#if (!defined ACTIV_FRAMEWORK_POST_MESSAGE_HELPER_H)
#define ACTIV_FRAMEWORK_POST_MESSAGE_HELPER_H
#include "ActivMiddleware/ActivFramework/External.h"
#include "ActivMiddleware/ActivFramework/Component.h"
#include "ActivMiddleware/ActivFramework/HeapMessage.h"
#include "ActivMiddleware/ActivBase/IniFileParser.h"
#include "ActivMiddleware/ActivBase/FieldTypes/UInt.h"
#include "ActivMiddleware/CxxYZ/memory.h"
//! Activ namespace.
namespace Activ
{
class EndPoint;
class SystemImpl;
class ManagedEndPointImpl;
/**
* @brief Helper class to post messages.
*
* This class provides a similar interface to the Component message posting functions. In addition,
* it will post multiple messages to a target endpoint in one go, saving multiple acquiring
* of locks, kernel transitions, etc.
*
* The intended use is when the processing of a single message will result in the sending of
* multiple messages. For example:
*
* MyComponent::ProcessMyMessage(heapMessage)
* {
* for (...)
* {
* HeapMessage heapMessage2;
* heapMessage2.Clone(heapMessage);
* m_postMessageHelper.PostMessage(*this, m_targetAddress, MY_TYPE, heapMessage2);
* }
* m_postMessageHelper.Flush();
* }
*
* The class is not thread-safe and is only intended to be used from a single thread.
*/
class PostMessageHelper : private Boost::noncopyable
{
public:
//! PostMessageHelper Flush() helper.
class ScopedFlush : private Boost::noncopyable
{
public:
/**
* @brief Constructor.
*
* @param postMessageHelper
*/
ScopedFlush(PostMessageHelper &postMessageHelper);
/**
* @brief Destructor.
*
* Calls Flush() on the PostMessageHelper passed to the constructor.
*/
~ScopedFlush();
private:
PostMessageHelper &m_postMessageHelper;
};
//! Scoped PostMessageHelper TryFlush() helper.
class ScopedTryFlush : private Boost::noncopyable
{
public:
/**
* @brief Constructor.
*
* @param postMessageHelper
*/
ScopedTryFlush(PostMessageHelper &postMessageHelper);
/**
* @brief Destructor.
*
* Calls TryFlush() on the PostMessageHelper passed to the constructor.
*/
~ScopedTryFlush();
private:
PostMessageHelper &m_postMessageHelper;
};
//! Settings.
class Settings
{
public:
//! Default constructor.
ACTIV_FRAMEWORK_API
Settings();
/**
* @brief Read settings from an ini-file section.
*
* @param sectionIterator
*
* @throw Exception
*/
ACTIV_FRAMEWORK_API
void Read(const IniFileParser::ConstSectionIterator &sectionIterator);
UInt m_maximumNumberOfFailedTryFlushes; ///< Default: 8. How many TryFlush() calls should fail before TryFlush() calls Flush() implicitly. Ini-file key: MaxFailedTryFlushes
UInt m_maximumNumberOfPostsBeforeImplicitFlush; ///< Default: undefined (no limit; otherwise implicitly Flush() or TryFlush() after this number of any PostMessage() calls). Ini-file key: MaxPostsBeforeFlush
bool m_shouldTryFlushAfterMaximumPosts; ///< Default: false (Flush() rather than TryFlush() when m_maximumNumberOfPostsBeforeImplicitFlush PostMessage()s have been called). Ini-file key: ShouldTryFlushAfterMaxPosts
bool m_shouldProcessEndPointsUntilFailureOnTryFlush; ///< Default: true. When true endpoint iteration during a TryFlush is repeated until none succeed or all are empty. Ini-file key: ProcessEndPointsUntilFailureOnTryFlush
};
//! Statistics.
class Statistics
{
public:
//! Default constructor.
ACTIV_FRAMEWORK_API
Statistics();
//! Reset.
ACTIV_FRAMEWORK_API
void Reset();
size_t m_numberOfForcedFlushesDuringTryFlush; ///< Number of times a TryFlush has resulted in a forced flush to an endpoint.
};
/**
* @brief Constructor.
*
* @param managedEndPoint the ManagedEndPoint containing all Components from which messages are to be sent.
*
* @throw Exception.
*/
ACTIV_FRAMEWORK_API
explicit PostMessageHelper(const ManagedEndPoint &managedEndPoint);
/**
* @brief Constructor.
*
* @param managedEndPoint the ManagedEndPoint containing all Components from which messages are to be sent.
* @param settings
*
* @throw Exception.
*/
ACTIV_FRAMEWORK_API
explicit PostMessageHelper(const ManagedEndPoint &managedEndPoint, const Settings &settings);
/**
* @brief Constructor.
*
* @param managedEndPoint the ManagedEndPoint containing all Components from which messages are to be sent.
* @param maximumNumberOfFailedTryFlushes how many TryFlush() calls should fail before TryFlush() calls Flush() implicitly.
*
* @throw Exception.
*/
ACTIV_FRAMEWORK_API
explicit PostMessageHelper(const ManagedEndPoint &managedEndPoint, const size_t maximumNumberOfFailedTryFlushes);
//! Destructor.
ACTIV_FRAMEWORK_API
~PostMessageHelper();
/**
* @brief Post an asynchronous request.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param requestId the message identification (to match up the response).
* @param messageBuilder reference to a MessageBuilder containing the message body to post.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
StatusCode PostRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, const MessageBuilder &messageBuilder);
/**
* @brief Post an asynchronous request.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param requestId the message identification (to match up the response).
* @param pRequest the request message buffer.
* @param requestLength the length of the request message buffer.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
StatusCode PostRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, const void *pRequest = ACTIV_NULLPTR, const size_t requestLength = 0);
/**
* @brief Post an asynchronous request.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param requestId the message identification (to match up the response).
* @param request the HeapMessage containing the request body.
*/
ACTIV_FRAMEWORK_API
void PostRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, HeapMessage &request);
/**
* @brief Send a synchronous request and wait for the response.
*
* If this returns STATUS_CODE_SUCCESS, the value of response.GetStatusCode()
* will contain the actual return status of the request (the return value from SendRequest() just
* determines whether the actual message transmission was successful).
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param messageBuilder reference to a MessageBuilder containing the message body to post.
* @param response HeapMessage to receive the response.
* @param timeout in milliseconds.
*
* @retval STATUS_CODE_SUCCESS a response has been received.
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
* @retval STATUS_CODE_TIMEOUT no response received in the timeout period.
*/
ACTIV_FRAMEWORK_API
StatusCode SendRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
const MessageBuilder &messageBuilder, HeapMessage &response, const TimeoutPeriod timeout = Component::defaultTimeout);
/**
* @brief Send a synchronous request and wait for the response.
*
* If this returns STATUS_CODE_SUCCESS, the value of response.GetStatusCode()
* will contain the actual return status of the request (the return value from SendRequest() just
* determines whether the actual message transmission was successful).
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param pRequest the request message buffer.
* @param requestLength the length of the request message buffer.
* @param response HeapMessage to receive the response.
* @param timeout in milliseconds.
*
* @retval STATUS_CODE_SUCCESS a response has been received.
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
* @retval STATUS_CODE_TIMEOUT no response received in the timeout period.
*/
ACTIV_FRAMEWORK_API
StatusCode SendRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
const void *pRequest, const size_t requestLength, HeapMessage &response,
const TimeoutPeriod timeout = Component::defaultTimeout);
/**
* @brief Send a synchronous request and wait for the response.
*
* If this returns STATUS_CODE_SUCCESS, the value of request.GetStatusCode()
* will contain the actual return status of the request (the return value from SendRequest() just
* determines whether the actual message transmission was successful).
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param request the request message and container for the response. If request is an empty HeapMessage, a
* request will be sent with no message body.
* @param timeout in milliseconds.
*
* @retval STATUS_CODE_SUCCESS a response has been received.
* @retval STATUS_CODE_HEAP_EMPTY if request was empty and no message could be allocated for the outgoing request.
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
* @retval STATUS_CODE_TIMEOUT no response received in the timeout period.
*/
ACTIV_FRAMEWORK_API
StatusCode SendRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
HeapMessage &request, const TimeoutPeriod timeout = Component::defaultTimeout);
/**
* @brief Send a synchronous request but do not wait for the response.
*
* If this returns STATUS_CODE_SUCCESS, the response can be obtained by calling syncRequestId.GetResponse().
* The actual return status of the request can then be obtained by GetStatusCode() on the message returned from
* syncRequestId.GetResponse().
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param syncRequestId reference to a SyncRequestId object that can be used later to wait (or poll) for the response.
* @param messageBuilder reference to a MessageBuilder containing the message body to post.
*
* @retval STATUS_CODE_SUCCESS the request was sent successfully.
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
ACTIV_FRAMEWORK_API
StatusCode SendRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
SyncRequestId &syncRequestId, const MessageBuilder &messageBuilder);
/**
* @brief Send a synchronous request but do not wait for the response.
*
* If this returns STATUS_CODE_SUCCESS, the response can be obtained by calling syncRequestId.GetResponse().
* The actual return status of the request can then be obtained by GetStatusCode() on the message returned from
* syncRequestId.GetResponse().
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param syncRequestId reference to a SyncRequestId object that can be used later to wait (or poll) for the response.
* @param pRequest the request message buffer.
* @param requestLength the length of the request message buffer.
*
* @retval STATUS_CODE_SUCCESS the request was sent successfully.
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
ACTIV_FRAMEWORK_API
StatusCode SendRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
SyncRequestId &syncRequestId, const void *pRequest, const size_t requestLength);
/**
* @brief Send a synchronous request but do not wait for the response.
*
* If this returns STATUS_CODE_SUCCESS, the response can be obtained by calling syncRequestId.GetResponse().
* The actual return status of the request can then be obtained by GetStatusCode() on the message returned from
* syncRequestId.GetResponse().
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param requestType the request type.
* @param syncRequestId reference to a SyncRequestId object that can be used later to wait (or poll) for the response.
* @param request the request message. If request is an empty HeapMessage, a
* request will be sent with no message body.
*
* @retval STATUS_CODE_SUCCESS the request was sent successfully.
* @retval STATUS_CODE_HEAP_EMPTY if request was empty and no message could be allocated for the outgoing request.
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
ACTIV_FRAMEWORK_API
StatusCode SendRequest(const Component &component, const Address &destinationAddress, const MessageType requestType,
SyncRequestId &syncRequestId, HeapMessage &request);
/**
* @brief Post a response to a request.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address (the source address of the request).
* @param requestType the request type.
* @param requestId the message identification (to match up the response).
* @param responseStatus the response status.
* @param messageBuilder reference to a MessageBuilder containing the message body to post.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
StatusCode PostResponse(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, const StatusCode responseStatus, const MessageBuilder &messageBuilder);
/**
* @brief Post a response to a request.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address (the source address of the request).
* @param requestType the request type.
* @param requestId the message identification (to match up the response).
* @param responseStatus the response status.
* @param pResponse the response message buffer.
* @param responseLength the length of the response message buffer.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
StatusCode PostResponse(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, const StatusCode responseStatus, const void *pResponse = ACTIV_NULLPTR,
const size_t responseLength = 0);
/**
* @brief Post a response to a request. Use this call when the response message is a newly allocated
* HeapMessage and is not the original request.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address (the source address of the request).
* @param requestType the request type.
* @param requestId the message identification (to match up the response).
* @param responseStatus the response status.
* @param response the response message.
*/
ACTIV_FRAMEWORK_API
void PostResponse(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, const StatusCode responseStatus, HeapMessage &response);
/**
* @brief Post a response to a request where the request HeapMessage still has the original request id
* and message type of the request. The contents of the request HeapMessage are overridden with
* the provided MessageBuilder contents.
*
* @param component reference to the Component to post from.
* @param responseStatus the response status.
* @param request the original request.
* @param messageBuilder reference to a MessageBuilder containing the message body to post.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
StatusCode PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request,
const MessageBuilder &messageBuilder);
/**
* @brief Post a response to a request where the request HeapMessage still has the original request id
* and message type of the request. The contents of the request HeapMessage are overridden with
* the provided buffer.
*
* @param component reference to the Component to post from.
* @param responseStatus the response status.
* @param request the original request.
* @param pResponse the response message buffer.
* @param responseLength the length of the response message buffer.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
* @retval STATUS_CODE_INVALID_ENDPOINT the destination endpoint does not exist.
* @retval STATUS_CODE_DISABLED the endpoint is not accepting messages.
*/
StatusCode PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request,
const void *pResponse, const size_t responseLength);
/**
* @brief Post a response to a request where the request HeapMessage still has the original request id
* and message type of the request. The provided response HeapMessage contains the response body.
*
* @param component reference to the Component to post from.
* @param responseStatus the response status.
* @param request the original request.
* @param response a second HeapMessage containing the response body.
*/
void PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request, HeapMessage &response);
/**
* @brief Post a response to a request where the original request message has been filled in with the response.
* All other members of the response message must be as received (request id, type, addresses).
*
* @param component reference to the Component to post from.
* @param responseStatus the response status.
* @param request the original request message filled in with the response data.
*/
ACTIV_FRAMEWORK_API
void PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request);
/**
* @brief Post an empty response to a request. The response will be sent to the source address of the request.
*
* If replying to a request and the contents of the response are unimportant, it is preferable to use PostEmptyResponse()
* as if the request was made remotely, there will be no serializing of message body over the network.
*
* @param component reference to the Component to post from.
* @param responseStatus the response status.
* @param request the original request message. Any data in the message is truncated.
*/
void PostEmptyResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request);
/**
* @brief Post an empty response to a request. Use this call when the response message is a newly allocated
* HeapMessage and is not the original request.
*
* If replying to a request and the contents of the response are unimportant, it is preferable to use PostEmptyResponse()
* as if the request was made remotely, there will be no serializing of message body over the network.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address (the source address of the original request).
* @param requestType the request type of the original request.
* @param requestId the message identification (to match up the response).
* @param responseStatus the response status.
* @param response the response message. Data will be truncated.
*/
void PostEmptyResponse(const Component &component, const Address &destinationAddress, const MessageType requestType,
const RequestId &requestId, const StatusCode responseStatus, HeapMessage &response);
/**
* @brief Post a message, setting destination address and type.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param messageType the message type.
* @param messageBuilder reference to a MessageBuilder containing the message body to post.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
*/
StatusCode PostMessage(const Component &component, const Address &destinationAddress, const MessageType messageType,
const MessageBuilder &messageBuilder);
/**
* @brief Post a message, setting destination address and type.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param messageType the message type.
* @param pMessage the message buffer.
* @param messageLength the length of the message buffer.
*
* @retval STATUS_CODE_SUCCESS
* @retval STATUS_CODE_HEAP_EMPTY
*/
StatusCode PostMessage(const Component &component, const Address &destinationAddress, const MessageType messageType,
const void *pMessage = ACTIV_NULLPTR, const size_t messageLength = 0);
/**
* @brief Post a message, setting destination address and type.
*
* @param component reference to the Component to post from.
* @param destinationAddress the target address.
* @param messageType the message type.
* @param message the message.
*/
ACTIV_FRAMEWORK_API
void PostMessage(const Component &component, const Address &destinationAddress, const MessageType messageType,
HeapMessage &message);
/**
* @brief Post a fully initialized message (type, src, dest addresses set as appropriate).
*
* @param heapMessage the message.
*/
ACTIV_FRAMEWORK_API
void PostMessage(HeapMessage &heapMessage);
//! Flush the queued messages to their target endpoints.
ACTIV_FRAMEWORK_API
void Flush();
/**
* @brief Try to flush the queued messages to their target endpoints.
*
* If unable to acquire the mutex protecting each target endpoint, messages are left queued in this object (the
* intention being that a later TryFlush() call will likely succeed).
*
* @return true if there is no data queued in this object.
*/
ACTIV_FRAMEWORK_API
bool TryFlush();
/**
* @brief Is the object empty?
*
* @return True if no messages are cached waiting to be flushed.
*/
bool IsEmpty() const;
//! Get statistics.
const Statistics &GetStatistics() const;
//! Reset statistics.
void ResetStatistics();
private:
//! Settings derived from those provided to the constructor.
class PrivateSettings
{
public:
PrivateSettings(const Settings &settings);
PrivateSettings(const size_t maximumNumberOfFailedTryFlushes);
size_t m_maximumNumberOfFailedTryFlushes;
size_t m_maximumNumberOfPostsBeforeImplicitFlush;
bool m_shouldTryFlushAfterMaximumPosts;
bool m_shouldProcessEndPointsUntilFailureOnTryFlush;
};
//! Info stored per endpoint.
class Info
{
public:
Info();
~Info();
CxxYZ::shared_ptr<EndPoint> m_pEndPoint;
size_t m_failedTryFlushCount;
bool m_isInUse;
};
/**
* @brief Extend lists and create local endpoint.
*
* @param endPointId
*
* @return IEndPoint.
*/
EndPoint *ExtendLists(const EndPointId endPointId);
/**
* @brief Create local endpoint.
*
* @param endPointId
* @param info
*
* @return IEndPoint.
*/
EndPoint *CreateLocalEndPoint(const EndPointId endPointId, Info &info);
/**
* @brief Add an endpoint id to the lists of in-use endpoints.
*
* @param endPointId
* @param info
*/
void AddEndPointIdToInUseList(const EndPointId endPointId, Info &info);
/**
* @brief Post a response message to an endpoint.
*
* This overrides the destination address if RequestId::ATTRIBUTE_USE_RESPONSE_ADDRESS is set in @a response.
*
* @param component reference to the Component to post from.
* @param response
*/
void PostResponse(const Component &component, HeapMessage &response);
/**
* @brief Flush a local endpoint before a sync call to that endpoint.
*
* @param endPointId if the target endpoint's local endpoint to flush. Range checked.
*/
void PreSyncFlush(const EndPointId endPointId);
/**
* @brief Flush a local endpoint.
*
* @param endPointId if the target endpoint's local endpoint to flush.
* @param info Info for @a endPointId.
*/
void InternalFlush(const EndPointId endPointId, Info &info);
typedef std::vector<Info> InfoList;
typedef std::vector<EndPointId> EndPointIdList;
const ManagedEndPointImpl & m_managedEndPointImpl;
SystemImpl & m_systemImpl;
const PrivateSettings m_settings;
InfoList m_infoList;
size_t m_infoListSize;
EndPointIdList m_endPointIdList;
EndPointIdList m_failedFlushEndPointIdList;
size_t m_numberOfUnflushedPosts;
Statistics m_statistics;
friend class ManagedEndPointImpl;
};
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostRequest(const Component &component, const Address &destinationAddress,
const MessageType requestType, const RequestId &requestId, const MessageBuilder &messageBuilder)
{
return PostRequest(component, destinationAddress, requestType, requestId, messageBuilder.GetMessage(),
messageBuilder.GetLength());
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostRequest(const Component &component, const Address &destinationAddress,
const MessageType requestType, const RequestId &requestId, const void *pRequest, const size_t requestLength)
{
HeapMessage request(*component.GetHeap(), pRequest, requestLength);
if (ACTIV_UNLIKELY(!request))
return STATUS_CODE_HEAP_EMPTY;
PostRequest(component, destinationAddress, requestType, requestId, request);
return STATUS_CODE_SUCCESS;
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostResponse(const Component &component, const Address &destinationAddress,
const MessageType requestType, const RequestId &requestId, const StatusCode responseStatus,
const MessageBuilder &messageBuilder)
{
return PostResponse(component, destinationAddress, requestType, requestId, responseStatus, messageBuilder.GetMessage(),
messageBuilder.GetLength());
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostResponse(const Component &component, const Address &destinationAddress,
const MessageType requestType, const RequestId &requestId, const StatusCode responseStatus, const void *pResponse,
const size_t responseLength)
{
HeapMessage response(*component.GetHeap(), pResponse, responseLength);
if (!response)
return STATUS_CODE_HEAP_EMPTY;
PostResponse(component, destinationAddress, requestType, requestId, responseStatus, response);
return STATUS_CODE_SUCCESS;
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request,
const MessageBuilder &messageBuilder)
{
return PostResponse(component, responseStatus, request, messageBuilder.GetMessage(), messageBuilder.GetLength());
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request,
const void *pResponse, const size_t responseLength)
{
HeapMessage response(*component.GetHeap(), pResponse, responseLength);
if (!response)
return STATUS_CODE_HEAP_EMPTY;
PostResponse(component, responseStatus, request, response);
return STATUS_CODE_SUCCESS;
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline void PostMessageHelper::PostResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request,
HeapMessage &response)
{
PostResponse(component, request.GetSourceAddress(), request.GetType(), request.GetRequestId(), responseStatus, response);
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline void PostMessageHelper::PostEmptyResponse(const Component &component, const StatusCode responseStatus, HeapMessage &request)
{
request.SetLength(0);
PostResponse(component, responseStatus, request);
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline void PostMessageHelper::PostEmptyResponse(const Component &component, const Address &destinationAddress,
const MessageType requestType, const RequestId &requestId, const StatusCode responseStatus, HeapMessage &response)
{
response.SetLength(0);
PostResponse(component, destinationAddress, requestType, requestId, responseStatus, response);
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostMessage(const Component &component, const Address &destinationAddress,
const MessageType messageType, const MessageBuilder &messageBuilder)
{
return PostMessage(component, destinationAddress, messageType, messageBuilder.GetMessage(), messageBuilder.GetLength());
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline StatusCode PostMessageHelper::PostMessage(const Component &component, const Address &destinationAddress,
const MessageType messageType, const void *pMessage, const size_t messageLength)
{
HeapMessage message(*component.GetHeap(), pMessage, messageLength);
if (ACTIV_UNLIKELY(!message))
return STATUS_CODE_HEAP_EMPTY;
PostMessage(component, destinationAddress, messageType, message);
return STATUS_CODE_SUCCESS;
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline bool PostMessageHelper::IsEmpty() const
{
return m_endPointIdList.empty();
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline const PostMessageHelper::Statistics &PostMessageHelper::GetStatistics() const
{
return m_statistics;
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline void PostMessageHelper::ResetStatistics()
{
return m_statistics.Reset();
}
// ---------------------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------------------
inline PostMessageHelper::ScopedFlush::ScopedFlush(PostMessageHelper &postMessageHelper) :
m_postMessageHelper(postMessageHelper)
{
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline PostMessageHelper::ScopedFlush::~ScopedFlush()
{
m_postMessageHelper.Flush();
}
// ---------------------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------------------------------------
inline PostMessageHelper::ScopedTryFlush::ScopedTryFlush(PostMessageHelper &postMessageHelper) :
m_postMessageHelper(postMessageHelper)
{
}
// ---------------------------------------------------------------------------------------------------------------------------------
inline PostMessageHelper::ScopedTryFlush::~ScopedTryFlush()
{
m_postMessageHelper.TryFlush();
}
} // namespace Activ
#endif // (!defined ACTIV_FRAMEWORK_POST_MESSAGE_HELPER_H)