Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions inc/bpl_evm_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* TODO: Fill in file header, if necessary.
*/
Comment on lines +1 to +3
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does there need to be a file header for these files?


#ifndef BPL_EVM_H
#define BPL_EVM_H

/******************************************************************************
INCLUDES
******************************************************************************/

#include "bplib_api_types.h"

/************************************************
* Typedefs
************************************************/

typedef enum
{
BPL_EVM_EventType_UNKNOWN = 0,
BPL_EVM_EventType_DEBUG = 1,
BPL_EVM_EventType_INFO = 2,
BPL_EVM_EventType_WARNING = 3,
BPL_EVM_EventType_ERROR = 4,
BPL_EVM_EventType_CRITICAL = 5
} BPL_EVM_EventType_t;

typedef struct
{
uint32_t ReturnValue;
} BPL_Status_t;

#define BPL_STATUS_SUCCESS (0u)
#define BPL_STATUS_ERROR_GENERAL (1u)
#define BPL_STATUS_ERROR_INPUT_INVALID (2u)
#define BPL_STATUS_ERROR_PROXY_INIT (3u)
Comment on lines +28 to +36
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these should be moved to somewhere else (if we decide to keep the struct impl of the return types, as discussed).


typedef struct
{
BPL_Status_t (*Initialize_Impl)(void);
BPL_Status_t (*SendEvent_Impl)(uint16_t EventID, BPL_EVM_EventType_t EventType,
char const * EventText, va_list EventTextArgPtr);
} BPL_EVM_ProxyCallbacks_t;

/************************************************
* Exported Functions
************************************************/

BPL_Status_t BPL_EVM_Initialize(BPL_EVM_ProxyCallbacks_t ProxyCallbacks);
char const * BPL_EVM_EventTypeToString(BPL_EVM_EventType_t Type);
BPL_Status_t BPL_EVM_SendEvent(uint16_t EventID, BPL_EVM_EventType_t EventType,
char const * EventText, ...);
void BPL_EVM_Deinitialize(void);

#endif /* BPL_EVM_H */
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(bplib_base_SOURCES
src/v7_cla_api.c
src/v7_dataservice_api.c
src/v7_routing.c
src/bpl_evm_api.c
)

add_library(bplib_base OBJECT
Expand Down
139 changes: 139 additions & 0 deletions lib/src/bpl_evm_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* TODO: Fill in file header, if necessary.
*/

/******************************************************************************
INCLUDES
******************************************************************************/

#include <stdarg.h>
#include "cfe.h"
#include "bpl_evm_api.h"

/******************************************************************************
TYPEDEFS
******************************************************************************/


/******************************************************************************
LOCAL DATA
******************************************************************************/

BPL_EVM_ProxyCallbacks_t BPL_EVM_ProxyCallbacks;

/******************************************************************************
LOCAL FUNCTIONS
******************************************************************************/

BPL_Status_t BPL_EVM_Initialize(BPL_EVM_ProxyCallbacks_t ProxyCallbacks)
{
BPL_Status_t ReturnStatus;
BPL_Status_t ProxyInitImplReturnStatus;

if ((ProxyCallbacks.Initialize_Impl == NULL) || (ProxyCallbacks.SendEvent_Impl == NULL))
{
ReturnStatus.ReturnValue = BPL_STATUS_ERROR_INPUT_INVALID;
OS_printf("BPL_EVM_Initialize got an invalid argument!\n");
}
else
{
/* impl callbacks determined to be valid */
BPL_EVM_ProxyCallbacks.Initialize_Impl = ProxyCallbacks.Initialize_Impl;
BPL_EVM_ProxyCallbacks.SendEvent_Impl = ProxyCallbacks.SendEvent_Impl;

/* TODO: immediately want to call the proxy init, or wait for a directive to do so? */
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to address this TODO

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the Initialize_Impl function pointer entirely. Have the BPNode call CFE_EVS_Register (or any other initialization) directly.

ProxyInitImplReturnStatus = BPL_EVM_ProxyCallbacks.Initialize_Impl();
if (ProxyInitImplReturnStatus.ReturnValue != BPL_STATUS_SUCCESS)
{
ReturnStatus.ReturnValue = BPL_STATUS_ERROR_PROXY_INIT;
OS_printf("BPL_EVM_Initialize hit error (%u) when calling proxy init!\n",
ProxyInitImplReturnStatus.ReturnValue);
}
else
{
ReturnStatus.ReturnValue = BPL_STATUS_SUCCESS;
}
}

return ReturnStatus;
}

char const * BPL_EVM_EventTypeToString(BPL_EVM_EventType_t Type)
{
/* BPL_EVM_EventTypeStrings should always match BPL_EVM_EventType_t. */
static char const * BPL_EVM_EventTypeStrings[] = {
"UNKNOWN",
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL"
};

switch (Type)
{
case BPL_EVM_EventType_DEBUG:
return BPL_EVM_EventTypeStrings[1];
case BPL_EVM_EventType_INFO:
return BPL_EVM_EventTypeStrings[2];
case BPL_EVM_EventType_WARNING:
return BPL_EVM_EventTypeStrings[3];
case BPL_EVM_EventType_ERROR:
return BPL_EVM_EventTypeStrings[4];
case BPL_EVM_EventType_CRITICAL:
return BPL_EVM_EventTypeStrings[5];
default:
/* This default case also captures the BPL_EVM_EventType_UNKNOWN case. */
return BPL_EVM_EventTypeStrings[0];
}
}

BPL_Status_t BPL_EVM_SendEvent(uint16_t EventID, BPL_EVM_EventType_t EventType,
char const * EventText, ...)
{
BPL_Status_t ReturnStatus;
BPL_Status_t ProxyReturnStatus;
va_list EventTextArgsPtr;

char const * EventTypeString = BPL_EVM_EventTypeToString(EventType);
OS_printf("BPL_EVM_SendEvent called! Event Info (%s, %u).\n",
EventTypeString,
EventID);

if (BPL_EVM_ProxyCallbacks.SendEvent_Impl == NULL)
{
ReturnStatus.ReturnValue = BPL_STATUS_ERROR_PROXY_INIT;
}
else if (EventText == NULL)
{
ReturnStatus.ReturnValue = BPL_STATUS_ERROR_INPUT_INVALID;
}
else
{
va_start(EventTextArgsPtr, EventText);
ProxyReturnStatus = BPL_EVM_ProxyCallbacks.SendEvent_Impl(EventID, EventType, EventText, EventTextArgsPtr);
va_end(EventTextArgsPtr);

if (ProxyReturnStatus.ReturnValue != BPL_STATUS_SUCCESS)
{
ReturnStatus.ReturnValue = BPL_STATUS_ERROR_GENERAL;
OS_printf("BPL_EVM_SendEvent hit error (%u) when calling proxy impl!\n",
ProxyReturnStatus.ReturnValue);
}
else
{
ReturnStatus.ReturnValue = BPL_STATUS_SUCCESS;
}
}

return ReturnStatus;
}

void BPL_EVM_Deinitialize(void)
{
/* Clear proxy function pointers */
BPL_EVM_ProxyCallbacks.Initialize_Impl = NULL;
BPL_EVM_ProxyCallbacks.SendEvent_Impl = NULL;

return;
}