Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
}
52 changes: 52 additions & 0 deletions include/ut_control_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,27 @@ typedef struct

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

/**** NOTE: This function will be deprecated in future major release ****/
/** @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 for handling HTTP requests to a specific REST API endpoint.
*
* This callback is invoked by the UT control server when an HTTP request (GET, POST, PUT, DELETE, etc.)
* is received and the requested REST API endpoint matches the `restAPI` parameter.
*
* @param restAPI The name of the REST API endpoint being called.
* @param httpRequestType The HTTP method of the request (e.g., "GET", "POST", "PUT", "DELETE").
* @param userData User-defined data passed during registration of the callback. This can be used to
* pass context or state to the callback function.
* @param pData Pointer to the key-value pair (KVP) instance containing the data sent with the request.
*
* @return A dynamically allocated character string containing the JSON response from the API endpoint.
* The caller is responsible for freeing the returned string using `free()`. Returns `NULL` on error.
*/
typedef char *(*ut_control_endpoint_callback_t)(const char *restAPI, const char *httpRequestType, ut_kvp_instance_t *pData, void *userData);
Copy link
Contributor

Choose a reason for hiding this comment

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

extensed the callback, so support bool return for error / no error , with char *pReturnedString, uint32_t *pReturnedSize

*pReturnedString - dynamically allocated character string containing the JSON response from the API endpoint.
*pReturnedSize - size of the returned string


/**
* @brief Initializes a control plane instance.
* @param monitorPort - Port number to monitor for incoming messages.
Expand All @@ -58,6 +76,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 );

/**
* **** NOTE: This function will be deprecated in future major release ****
* @brief Registers a callback function for a specific message key.
* @param pInstance - Handle to the control plane instance.
* @param key - Null-terminated string representing the message key to trigger the callback.
Expand All @@ -74,6 +93,39 @@ ut_control_plane_status_t UT_ControlPlane_RegisterCallbackOnMessage(ut_controlPl
ut_control_callback_t callbackFunction,
void *userData);

/**
* @brief Registers a callback for a REST API endpoint (GET) or POST message key.
*
* Registers a callback function to be invoked when a GET request is made to the
* specified `restAPI` endpoint, or when a POST request is received with
* `restAPI` as the message key.
*
* @param[in] pInstance Pointer to the control plane instance.
* @param[in] httpRequestType The HTTP request type ("GET" or "POST").
* @param[in] restAPI The REST API endpoint for GET requests, or the message key
* for POST requests. For example, "/users" for a GET
* request, or "status" for a POST request.
* @param[in] callbackFunction Pointer to the callback function. The function
* type depends on the request type:
* `ut_control_endpoint_callback_t` for GET requests,
* or `ut_control_on_message_callback_t` for POST
* requests.
* @param[in] userData Pointer to user-provided data that will be passed to the
* callback function. This can be used, for example, to
* pass a pointer to context data.
* @returns A status code indicating the result of the operation.
* @retval UT_CONTROL_PLANE_STATUS_OK Success.
* @retval UT_CONTROL_PLANE_STATUS_INVALID_HANDLE Invalid `pInstance`.
* @retval UT_CONTROL_PLANE_STATUS_INVALID_PARAM Invalid `restAPI` or
* `callbackFunction`.
* @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,
const char *httpRequestType,
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