Add argument to continuous fragment mode callback (#260)

* Add argument to continuous fragment mode callback

* Update example

* Fix

* Fix

* Uncrustify
This commit is contained in:
Pablo Garrido 2021-07-26 11:00:31 +02:00 committed by GitHub
parent 2693d83bd9
commit 4ccec07f40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 13 deletions

View File

@ -23,8 +23,10 @@
#define BUFFER_SIZE 100 * STREAM_HISTORY
bool flush_session(
uxrSession* session)
uxrSession* session,
void* args)
{
(void) args;
return uxr_run_session_until_confirm_delivery(session, 1000);
}
@ -115,7 +117,7 @@ int main(
memset(buf, 'A', sizeof(buf));
ucdrBuffer ub;
uxr_prepare_output_stream_fragmented(&session, reliable_out, datawriter_id, &ub, sizeof(buf), flush_session);
uxr_prepare_output_stream_fragmented(&session, reliable_out, datawriter_id, &ub, sizeof(buf), flush_session, NULL);
ucdr_serialize_array_char(&ub, buf, sizeof(buf));
uxr_run_session_until_confirm_delivery(&session, 1000);

View File

@ -138,7 +138,8 @@ typedef void (* uxrOnReplyFunc) (
* @param session Session structure related to the buffer to be flushed.
*/
typedef bool (* uxrOnBuffersFull) (
struct uxrSession* session);
struct uxrSession* session,
void* args);
#ifdef PERFORMANCE_TESTING
/**
@ -156,6 +157,7 @@ typedef void (* uxrOnPerformanceFunc) (
typedef struct uxrContinuousArgs
{
uxrOnBuffersFull flush_callback;
void* flush_callback_args;
uxrStreamId stream_id;
size_t data_size;
} uxrContinuousArgs;

View File

@ -116,12 +116,13 @@ UXRDLLAPI uint16_t uxr_prepare_output_stream(
* The submessage will be sent when `uxr_flash_output_stream` or `uxr_run_session` function are called.
* This function handles the buffer flush by means of `uxrOnBuffersFull` callback.
* As a result of the reception of this submessage, the Agent will write a topic into the DDS Global-Data-Space.
* @param session A uxrSession structure previously initialized.
* @param stream_id The output stream identifier where the WRITE_DATA submessage will be buffered.
* @param datawriter_id The identifier of the XRCE DataWriter that will write the topic into the DDS GDS.
* @param ub The ucdrBuffer structure used for serializing the topic.
* @param data_size The size of the topic in bytes.
* @param flush_callback Callback that is call by the library when user should flush output buffers.
* @param session A uxrSession structure previously initialized.
* @param stream_id The output stream identifier where the WRITE_DATA submessage will be buffered.
* @param datawriter_id The identifier of the XRCE DataWriter that will write the topic into the DDS GDS.
* @param ub The ucdrBuffer structure used for serializing the topic.
* @param data_size The size of the topic in bytes.
* @param flush_callback Callback that is call by the library when user should flush output buffers.
* @param flush_callback_args Arguments passed to flush callback.
* @return A `request_id` that identifies the XRCE request made by the Entity.
* This could be used in the `uxr_run_session_until_one_status` or `uxr_run_session_until_all_status` functions.
* */
@ -132,7 +133,8 @@ UXRDLLAPI uint16_t uxr_prepare_output_stream_fragmented(
uxrObjectId datawriter_id,
ucdrBuffer* ub,
size_t data_size,
uxrOnBuffersFull flush_callback);
uxrOnBuffersFull flush_callback,
void* flush_callback_args);
/** @}*/

View File

@ -158,7 +158,7 @@ bool on_full_output_buffer_fragmented(
if (0 == remaining_blocks)
{
if (!local_args->flush_callback(session) ||
if (!local_args->flush_callback(session, local_args->flush_callback_args) ||
0 == (remaining_blocks = get_available_free_slots(stream)))
{
return true;
@ -208,7 +208,8 @@ uint16_t uxr_prepare_output_stream_fragmented(
uxrObjectId entity_id,
ucdrBuffer* ub,
size_t data_size,
uxrOnBuffersFull flush_callback)
uxrOnBuffersFull flush_callback,
void* flush_callback_args)
{
uint16_t rv = UXR_INVALID_REQUEST_ID;
UXR_LOCK_STREAM_ID(session, stream_id);
@ -226,7 +227,7 @@ uint16_t uxr_prepare_output_stream_fragmented(
if (0 == remaining_blocks)
{
if (!flush_callback(session) ||
if (!flush_callback(session, flush_callback_args) ||
0 == (remaining_blocks = get_available_free_slots(stream)))
{
return rv;
@ -289,6 +290,7 @@ uint16_t uxr_prepare_output_stream_fragmented(
session->continuous_args.stream_id = stream_id;
session->continuous_args.data_size = user_required_space;
session->continuous_args.flush_callback = flush_callback;
session->continuous_args.flush_callback_args = flush_callback_args;
ucdr_set_on_full_buffer_callback(ub, on_full_output_buffer_fragmented, session);
return rv;