CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
internal.c File Reference

This file contains internal definitions and implementation used with the SDK that is not part of the API. More...

#include "internal.h"
#include <arpa/inet.h>
#include <inttypes.h>
#include <stdarg.h>
#include <string.h>
#include "adapter_api.h"
#include "adapter_control_interface.h"
#include "cdi_baseline_profile_01_00_api.h"
#include "cdi_baseline_profile_02_00_api.h"
#include "cdi_logger_api.h"
#include "cdi_utility_api.h"
#include "endpoint_manager.h"
#include "fifo_api.h"
#include "internal_tx.h"
#include "internal_rx.h"
#include "statistics.h"

Functions

static CDI_THREAD SystemMonitorThread (void *ptr)
 
static CDI_THREAD AppCallbackPayloadThread (void *ptr)
 
static void ConnectionShutdownInternal (CdiConnectionHandle handle)
 
static void AdapterShutdownInternal (CdiAdapterHandle handle)
 
static void CleanupGlobalResources (void)
 Cleanup global resources. NOTE: Caller must have acquired mutex_lock.
 
CdiReturnStatus CdiGlobalInitialization (const CdiCoreConfigData *core_config_ptr)
 
int CdiGatherInternal (const CdiSgList *sgl_ptr, int offset, void *dest_data_ptr, int byte_count)
 
CdiReturnStatus AdapterInitializeInternal (CdiAdapterData *adapter_data_ptr, CdiAdapterHandle *ret_handle_ptr)
 
CdiReturnStatus NetworkAdapterDestroyInternal (CdiAdapterHandle handle)
 
CdiReturnStatus ConnectionCommonResourcesCreate (CdiConnectionHandle handle, CdiCoreStatsCallback stats_cb_ptr, CdiUserCbParameter stats_user_cb_param, const CdiStatsConfigData *stats_config_ptr)
 
void ConnectionCommonResourcesDestroy (CdiConnectionHandle handle)
 
CdiReturnStatus ConnectionCommonPacketMessageThreadCreate (CdiConnectionHandle handle, const char *thread_name)
 
CdiReturnStatus CoreStatsConfigureInternal (CdiConnectionHandle handle, const CdiStatsConfigData *new_config_ptr, bool force_changes)
 
void PayloadErrorSet (CdiConnectionState *con_state_ptr, AppPayloadCallbackData *app_cb_data_ptr, CdiReturnStatus status_code, const char *format_str,...)
 
void PayloadErrorFreeBuffer (CdiPoolHandle pool_handle, AppPayloadCallbackData *app_cb_data_ptr)
 
void ConnectionDestroyInternal (CdiConnectionHandle handle)
 
void EndpointDestroyInternal (CdiEndpointHandle handle)
 
CdiReturnStatus SdkShutdownInternal (void)
 
bool FreeSglEntries (CdiPoolHandle pool_handle, CdiSglEntry *sgl_entry_head_ptr)
 
void DumpPayloadConfiguration (const CdiCoreExtraData *core_extra_data_ptr, int extra_data_size, const uint8_t *extra_data_array, CdiConnectionProtocolType protocol_type)
 
void BytesToHexString (const void *data_ptr, int data_byte_count, char *dest_buffer_str, int dest_buffer_size)
 
void DeviceGidToString (const uint8_t *device_gid_ptr, int gid_length, char *dest_buffer_str, int dest_buffer_size)
 
void SdkThreadJoin (CdiThreadID thread_id, CdiSignalType shutdown_signal)
 
CdiLogHandle CdiLogGlobalGetInternal (void)
 

Variables

CdiGlobalContext cdi_global_context = { 0 }
 global configuration data.
 
static CdiStaticMutexType global_context_mutex_lock = CDI_STATIC_MUTEX_INITIALIZER
 Statically allocated mutex used to make initialization of global data thread-safe.
 

Detailed Description

This file contains internal definitions and implementation used with the SDK that is not part of the API.

Function Documentation

◆ AdapterInitializeInternal()

CdiReturnStatus AdapterInitializeInternal ( CdiAdapterData * adapter_data_ptr,
CdiAdapterHandle * ret_handle_ptr )

Initialize an adapter.

Parameters
adapter_data_ptrAddress of a structure containing all of the pertinent information required to perform the initialization.
ret_handle_ptrPointer to a location in memory to place the handle to the initialized adapter.
Returns
CdiReturnStatus kCdiStatusOk if all went well, otherwise a value indicating why it failed.
See also
CdiCoreNetworkAdapterInitialize

◆ AdapterShutdownInternal()

static void AdapterShutdownInternal ( CdiAdapterHandle handle)
static

Function to shutdown an adapter.

Parameters
handlePointer to adapter being shut down.

◆ AppCallbackPayloadThread()

static CDI_THREAD AppCallbackPayloadThread ( void * ptr)
static

Payload thread used to notify application that payload has been transmitted and acknowledged as being received by the receiver.

Parameters
ptrPointer to thread specific data. In this case, a pointer to CdiConnectionState.
Returns
The return value is not used.

◆ BytesToHexString()

void BytesToHexString ( const void * data_ptr,
int data_byte_count,
char * dest_buffer_str,
int dest_buffer_size )

Convert an array of bytes to a hexadecimal string.

Parameters
data_ptrPointer to array of bytes.
data_byte_countNumber of data bytes.
dest_buffer_strAddress where to write the hex string to.
dest_buffer_sizeSize of destination string buffer.

◆ CdiGatherInternal()

int CdiGatherInternal ( const CdiSgList * sgl_ptr,
int offset,
void * dest_data_ptr,
int byte_count )

This is the implementation behind the API function CdiGather(). It is located in a private implementation file since it references names we wish to hide from cdiAPI.c.

Parameters
sgl_ptrThe scatter-gather list containing the data to be gathered.
offsetNumber of bytes to skip in SGL before starting the copy.
dest_data_ptrWhere to write the gathered data in linear format.
byte_countThe number of bytes to copy.
Returns
The number of bytes copied. This will be less than byte_count if fewer than that number of bytes are present in the source SGL starting from the specified offset. A value of -1 indicates that a fatal error was encountered.

◆ CdiGlobalInitialization()

CdiReturnStatus CdiGlobalInitialization ( const CdiCoreConfigData * core_config_ptr)

Performs initialization of the SDK that only needs to be done once and applies to programs that transmit, receive, or both transmit and receive.

Parameters
core_config_ptrPointer to core configuration data that is used to initalize the SDK. Value is required and cannot be NULL.
Returns
A value from the CdiReturnStatus enumeration.

◆ CdiLogGlobalGetInternal()

CdiLogHandle CdiLogGlobalGetInternal ( void )

Get the handle to the global log set by the CdiGlobalInitialization() function.

Returns
Handle of global log. If the CdiGlobalInitialization() function has not been used, NULL is returned.

◆ ConnectionCommonPacketMessageThreadCreate()

CdiReturnStatus ConnectionCommonPacketMessageThreadCreate ( CdiConnectionHandle handle,
char const * thread_name )

Create connection packet message thread that is common to both Tx and Rx connection types.

Parameters
handleThe handle of the connection being created.
thread_nameThe internal name of the thread.
Returns
CdiReturnStatus kCdiStatusOk if the thread was successfully created, otherwise the value indicates the nature of the failure.

◆ ConnectionCommonResourcesCreate()

CdiReturnStatus ConnectionCommonResourcesCreate ( CdiConnectionHandle handle,
CdiCoreStatsCallback stats_cb_ptr,
CdiUserCbParameter stats_user_cb_param,
const CdiStatsConfigData * stats_config_ptr )

Create connection resources that are common to both Tx and Rx connection types. These are OS level resources that must be created prior to the creation of any child threads related to this connection.

Parameters
handleThe handle of the connection being created.
stats_cb_ptrAddress of stats callback function.
stats_user_cb_paramUser-defined parameter in structure passed to stats_cb_ptr.
stats_config_ptrPointer to statistics configuration data.
Returns
CdiReturnStatus kCdiStatusOk if resources were successfully created, otherwise the value indicates the nature of the failure.

◆ ConnectionCommonResourcesDestroy()

void ConnectionCommonResourcesDestroy ( CdiConnectionHandle handle)

Destroy connection resources that are common to both Tx and Rx connection types. These are OS level resources that should be destroyed after all child threads related to this connection have finished using resources.

Parameters
handleThe handle of the connection being destroyed.

◆ ConnectionDestroyInternal()

void ConnectionDestroyInternal ( CdiConnectionHandle handle)

Shuts down a connection and frees all of the resources associated with it.

Parameters
handleThe handle of the connection to shut down.

◆ ConnectionShutdownInternal()

static void ConnectionShutdownInternal ( CdiConnectionHandle handle)
static

Function to shutdown connection.

Parameters
handlePointer to connection being shutdown.

◆ CoreStatsConfigureInternal()

CdiReturnStatus CoreStatsConfigureInternal ( CdiConnectionHandle handle,
const CdiStatsConfigData * new_config_ptr,
bool force_changes )

Configure transfer statistics.

Parameters
handleThe handle of the connection to set statistics configuration.
new_config_ptrPointer to new statistics configuration data.
force_changesIf true, settings are applied (used to set initial values), otherwise settings are only applied if any of their values change.
Returns
A value from the CdiReturnStatus enumeration.

◆ DeviceGidToString()

void DeviceGidToString ( const uint8_t * device_gid_ptr,
int gid_length,
char * dest_buffer_str,
int dest_buffer_size )

Convert a binary device GID to a string.

Parameters
device_gid_ptrPointer to binary device GID.
gid_lengthNumber of bytes in GID.
dest_buffer_strAddress where to write the string to.
dest_buffer_sizeSize of destination string buffer.

◆ DumpPayloadConfiguration()

void DumpPayloadConfiguration ( const CdiCoreExtraData * core_extra_data_ptr,
int extra_data_size,
const uint8_t * extra_data_array,
CdiConnectionProtocolType protocol_type )

Dump to log payload configuration data. NOTE: kLogPAYLOAD_CONFIG must be enabled in the logger using CdiFileLogEnable(), otherwise no messages will be generated.

Parameters
core_extra_data_ptrPointer to core extra data.
extra_data_sizeNumber of extra data bytes.
extra_data_arrayPointer to extra data bytes.
protocol_typeThe type of connection protocol, kProtocolTypeRaw or kProtocolTypeAvm

◆ EndpointDestroyInternal()

void EndpointDestroyInternal ( CdiEndpointHandle handle)

Shuts down a endpoint and frees all of the resources associated with it.

Parameters
handleThe handle of the endpoint to shut down.

◆ FreeSglEntries()

bool FreeSglEntries ( CdiPoolHandle pool_handle,
CdiSglEntry * sgl_entry_head_ptr )

Free a list of scatter-gather list entries from a memory pool.

Parameters
pool_handleHandle of pool which contains the SGL entries to free.
sgl_entry_head_ptrPointer to the head entry of the SGL entry list to free.
Returns
bool True if entry was successfully freed, otherwise an error occurred.

◆ NetworkAdapterDestroyInternal()

CdiReturnStatus NetworkAdapterDestroyInternal ( CdiAdapterHandle handle)

Destroy an adapter.

Parameters
handleHandle of adapter to destroy.
Returns
CdiReturnStatus kCdiStatusOk if all went well, otherwise a value indicating why it failed.
See also
CdiCoreNetworkAdapterDestroy

◆ PayloadErrorFreeBuffer()

void PayloadErrorFreeBuffer ( CdiPoolHandle pool_handle,
AppPayloadCallbackData * app_cb_data_ptr )

Free error message buffer, if it was used.

Parameters
pool_handleHandle for the pool to which to return the error buffer.
app_cb_data_ptrPointer to payload callback data (AppPayloadCallbackData).

◆ PayloadErrorSet()

void PayloadErrorSet ( CdiConnectionState * con_state_ptr,
AppPayloadCallbackData * app_cb_data_ptr,
CdiReturnStatus status_code,
const char * format_str,
... )

Set error message string in the specified payload callback. The error message is made available to the application through the user-registered Tx/Rx payload callback functions.

NOTE: Should not be used directly. Use the PAYLOAD_ERROR() macro instead.

Parameters
con_state_ptrPointer to connection state data (CdiConnectionState).
app_cb_data_ptrPointer to payload callback data (AppPayloadCallbackData).
status_codeStatus code to set (CdiReturnStatus).
format_strPointer to string used for formatting the message.
The remaining parameters contain a variable length list of arguments used by the format string to generate the error message.

◆ SdkShutdownInternal()

CdiReturnStatus SdkShutdownInternal ( void )

Shut down the SDK, freeing all of the resources that were allocated by it.

Returns
CdiReturnStatus kCdiStatusOk if SDK was shut down cleanly, otherwise the value indicates the nature of the failure.

◆ SdkThreadJoin()

void SdkThreadJoin ( CdiThreadID thread_id,
CdiSignalType shutdown_signal )

Set shutdown signal and wait for thread to exit.

Parameters
thread_idIdentifier of thread to wait for it to exit.
shutdown_signalThe shutdown signal used to shutdown the thread.

◆ SystemMonitorThread()

static CDI_THREAD SystemMonitorThread ( void * ptr)
static

System monitor thread used to detect CDI-SDK thread stall periods.

Parameters
ptrPointer to thread specific data.
Returns
The return value is not used.

Variable Documentation

◆ cdi_global_context

CdiGlobalContext cdi_global_context = { 0 }

global configuration data.

The one global variable defined by the SDK containing all of its state information.