Hi Team,
I am currently working on establishing bi-directional communication between 2 application (client & server). My objective is that when client calls the server API (i.e FUNCTION fname defined in .api file) , I am also passing a HANDLER (a client function) so that server can respond back to the client by calling the callback from the server side i.e send response back to the client.
Scenerio:
Below are my 2 application source file and API file:
printer.api:
HANDLER callback
(
string msg[100] IN
);
FUNCTION request
(
string message[100] IN,
callback callbackHandler IN
);
printServer/server.c:
#include “legato.h”
#include “interfaces.h”
void Fx(const char* message);
static printer_printClientHandler_t cbkHandler;
void printer_request(const char* message, printer_printClientHandler_t callback, void contextPtr)
{
LE_INFO("******* Client says ‘%s’", message);
Fx(message);
cbkHandler = callback;
cbkHandler(“How are you client”);
}
void Fx(const char* message)
{
LE_INFO(“******** Internal message: ‘%s’”, message);
}
COMPONENT_INIT
{
}
printClient/client.c:
#include “legato.h”
#include “interfaces.h”
static void internal_fn(const char *message);
COMPONENT_INIT
{
LE_INFO(“Asking server to print ‘Hello, world!’”);
internal_fn(“Hello, world!”);
}
void callback(const char *rsp)
{
LE_INFO(“Response received from server: ‘%s’”, rsp);
}
void internal_fn(const char *message)
{
char response[100];
LE_INFO(“Calling server API from internal fn!!!”);
printer_request(message, callback, NULL);
LE_INFO(“Response received from server: ‘%s’!!!”, response);
}
Output:
I am observing the crash at the server side when the callback function is getting called saying the address is ‘null’.
Is this approach the correct approach for communication between 2 seperate legato applications each having one component each. If not please provide correct approach with some source code.
Thanks and regards,
Kartik