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

Create ut-control as a seperate module, and support testing indepdance #1

Closed
Ulrond opened this issue May 28, 2024 · 0 comments · Fixed by #2
Closed

Create ut-control as a seperate module, and support testing indepdance #1

Ulrond opened this issue May 28, 2024 · 0 comments · Fixed by #2
Assignees
Labels
enhancement New feature or request

Comments

@Ulrond
Copy link
Collaborator

Ulrond commented May 28, 2024

See -> rdkcentral/ut-core#20

This control plane will support receiving messages via JSON/ YAML RPC on a websocket.

The module will open a port and wait for control messages.

Any client module is linked against ut-core will register interest in received message type from the control plane.

Full design of the implementation is yet to be defined but an idea on the server side you would register interest in messages

#define UT_CONTROL_PLANE_MAX_KEY_SIZE (256)
#define UT_CONTROL_PLANE_MAX_KEY_SIZE (64)

typedef struct
{
  char key[UT_CONTROL_PLANE_MAX_KEY_SIZE];
  ut_control_callback_t pCallback;
}CallbackEntry_t;

static callbackEntry_t callbackList[UT_CONTROL_PLANE_MAX_CALLBACK_ENTRIES);
static uint32_t lastFreeCallbackSlot=0; /* Must always be < UT_CONTROL_PLANE_MAX_CALLBACK_ENTRIES */

/* Callback function that will be triggered */
void (*ut_control_callback_t)( char *key, ut_kvp_instance_t *instance );

/* Init the control plane and create instance */
ut_controlPlane_instance_t *UT_ControlPlane_Init( uint32_t monitorPort );

/* pInstance, will be freed on return from the callback */
UT_ControlPlane_RegisterCallbackOnMessage( ut_controlPlane_instance_t *pInstance, char* key, ut_control_callback_t  callbackFunction);

/* Exit the controlPlane instance and release */
void UT_ControlPlane_Exit( ut_controlPlane_instance_t *pInstance );
...
  • Examples
// Examples of someone calling the registration function
UT_ControlPlane_RegisterCallbackOnMessage(ut_controlPlane_instance_t *pInstance, "hdmicec/command", &myCallback);
UT_ControlPlane_RegisterCallbackOnMessage(ut_controlPlane_instance_t *pInstance, "hdmicec", &myCallback);

On the client side, you would send message e.g.

hdmicec:
  command: hotplug
  port:10
  on: true

rmfAudio:
 a:1
 b:2 
sequenceDiagram
      actor Test_Control
      participant Control_Plane
      participant vDevice_Control_Plane
      Test_Control -->> Control_Plane: Request Behaviour
      Control_Plane -->> vDevice_Control_Plane: Platform control to vDevice
Loading

Example Socket connection using https://libwebsockets.org/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libwebsockets.h>

static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) {

    switch (reason) {
        case LWS_CALLBACK_CLIENT_ESTABLISHED:
            printf("Connection established\n");
            break;

        case LWS_CALLBACK_CLIENT_RECEIVE:
            // Message received - assuming JSON format like {"symbol": "AAPL", "price": 155.23}
            printf("Received message: %.*s\n", (int)len, (char *)in);  
            // TODO: Parse the JSON for symbol and price
            break;

        // Other events as needed ... (connection closed, etc.)

        default:
            break;
    }

    return 0;
}

static struct lws_protocols protocols[] = {
    { "http-only", callback_http, 0, 0 },
    { NULL, NULL, 0, 0 } /* terminator */
};

int main(void) {
    struct lws_context_creation_info info;
    struct lws_context *context;
    const char *server_address = "YOUR_WEBSOCKET_SERVER_ADDRESS";
    int port = 80; // Or whatever port is used by your provider

    memset(&info, 0, sizeof info);
    info.port = CONTEXT_PORT_NO_LISTEN;
    info.protocols = protocols;

    context = lws_create_context(&info);
    if (!context) {
        fprintf(stderr, "Failed to create libwebsockets context\n");
        return 1;
    }

    // Connect to the server
    struct lws *wsi = lws_client_connect(context, server_address, port, 0, "/", server_address, NULL, NULL, -1);
    if (!wsi) {
        fprintf(stderr, "Failed to connect to server\n");
        lws_context_destroy(context);
        return 1;
    }

    // Event loop
    while (1) {
        lws_service(context, 1000); // Timeout of 1000 ms
    }

    lws_context_destroy(context);
    return 0;
}
@kanjoe24 kanjoe24 linked a pull request May 30, 2024 that will close this issue
@Ulrond Ulrond added the enhancement New feature or request label May 31, 2024
@Ulrond Ulrond added this to the 1.0.0 - Initial Release milestone May 31, 2024
@Ulrond Ulrond changed the title split control plane into seperate repo Create ut-control as a seperate module, and support testing indepdance Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants