Client entity implementation

The client entity uses the test() function to call the Ping and Pong methods in a different sequence and/or at different times (depending on the utilized policy family).

The implementation of the test() function is contained in a test.c file. There is a separate test.c file for each policy family utilized in the example.

For more details on initialization of transport to the server, use of a proxy object and interface methods and the purpose of the ping.idl.h file, see the comments to the client.c file in the echo example.

client.c

#include <stdio.h>

#include <stdlib.h>

#include <stdint.h>

#include <assert.h>

#include <coresrv/nk/transport-kos.h>

#include <coresrv/sl/sl_api.h>

#include "ping.idl.h"

/* Implementation of the test() function is contained in the test.c file. */

void test(struct IPing *proxy);

uint32_t ping(struct IPing *proxy, uint32_t value)

{

/* Request and response structures */

struct IPing_Ping_req req;

struct IPing_Ping_res res;

req.value = value;

/*Call IPing_Ping interface method. */

if (IPing_Ping(proxy, &req, NULL, &res, NULL) == rcOk)

{

fprintf(stderr, "Client: Ping(%d), result = %d\n", (int) value, (int) res.result);

value = res.result;

}

else

fprintf(stderr, "Client: Ping(%d), failed\n", (int) value);

return value;

}

uint32_t pong(struct IPing *proxy, uint32_t value)

{

/* Request and response structures */

struct IPing_Pong_req req;

struct IPing_Pong_res res;

req.value = value;

/* Call IPing_Pong interface method. */

if (IPing_Pong(proxy, &req, NULL, &res, NULL) == rcOk)

{

fprintf(stderr, "Client: Pong(%d), result = %d\n", (int) value, (int) res.result);

value = res.result;

}

else

fprintf(stderr, "Client: Pong(%d), failed\n", (int) value);

return value;

}

int main(int argc, const char *argv[])

{

NkKosTransport transport;

struct IPing_proxy proxy;

fprintf(stderr, "Hello I'm client\n");

/* Get client IPC handle of

* "server_connection". */

Handle handle = ServiceLocatorConnect("server_connection");

assert(handle != INVALID_HANDLE);

/* Initialize transport to server. */

NkKosTransport_Init(&transport, handle, NK_NULL, 0);

/* Get ping_comp.ping_impl interface ID. */

nk_iid_t riid = ServiceLocatorGetRiid(handle, "ping_comp.ping_impl");

assert(riid != INVALID_RIID);

/* Initialize proxy object. */

IPing_proxy_init(&proxy, &transport.base, riid);

/* Call Ping and Pong methods in adifferent sequence and/or at different times (depending on utilized policy family). */

test(&proxy.base);

return EXIT_SUCCESS;

}

Page top