CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
internal.h
Go to the documentation of this file.
1// -------------------------------------------------------------------------------------------
2// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3// This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License.
4// License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE
5// -------------------------------------------------------------------------------------------
6
13#ifndef CDI_INTERNAL_H__
14#define CDI_INTERNAL_H__
15
16#include <assert.h>
17
18// The configuration.h file must be included first since it can have defines which affect subsequent files.
19#include "configuration.h"
20
21#include "adapter_api.h"
22#include "cdi_core_api.h"
23#include "cdi_log_api.h"
24#include "cdi_raw_api.h"
25#include "internal_log.h"
26
27//*********************************************************************************************************************
28//***************************************** START OF DEFINITIONS AND TYPES ********************************************
29//*********************************************************************************************************************
30
31//*********************************************************************************************************************
32//******************************************* START OF PUBLIC FUNCTIONS ***********************************************
33//*********************************************************************************************************************
34
42static inline bool IsValidTxHandle(const CdiConnectionHandle handle)
43{
44 return handle != NULL && handle->handle_type == kHandleTypeTx && handle->magic == kMagicConnection &&
45 handle->adapter_state_ptr != NULL;
46}
47
55static inline bool IsValidRxHandle(const CdiConnectionHandle handle)
56{
57 return handle != NULL && handle->handle_type == kHandleTypeRx && handle->magic == kMagicConnection
58 && handle->adapter_state_ptr != NULL;
59}
60
68static inline bool IsValidConnectionHandle(const CdiConnectionHandle handle)
69{
70 // with -O2 or higher, GCC optimizes to only a single check of magic
71 return (IsValidTxHandle(handle) || IsValidRxHandle(handle));
72}
73
79static inline bool IsValidEndpointHandle(const CdiEndpointHandle handle)
80{
81 return handle != NULL && handle->magic == kMagicEndpoint;
82}
83
91static inline bool IsValidMemoryHandle(const CdiMemoryHandle handle)
92{
93 return handle != NULL && handle->magic == kMagicMemory;
94}
95
103static inline bool IsValidAdapterHandle(const CdiAdapterHandle handle)
104{
105 return handle != NULL && handle->magic == kMagicAdapter;
106}
107
118
132int CdiGatherInternal(const CdiSgList* sgl_ptr, int offset, void* dest_data_ptr, int byte_count);
133
146
157
164
171
179
193 CdiUserCbParameter stats_user_cb_param,
194 const CdiStatsConfigData* stats_config_ptr);
195
203
214
226 bool force_changes);
227
237#define PAYLOAD_ERROR(con_state_ptr, app_cb_data_ptr, status_code, ...) { \
238 PayloadErrorSet(con_state_ptr, app_cb_data_ptr, status_code, __VA_ARGS__); \
239 CdiLogger(CdiLoggerThreadLogGet(), kLogComponentGeneric, kLogError, __FUNCTION__, __LINE__ , __VA_ARGS__); }
240
250#define BACK_PRESSURE_ERROR(back_pressure_state, log_level, ...) \
251 if (kCdiBackPressureNone == back_pressure_state) { \
252 back_pressure_state = kCdiBackPressureActive; \
253 CdiLogger(CdiLoggerThreadLogGet(), kLogComponentGeneric, log_level, __FUNCTION__, __LINE__, __VA_ARGS__); \
254 }
255
268void PayloadErrorSet(CdiConnectionState* con_state_ptr, AppPayloadCallbackData* app_cb_data_ptr,
269 CdiReturnStatus status_code, const char* format_str, ...);
270
277void PayloadErrorFreeBuffer(CdiPoolHandle pool_handle, AppPayloadCallbackData* app_cb_data_ptr);
278
289static inline void SglAppend(CdiSgList* sgl_list_ptr, CdiSglEntry* sgl_add_ptr)
290{
291 if (NULL == sgl_list_ptr->sgl_head_ptr) {
292 sgl_list_ptr->sgl_head_ptr = sgl_add_ptr;
293 sgl_list_ptr->sgl_tail_ptr = sgl_add_ptr;
294 } else {
295 if (NULL == sgl_list_ptr->sgl_tail_ptr) {
296 sgl_list_ptr->sgl_tail_ptr = sgl_list_ptr->sgl_head_ptr;
297 }
298 sgl_list_ptr->sgl_tail_ptr->next_ptr = sgl_add_ptr;
299 sgl_list_ptr->sgl_tail_ptr = sgl_add_ptr;
300 }
301 sgl_list_ptr->total_data_size += sgl_add_ptr->size_in_bytes; // Update size of the SGL list.
302}
303
311static inline void SglMoveEntries(CdiSgList* destination_sgl_ptr, CdiSgList* source_sgl_ptr)
312{
313 // If the SGL has a head, it should also have a tail. Validate both SGL lists.
314 if (destination_sgl_ptr->sgl_head_ptr) {
315 assert(destination_sgl_ptr->sgl_tail_ptr);
316 }
317 if (source_sgl_ptr->sgl_head_ptr) {
318 assert(source_sgl_ptr->sgl_tail_ptr);
319 }
320
321 if (destination_sgl_ptr->sgl_tail_ptr != NULL) {
322 destination_sgl_ptr->sgl_tail_ptr->next_ptr = source_sgl_ptr->sgl_head_ptr;
323 } else {
324 if (destination_sgl_ptr->sgl_head_ptr == NULL) {
325 destination_sgl_ptr->sgl_head_ptr = source_sgl_ptr->sgl_head_ptr;
326 } else {
327 destination_sgl_ptr->sgl_head_ptr->next_ptr = source_sgl_ptr->sgl_head_ptr;
328 }
329 }
330 destination_sgl_ptr->sgl_tail_ptr = source_sgl_ptr->sgl_tail_ptr;
331 destination_sgl_ptr->total_data_size += source_sgl_ptr->total_data_size; // Update size of the destination list.
332 memset(source_sgl_ptr, 0, sizeof(*source_sgl_ptr));
333}
334
341static inline void SglSetEmptyForExternalUse(CdiSgList* sgl_ptr)
342{
343 sgl_ptr->total_data_size = 0;
345 sgl_ptr->sgl_tail_ptr = sgl_ptr->sgl_head_ptr;
346 sgl_ptr->internal_data_ptr = NULL;
347}
348
357bool FreeSglEntries(CdiPoolHandle pool_handle, CdiSglEntry* sgl_entry_head_ptr);
358
368void DumpPayloadConfiguration(const CdiCoreExtraData* core_extra_data_ptr, int extra_data_size,
369 const uint8_t* extra_data_array, CdiConnectionProtocolType protocol_type);
370
379void BytesToHexString(const void* data_ptr, int data_byte_count, char* dest_buffer_str, int dest_buffer_size);
380
389void DeviceGidToString(const uint8_t* device_gid_ptr, int gid_length, char* dest_buffer_str, int dest_buffer_size);
390
397void SdkThreadJoin(CdiThreadID thread_id, CdiSignalType shutdown_signal);
398
405
406#endif // CDI_INTERNAL_H__
The declarations in this header file correspond to the definitions in adapter.c.
This file declares the public API data types, structures and functions that comprise the CDI low-leve...
CdiReturnStatus
Values used for API function return codes.
Definition cdi_core_api.h:189
void(* CdiCoreStatsCallback)(const CdiCoreStatsCbData *data_ptr)
Prototype of statistics callback function. The user code must implement a function with this prototyp...
Definition cdi_core_api.h:606
void * CdiUserCbParameter
Type used as user defined data that is passed to the registered user RX/TX callback functions.
Definition cdi_core_api.h:182
This file declares the public API data types, structures and functions that comprise the CDI log API.
struct CdiSignalType_t * CdiSignalType
Define portable signal type. Don't use void* here, which prevents the compiler from type checking.
Definition cdi_os_api.h:189
struct CdiThreadID_t * CdiThreadID
Define portable thread type. Separate name from type, otherwise the typedef that follows it will gene...
Definition cdi_os_api.h:312
This file declares the public API data types, structures and functions that comprise the CDI Raw payl...
CdiConnectionProtocolType
This enumeration is used in the CdiConnectionState structure to indicate what connection layer is bei...
Definition cdi_utility_api.h:71
This header file contains definitions used to define the build configuration of the CDI SDK's impleme...
CdiGlobalContext cdi_global_context
global configuration data.
Definition internal.c:44
static void SglSetEmptyForExternalUse(CdiSgList *sgl_ptr)
Definition internal.h:341
CdiReturnStatus ConnectionCommonResourcesCreate(CdiConnectionHandle handle, CdiCoreStatsCallback stats_cb_ptr, CdiUserCbParameter stats_user_cb_param, const CdiStatsConfigData *stats_config_ptr)
Definition internal.c:553
int CdiGatherInternal(const CdiSgList *sgl_ptr, int offset, void *dest_data_ptr, int byte_count)
Definition internal.c:366
static bool IsValidMemoryHandle(const CdiMemoryHandle handle)
Definition internal.h:91
CdiReturnStatus ConnectionCommonPacketMessageThreadCreate(CdiConnectionHandle handle, char const *thread_name)
Definition internal.c:636
CdiReturnStatus CdiGlobalInitialization(const CdiCoreConfigData *core_config_ptr)
Definition internal.c:251
void DeviceGidToString(const uint8_t *device_gid_ptr, int gid_length, char *dest_buffer_str, int dest_buffer_size)
Definition internal.c:890
CdiReturnStatus CoreStatsConfigureInternal(CdiConnectionHandle handle, const CdiStatsConfigData *new_config_ptr, bool force_changes)
Definition internal.c:649
CdiReturnStatus AdapterInitializeInternal(CdiAdapterData *adapter_data_ptr, CdiAdapterHandle *ret_handle_ptr)
Definition internal.c:412
static void SglMoveEntries(CdiSgList *destination_sgl_ptr, CdiSgList *source_sgl_ptr)
Definition internal.h:311
CdiReturnStatus SdkShutdownInternal(void)
Definition internal.c:746
void ConnectionCommonResourcesDestroy(CdiConnectionHandle handle)
Definition internal.c:619
static bool IsValidTxHandle(const CdiConnectionHandle handle)
Definition internal.h:42
void EndpointDestroyInternal(CdiEndpointHandle handle)
Definition internal.c:741
static bool IsValidRxHandle(const CdiConnectionHandle handle)
Definition internal.h:55
void SdkThreadJoin(CdiThreadID thread_id, CdiSignalType shutdown_signal)
Definition internal.c:907
void BytesToHexString(const void *data_ptr, int data_byte_count, char *dest_buffer_str, int dest_buffer_size)
Definition internal.c:879
static void SglAppend(CdiSgList *sgl_list_ptr, CdiSglEntry *sgl_add_ptr)
Definition internal.h:289
CdiReturnStatus NetworkAdapterDestroyInternal(CdiAdapterHandle handle)
Definition internal.c:526
CdiLogHandle CdiLogGlobalGetInternal(void)
Definition internal.c:917
void ConnectionDestroyInternal(CdiConnectionHandle handle)
Definition internal.c:709
void DumpPayloadConfiguration(const CdiCoreExtraData *core_extra_data_ptr, int extra_data_size, const uint8_t *extra_data_array, CdiConnectionProtocolType protocol_type)
Definition internal.c:784
void PayloadErrorFreeBuffer(CdiPoolHandle pool_handle, AppPayloadCallbackData *app_cb_data_ptr)
Definition internal.c:700
static bool IsValidEndpointHandle(const CdiEndpointHandle handle)
Definition internal.h:79
bool FreeSglEntries(CdiPoolHandle pool_handle, CdiSglEntry *sgl_entry_head_ptr)
Definition internal.c:762
static bool IsValidConnectionHandle(const CdiConnectionHandle handle)
Definition internal.h:68
void PayloadErrorSet(CdiConnectionState *con_state_ptr, AppPayloadCallbackData *app_cb_data_ptr, CdiReturnStatus status_code, const char *format_str,...)
Definition internal.c:675
static bool IsValidAdapterHandle(const CdiAdapterHandle handle)
Definition internal.h:103
The declarations in this header file is used for logging.
@ kHandleTypeTx
Transmitter type handle.
Definition private.h:98
@ kHandleTypeRx
Receiver type handle.
Definition private.h:99
This defines a structure that contains all of the data required to use the application registered pay...
Definition private.h:106
Configuration data used by the CdiCoreNetworkAdapterInitialize() API function.
Definition cdi_core_api.h:480
Structure definition behind the handles shared with the user's application program....
Definition adapter_api.h:384
uint32_t magic
Set to kMagicAdapter when allocated, checked at every API function to help ensure validity.
Definition adapter_api.h:389
Structure definition behind the connection handles shared with the user's application program....
Definition private.h:371
CdiAdapterState * adapter_state_ptr
The instance of the adapter this Tx/Rx object is associated with.
Definition private.h:390
ConnectionHandleType handle_type
Indicates which structure of the union is valid.
Definition private.h:405
uint32_t magic
Set to kMagicConnection when allocated, checked at every API function to help ensure validity.
Definition private.h:375
SDK configuration data used by the CdiCoreInitialize() API function.
Definition cdi_core_api.h:869
Extra data that is sent along with payloads to the receiver. It will be provided to the receiver thro...
Definition cdi_core_api.h:340
Structure definition behind the connection handles shared with the user's application program....
Definition private.h:330
uint32_t magic
Set to kMagicEndpoint when allocated, checked at every API function to help ensure validity.
Definition private.h:332
CdiSglEntry empty_sgl_entry
Empty scatter-gather-list entry.
Definition private.h:52
Structure used to hold state data for a single log of any type (stdout, callback or file).
Definition logger.c:79
Structure definition behind the Scatter-Gather List internal data handles shared with the user's appl...
Definition private.h:456
uint32_t magic
Set to kMagicMem when allocated, checked at every API function to help ensure validity.
Definition private.h:458
This structure represents the current state of a memory pool.
Definition pool.c:46
This structure defines a scatter-gather list (SGL) which is used to represent an array of data compri...
Definition cdi_core_api.h:728
CdiSglEntry * sgl_tail_ptr
Pointer to the last entry in the singly-linked list of SGL entries.
Definition cdi_core_api.h:738
int total_data_size
Total size of data in the list, in units of bytes. This value can be calculated by walking the sgl_ar...
Definition cdi_core_api.h:732
CdiSglEntry * sgl_head_ptr
Pointer to the first entry in the singly-linked list of SGL entries.
Definition cdi_core_api.h:735
void * internal_data_ptr
Handle to internal data used within the SDK that relates to this SGL. Do not use or modify this value...
Definition cdi_core_api.h:741
This structure represents a single, contiguous region of memory as part of a scatter-gather list.
Definition cdi_core_api.h:709
int size_in_bytes
The size of the data in bytes.
Definition cdi_core_api.h:714
CdiSglEntry * next_ptr
The next entry in the list or NULL if this is the final entry in the list.
Definition cdi_core_api.h:721
A structure that is used to hold statistics gathering configuration data.
Definition cdi_core_api.h:611