2016-06-10 01:21:04 +02:00
|
|
|
#include "../lib/pubsubd.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#define MYMESSAGE "coucou"
|
|
|
|
#define MYCHAN "chan1"
|
|
|
|
|
|
|
|
void
|
|
|
|
ohshit(int rvalue, const char* str) {
|
|
|
|
fprintf (stderr, "\033[31merr: %s\033[00m\n", str);
|
|
|
|
exit (rvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-06-12 14:41:25 +02:00
|
|
|
main(int argc, char **argv, char **env)
|
2016-06-10 01:21:04 +02:00
|
|
|
{
|
|
|
|
struct service srv;
|
2016-06-10 20:02:58 +02:00
|
|
|
memset (&srv, 0, sizeof (struct service));
|
2016-06-12 14:41:25 +02:00
|
|
|
srv_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME);
|
2016-06-10 01:21:04 +02:00
|
|
|
printf ("Writing on %s.\n", srv.spath);
|
|
|
|
|
|
|
|
struct process p;
|
2016-06-10 20:02:58 +02:00
|
|
|
memset (&p, 0, sizeof (struct process));
|
2016-06-10 01:21:04 +02:00
|
|
|
int index = 1;
|
|
|
|
|
|
|
|
if (app_create (&p, index)) // called by the application
|
|
|
|
ohshit (1, "app_create");
|
|
|
|
|
|
|
|
// send a message to warn the service we want to do something
|
|
|
|
// line : pid index version action chan
|
|
|
|
pubsub_connection (&srv, &p, PUBSUB_PUB, MYCHAN);
|
|
|
|
|
|
|
|
struct pubsub_msg m;
|
2016-06-10 20:02:58 +02:00
|
|
|
memset (&m, 0, sizeof (struct pubsub_msg));
|
2016-06-10 01:21:04 +02:00
|
|
|
|
|
|
|
// first message, "coucou"
|
|
|
|
m.type = PUBSUB_TYPE_INFO;
|
|
|
|
m.chan = malloc (strlen (MYCHAN));
|
|
|
|
m.chanlen = strlen (MYCHAN);
|
|
|
|
m.data = malloc (strlen (MYMESSAGE));
|
|
|
|
m.datalen = strlen (MYMESSAGE);
|
2016-06-12 14:41:25 +02:00
|
|
|
pubsub_msg_send (&p, &m);
|
2016-06-10 01:21:04 +02:00
|
|
|
|
|
|
|
// second message, to disconnect from the server
|
|
|
|
m.type = PUBSUB_TYPE_DISCONNECT;
|
2016-06-12 14:41:25 +02:00
|
|
|
pubsub_msg_send (&p, &m);
|
2016-06-10 01:21:04 +02:00
|
|
|
|
|
|
|
// free everything
|
|
|
|
|
|
|
|
pubsubd_msg_free (&m);
|
|
|
|
|
|
|
|
// the application will shut down, and remove the application named pipes
|
|
|
|
if (app_destroy (&p))
|
|
|
|
ohshit (1, "app_destroy");
|
|
|
|
|
|
|
|
srv_process_free (&p);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|