<commit_before>/**
 *  @file ARNETWORK_IOBuffer.c
 *  @brief input or output buffer, used by ARNetwork_Receiver or ARNetwork_Sender
 *  @date 28/09/2012
 *  @author <EMAIL>
**/

/*****************************************
 * 
 *             include file :
 *
******************************************/

#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <libARSAL/ARSAL_Print.h>
#include <libARSAL/ARSAL_Mutex.h>

#include <libARNetwork/ARNETWORK_Error.h>
#include "ARNETWORK_RingBuffer.h"
#include <libARNetwork/ARNETWORK_Frame.h>
#include "ARNETWORK_DataDescriptor.h"
#include <libARNetwork/ARNETWORK_Manager.h>
#include "ARNETWORK_IOBuffer.h"

/*****************************************
 * 
 *             define :
 *
******************************************/

#define ARNETWORK_IOBUFFER_TAG "ARNETWORK_IOBuffer"

/**
 *  @brief free the data pointed by the data descriptor
 *  @param IOBufferPtr Pointer on the IOBuffer
 *  @param dataDescriptorPtr Pointer on the data descriptor of the data to free
 *  @return error equal to ARNETWORK_OK if the data are correctly deleted otherwise see eARNETWORK_ERROR
**/
static inline eARNETWORK_ERROR ARNETWORK_IOBuffer_FreeData(ARNETWORK_IOBuffer_t *IOBufferPtr, ARNETWORK_DataDescriptor_t *dataDescriptorPtr)
{
    /** -- free the last data of the IOBuffer -- */
    
    /** local declarations */
    eARNETWORK_ERROR error = ARNETWORK_OK;
    
    if(dataDescriptorPtr->isUsingDataCopy)
    {
        /** if the data has been copied in the dataCopyRBuffer */
        /** pop data copy*/
        error = ARNETWORK_RingBuffer_PopFrontWithSize(IOBufferPtr->dataCopyRBufferPtr, NULL, dataDescriptorPtr->dataSize);
    }
    else
    {
        /** if the data is store out of the ARNetwork */
        /** callback with free status */
        if(dataDescriptorPtr->callback != NULL)
        {
            dataDescriptorPtr->callback(IOBufferPtr->ID, dataDescriptorPtr->dataPtr, dataDescriptorPtr->customData, ARNETWORK_MANAGER_CALLBACK_STATUS_FREE);
        }
    }
    
    return error;
}

/*****************************************
 * 
 *             implementation :
 *
******************************************/

ARNETWORK_IOBuffer_t* ARNETWORK_IOBuffer_New(const ARNETWORK_IOBufferParam_t *paramPtr)
{
    /** -- Create a new input or output buffer -- */
    
    /** local declarations */
    ARNETWORK_IOBuffer_t *IOBufferPtr = NULL;
    eARNETWORK_ERROR error = ARNETWORK_OK;
    
    /** Create the input or output buffer in accordance with parameters set in the ARNETWORK_IOBufferParam_t */
    IOBufferPtr = malloc( sizeof(ARNETWORK_IOBuffer_t) );
    
    if(IOBufferPtr != NULL)
    {
        /** Initialize to default values */
        IOBufferPtr->dataDescriptorRBufferPtr = NULL;
        IOBufferPtr->dataCopyRBufferPtr = NULL;
        ARSAL_Mutex_InitWithType(&(IOBufferPtr->mutex), ARSAL_MUTEX_TYPE_ERRORCHECK);
        ARSAL_Sem_Init(&(IOBufferPtr->outputSem), 0, 0);
        
        if(ARNETWORK_IOBufferParam_Check(paramPtr))
        {<commit_msg>- Remove initialization of the IOBuffer mutex with type<commit_after>/**
 *  @file ARNETWORK_IOBuffer.c
 *  @brief input or output buffer, used by ARNetwork_Receiver or ARNetwork_Sender
 *  @date 28/09/2012
 *  @author <EMAIL>
**/

/*****************************************
 * 
 *             include file :
 *
******************************************/

#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <libARSAL/ARSAL_Print.h>
#include <libARSAL/ARSAL_Mutex.h>

#include <libARNetwork/ARNETWORK_Error.h>
#include "ARNETWORK_RingBuffer.h"
#include <libARNetwork/ARNETWORK_Frame.h>
#include "ARNETWORK_DataDescriptor.h"
#include <libARNetwork/ARNETWORK_Manager.h>
#include "ARNETWORK_IOBuffer.h"

/*****************************************
 * 
 *             define :
 *
******************************************/

#define ARNETWORK_IOBUFFER_TAG "ARNETWORK_IOBuffer"

/**
 *  @brief free the data pointed by the data descriptor
 *  @param IOBufferPtr Pointer on the IOBuffer
 *  @param dataDescriptorPtr Pointer on the data descriptor of the data to free
 *  @return error equal to ARNETWORK_OK if the data are correctly deleted otherwise see eARNETWORK_ERROR
**/
static inline eARNETWORK_ERROR ARNETWORK_IOBuffer_FreeData(ARNETWORK_IOBuffer_t *IOBufferPtr, ARNETWORK_DataDescriptor_t *dataDescriptorPtr)
{
    /** -- free the last data of the IOBuffer -- */
    
    /** local declarations */
    eARNETWORK_ERROR error = ARNETWORK_OK;
    
    if(dataDescriptorPtr->isUsingDataCopy)
    {
        /** if the data has been copied in the dataCopyRBuffer */
        /** pop data copy*/
        error = ARNETWORK_RingBuffer_PopFrontWithSize(IOBufferPtr->dataCopyRBufferPtr, NULL, dataDescriptorPtr->dataSize);
    }
    else
    {
        /** if the data is store out of the ARNetwork */
        /** callback with free status */
        if(dataDescriptorPtr->callback != NULL)
        {
            dataDescriptorPtr->callback(IOBufferPtr->ID, dataDescriptorPtr->dataPtr, dataDescriptorPtr->customData, ARNETWORK_MANAGER_CALLBACK_STATUS_FREE);
        }
    }
    
    return error;
}

/*****************************************
 * 
 *             implementation :
 *
******************************************/

ARNETWORK_IOBuffer_t* ARNETWORK_IOBuffer_New(const ARNETWORK_IOBufferParam_t *paramPtr)
{
    /** -- Create a new input or output buffer -- */
    
    /** local declarations */
    ARNETWORK_IOBuffer_t *IOBufferPtr = NULL;
    eARNETWORK_ERROR error = ARNETWORK_OK;
    
    /** Create the input or output buffer in accordance with parameters set in the ARNETWORK_IOBufferParam_t */
    IOBufferPtr = malloc( sizeof(ARNETWORK_IOBuffer_t) );
    
    if(IOBufferPtr != NULL)
    {
        /** Initialize to default values */
        IOBufferPtr->dataDescriptorRBufferPtr = NULL;
        IOBufferPtr->dataCopyRBufferPtr = NULL;
        ARSAL_Mutex_Init(&(IOBufferPtr->mutex));
        ARSAL_Sem_Init(&(IOBufferPtr->outputSem), 0, 0);
        
        if(ARNETWORK_IOBufferParam_Check(paramPtr))
        {
{'fraction_non_alphanumeric': 0.17037403196572748, 'fraction_numerical': 0.0032954358213873785, 'mean_word_length': 3.6089597570235386, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1754152', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1795, 'n_words': 401}