2016-12-19 18:16:38 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
#include "../../core/msg.h"
|
|
|
|
#include "../../core/error.h"
|
2016-12-19 18:16:38 +01:00
|
|
|
#include "../../core/communication.h"
|
|
|
|
|
|
|
|
#define MSG "coucou"
|
|
|
|
#define SERVICE_NAME "test"
|
|
|
|
|
|
|
|
int main (int argc, char *argv[], char *env[])
|
|
|
|
{
|
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
struct msg m;
|
|
|
|
memset (&m, 0, sizeof (struct msg));
|
2016-12-19 18:16:38 +01:00
|
|
|
struct service srv;
|
2016-12-21 02:56:52 +01:00
|
|
|
memset (&srv, 0, sizeof (struct service));
|
2016-12-19 18:16:38 +01:00
|
|
|
|
|
|
|
// index and version should be filled
|
|
|
|
srv.index = 0;
|
|
|
|
srv.version = 0;
|
|
|
|
|
|
|
|
// init service
|
|
|
|
if (app_connection (argc, argv, env, &srv, SERVICE_NAME, NULL, 0) < 0) {
|
|
|
|
handle_err("main", "srv_init < 0");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-12-19 19:20:27 +01:00
|
|
|
printf ("msg to send: %s\n", MSG);
|
2016-12-21 02:56:52 +01:00
|
|
|
msg_format_data (&m, MSG, strlen(MSG) +1);
|
|
|
|
printf ("msg to send in the client: ");
|
|
|
|
print_msg (&m);
|
|
|
|
if (app_write (&srv, &m) < 0) {
|
2016-12-19 18:16:38 +01:00
|
|
|
handle_err("main", "app_write < 0");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2016-12-21 02:56:52 +01:00
|
|
|
msg_free (&m);
|
2016-12-19 18:16:38 +01:00
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
if (app_read (&srv, &m) < 0) {
|
2016-12-19 18:16:38 +01:00
|
|
|
handle_err("main", "app_read < 0");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
printf ("msg recv: %s\n", m.val);
|
|
|
|
msg_free (&m);
|
2016-12-19 18:16:38 +01:00
|
|
|
|
|
|
|
if (app_close (&srv) < 0) {
|
|
|
|
handle_err("main", "app_close < 0");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|