Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
}
50 changes: 46 additions & 4 deletions include/ut_control_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,31 @@ typedef struct

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 POST triggers.
*
* This callback function is invoked when a POST request is received
* at the ut control server 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_on_message_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 UT control server and the rest api name of the GET request matches the restAPI parameter
* registered with the UT control server.
*
* @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
*/
typedef char *(*ut_control_endpoint_callback_t)(char *restAPI, void *userData);

/**
* @brief Initializes a control plane instance.
Expand All @@ -58,7 +81,7 @@ typedef void (*ut_control_callback_t)( char *key, ut_kvp_instance_t *instance, v
ut_controlPlane_instance_t* UT_ControlPlane_Init( uint32_t monitorPort );

/**
* @brief Registers a callback function for a specific message key.
* @brief Registers a callback function to pattern match a key from the POST request
* @param pInstance - Handle to the control plane instance.
* @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.
Expand All @@ -71,9 +94,28 @@ ut_controlPlane_instance_t* UT_ControlPlane_Init( uint32_t monitorPort );
*/
ut_control_plane_status_t UT_ControlPlane_RegisterCallbackOnMessage(ut_controlPlane_instance_t *pInstance,
char *key,
ut_control_callback_t callbackFunction,
ut_control_on_message_callback_t callbackFunction,
void *userData);

/**
* @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 userData NULL by default. Optionally, can be used as a handle to the caller instance.
* @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
*/
ut_control_plane_status_t UT_ControlPlane_RegisterEndPointCallback(
ut_controlPlane_instance_t *pInstance,
char *restAPI, ut_control_endpoint_callback_t callbackFunction, void *userData);

/**
* @brief Starts the control plane listening for incoming messages.
* @param pInstance - Handle to the control plane instance.
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