Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@
"ut_control_plane.h": "c",
"ut.h": "c",
"ut_log.h": "c",
"tuple": "c"
"tuple": "c",
"array": "c",
"compare": "c",
"functional": "c",
"type_traits": "c",
"utility": "c",
"istream": "c",
"ostream": "c",
"libwebsockets.h": "c"
},
"cmake.configureOnOpen": true
}
65 changes: 61 additions & 4 deletions include/ut_control_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,48 @@ typedef struct
int32_t value;
} ut_control_keyStringMapping_t;

typedef enum
{
POST = 0,
GET,
INVALID
}eRestApi_t;

typedef void ut_controlPlane_instance_t; /*!< Handle to a control plane instance */

/** @brief Callback function type for handling control plane messages. */
typedef void (*ut_control_callback_t)( char *key, ut_kvp_instance_t *instance, void *userData );
/**
* @brief Callback function type for handling REST_API from POST triggers.
*
* This callback function is invoked when a POST request is received
* at a registered endpoint and the triggerKey is matched on the incoming data.
*
* @param triggerKey The trigger key that was matched.
* @param instance The key-value pair instance containing the incoming data.
* @param userData User-defined data passed to the callback function.
*/
typedef void (*ut_control_REST_API_POST_callback_t)(char *triggerKey, ut_kvp_instance_t *instance, void *userData);

/**
* @brief Callback function for handling REST_API from GET triggers.
*
* This callback function is invoked when a GET request is received
* at a registered endpoint. It allows the user to implement the
* REST API call.
*
* @param restAPI The name of the REST API being called.
* @param userData User-defined data passed to the callback function.
*
* @returns A character string containing the result of the API call, in JSON or YAML format
*/
typedef char *(*ut_control_REST_API_GET_callback_t)(char *restAPI, void *userData);

typedef struct
{
ut_control_REST_API_GET_callback_t callbackFunctionGET;
ut_control_REST_API_POST_callback_t callbackFunctionPOST;
eRestApi_t restApiType; // POST = 0, GET = 1
void *userData; // user-defined data
} ut_control_rest_api_handler_t;

/**
* @brief Initializes a control plane instance.
Expand All @@ -63,16 +101,35 @@ ut_controlPlane_instance_t* UT_ControlPlane_Init( uint32_t monitorPort );
* @param key - Null-terminated string representing the message key to trigger the callback.
* @param callbackFunction - Callback function to be invoked when the key is received.
* @param userData - Handle to the caller instance.
* @param restApiType - Type of REST API to be registered.(POST = 0, GET = 1)
* @returns Status of the registration operation (`ut_control_plane_status_t`).
* @retval UT_CONTROL_PLANE_STATUS_OK - Success
* @retval UT_CONTROL_PLANE_STATUS_INVALID_HANDLE - Invalid control plane instance handle.
* @retval UT_CONTROL_PLANE_STATUS_INVALID_PARAM - Invalid parameter passed
* @retval UT_CONTROL_PLANE_STATUS_CALLBACK_LIST_FULL - Callback list is full
* *******************NOTE: This function will be deprecated in future major releases.*******************
*/
ut_control_plane_status_t UT_ControlPlane_RegisterCallbackOnMessage(ut_controlPlane_instance_t *pInstance,
char *key,
ut_control_callback_t callbackFunction,
void *userData);
ut_control_REST_API_POST_callback_t callbackFunction,
void *userData, eRestApi_t restApiType);

/**
* @brief Registers a callback function for REST API endpoint.
*
* This function registers a callback function that will be invoked when a request
* is received for the specified REST API endpoint.
*
* @param pInstance A pointer to the control plane instance.
* @param restAPI The name of the REST API endpoint in case of GET or message key for POST.
* @param handler A structure containing callback functions and metadata.
*
* @returns A status code indicating the success or failure of the registration.
*/
ut_control_plane_status_t UT_ControlPlane_RegisterAPIEndpointHandler(
ut_controlPlane_instance_t *pInstance,
char *restAPI,
ut_control_rest_api_handler_t *handler);

/**
* @brief Starts the control plane listening for incoming messages.
Expand Down
10 changes: 10 additions & 0 deletions include/ut_kvp.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ uint32_t ut_kvp_getListCount( ut_kvp_instance_t *pInstance, const char *pszKey);
*/
unsigned char* ut_kvp_getDataBytes(ut_kvp_instance_t *pInstance, const char *pszKey, int *size);

/**
* @brief Get the data block from the instance based on the type requested by user.
* User to free the instance where the data is invalid, no output will be provided
* Also caller needs to ensure, that they free the pointer to the data block
*
* @param pInstance - pointer to the KVP instance
* @param pszType - type of data to be retrieved. Currently supported types are "json" and "yaml"
*/
char* ut_kvp_getDataOfType( ut_kvp_instance_t *pInstance, const char *pszType );

/* TODO:
* - Implement functions for getting signed integer values (`ut_kvp_getInt8Field`, `ut_kvp_getInt16Field`, `ut_kvp_getInt32Field`,
*`ut_kvp_getInt64Field`
Expand Down
Loading