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/drop/init-connection.c
2018-11-02 21:03:54 +01:00

57 lines
1.4 KiB
C

#include "../lib/communication.h"
#define SERVICE "windowing"
void
ohshit(int32_t rvalue, const char* str) {
fprintf(stderr, "%s\n", str);
exit(rvalue);
}
int32_t main(int32_t argc, char * argv[], char *env[])
{
struct ipc_service srv;
memset (&srv, 0, sizeof (struct ipc_service));
ipc_server_init (argc, argv, env, &srv, SERVICE, NULL);
printf ("Listening on %s.\n", srv.spath);
// creates the service named pipe, that listens to client applications
if (server_create (&srv))
ohshit(1, "service_create error");
/*
* PROCESS
*/
struct ipc_client p;
memset (&p, 0, sizeof (struct ipc_client));
int32_t index = 0; // first time we communication with the service
int32_t version = 1;
printf ("app creation\n");
if (application_create (&p, index, version)) // called by the application
ohshit (1, "application_create");
/*
* some exchanges between App and S
* specific code, talks between applications
* then App wants to end the communication
*/
printf ("destroying app\n");
// the application will shut down, and remove the application named pipes
if (application_destroy (&p))
ohshit (1, "application_destroy");
/*
* /PROCESS
*/
// the application will shut down, and remove the service named pipe
if (server_close (&srv))
ohshit (1, "server_close error");
return EXIT_SUCCESS;
}