Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: gh #66 : Changes for GET Request support in ut-control #68

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@
"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"
},
"cmake.configureOnOpen": true
}
44 changes: 44 additions & 0 deletions include/ut_control_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,34 @@ typedef struct
typedef void ut_controlPlane_instance_t; /*!< Handle to a control plane instance */

/** @brief Callback function type for handling control plane messages. */
/**
* @typedef ut_control_callback_t
kanjoe24 marked this conversation as resolved.
Show resolved Hide resolved
* @brief A callback function type for handling control operations.
*
* This callback function is called with a key, an instance of ut_kvp_instance_t,
* and user-defined data.
*
* @param key The key associated with the control operation.
* @param instance A pointer to a ut_kvp_instance_t instance.
* @param userData A pointer to user-defined data.
*/
typedef void (*ut_control_callback_t)( char *key, ut_kvp_instance_t *instance, void *userData );

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about this ->

/**
 * @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 httpMethod 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.
 *
 * @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 *httpMethod, void *userData);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Request Type URL Headers Body (Data) Parameter Type restAPI Parameter Value (Example) httpMethod Parameter Value pData
POST /products Content-Type: application/json {"name": "...", "description": "...", "price": ..., "category": "..."} Body /products POST Body
GET (Specific) /products/123 (None usually needed) (None usually needed) Path /products/123 GET NULL
GET (Filtered) /products?category=X&price_lt=Y (None usually needed) (None usually needed) Query /products GET category=X&price_lt=Y

Copy link
Collaborator

Choose a reason for hiding this comment

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

ignoring the incorrectly defined types

typedef char *(*ut_control_endpoint_callback_t)(const char *restAPI, const char *httpRequestType, ut_kvp_instance_t *pData, void *userData);

In the cast of POST -> Body Data is used for pData
In the case of GET -> it will be the pData itself

* @typedef ut_control_string_callback_t
* @brief A callback function type for handling control operations with formatted strings.
*
* This callback function is called with a key, an instance of ut_kvp_instance_t,
* user-defined data, and a format string. It returns a formatted string.
*
* @param key The key associated with the control operation.
* @param instance A pointer to a ut_kvp_instance_t instance.
* @param userData A pointer to user-defined data.
* @param format A constant character pointer representing the format string.
* @return A formatted string.
*/
typedef char* (*ut_control_string_callback_t)( char *key, ut_kvp_instance_t *instance, void *userData, const char* format );
kanjoe24 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Initializes a control plane instance.
* @param monitorPort - Port number to monitor for incoming messages.
Expand All @@ -74,6 +100,24 @@ ut_control_plane_status_t UT_ControlPlane_RegisterCallbackOnMessage(ut_controlPl
ut_control_callback_t callbackFunction,
void *userData);

/**
* @brief Registers a string callback function for a specific message key in the control plane instance.
kanjoe24 marked this conversation as resolved.
Show resolved Hide resolved
*
* This function allows the user to register a callback function that will be invoked when a message
* with the specified key is received by the control plane instance.
*
* @param pInstance Pointer to the control plane instance.
* @param key The key associated with the message for which the callback is to be registered.
* @param callbackFunction The callback function to be invoked when the message with the specified key is received.
* @param userData User-defined data to be passed to the callback function.
*
* @return Status of the registration operation.
*/
ut_control_plane_status_t UT_ControlPlane_RegisterStringCallbackOnMessage(ut_controlPlane_instance_t *pInstance,
char *key,
ut_control_string_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