Archived
3
0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
libipc-old/pubsub/tests/pubsub-test-send.c

64 lines
1.6 KiB
C
Raw Normal View History

2017-01-19 22:07:52 +01:00
int main() { return 0; }
#if 0
#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)
{
2018-10-04 00:30:47 +02:00
struct ipc_service srv;
memset (&srv, 0, sizeof (struct ipc_service));
2018-10-03 21:52:11 +02:00
ipc_server_init (argc, argv, env, &srv, PUBSUB_SERVICE_NAME, NULL);
printf ("Writing on %s.\n", srv.spath);
2018-10-04 00:30:47 +02:00
struct ipc_client p;
memset (&p, 0, sizeof (struct ipc_client));
int index = 1;
2016-06-13 09:47:19 +02:00
pid_t pid = getpid();
2018-10-03 21:24:20 +02:00
if (application_create (&p, pid, index, COMMUNICATION_VERSION))
ohshit (1, "application_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;
memset (&m, 0, sizeof (struct pubsub_msg));
// 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);
2018-10-03 21:52:11 +02:00
pubsub_message_send (&p, &m);
// second message, to disconnect from the server
m.type = PUBSUB_TYPE_DISCONNECT;
2018-10-03 21:52:11 +02:00
pubsub_message_send (&p, &m);
// free everything
2018-10-03 21:52:11 +02:00
pubsubd_message_free (&m);
// the application will shut down, and remove the application named pipes
2018-10-03 21:24:20 +02:00
if (application_destroy (&p))
ohshit (1, "application_destroy");
return EXIT_SUCCESS;
}
2017-01-19 22:07:52 +01:00
#endif