Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//--------------------------------------------------------------------------------------------------
/**
* Handles ACK returned for every data pushed
*/
//--------------------------------------------------------------------------------------------------
static void PushCallBackHandler
(
lwm2mcore_AckResult_t result,
uint16_t mid
)
{
LE_INFO("Push callback mid: %d", mid);
le_avdata_PushStatus_t status;
if (result == LWM2MCORE_ACK_RECEIVED)
{
status = LE_AVDATA_PUSH_SUCCESS;
}
else
{
status = LE_AVDATA_PUSH_FAILED;
}
le_dls_Link_t* linkPtr = le_dls_Peek(&PushDataList);
// Return callback with associated message id
while (linkPtr != NULL)
{
PushData_t* pDataPtr = CONTAINER_OF(linkPtr, PushData_t, link);
if (pDataPtr->mid == mid)
{
le_avdata_CallbackResultFunc_t handlerPtr = pDataPtr->handlerPtr;
if (handlerPtr != NULL)
{
handlerPtr(status, pDataPtr->callbackContextPtr);
}
le_dls_Remove(&PushDataList, linkPtr);
le_mem_Release(pDataPtr);
linkPtr = NULL;
IsPushing = false;
break;
}
linkPtr = le_dls_PeekNext(&PushDataList, linkPtr);
}
// Try sending the next queued item
linkPtr = NULL;
linkPtr = le_dls_Peek(&PushDataList);
while (linkPtr != NULL)
{
PushData_t* pDataPtr = CONTAINER_OF(linkPtr, PushData_t, link);
if (!pDataPtr->isSent)
{
uint16_t mid = 0;
le_result_t result;
result = avcClient_Push(pDataPtr->buffer,
pDataPtr->bufferLength,
pDataPtr->contentType,
&mid);
// Send was successful, otherwise we need to keep it in the queue until next try
if (result == LE_OK)
{
pDataPtr->mid = mid;
IsPushing = true;
}
break;
}
linkPtr = le_dls_PeekNext(&PushDataList, linkPtr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.