2016-05-31 23:16:39 +02:00
|
|
|
#include "../lib/communication.h"
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-09-14 23:05:02 +02:00
|
|
|
#define SERVICE "windowing"
|
|
|
|
|
|
|
|
void
|
2018-11-02 21:03:54 +01:00
|
|
|
ohshit(int32_t rvalue, const char* str) {
|
2016-09-14 23:05:02 +02:00
|
|
|
fprintf(stderr, "%s\n", str);
|
|
|
|
exit(rvalue);
|
|
|
|
}
|
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t main(int32_t argc, char * argv[], char *env[])
|
2016-05-26 18:27:59 +02:00
|
|
|
{
|
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, SERVICE, NULL);
|
2016-09-14 23:05:02 +02:00
|
|
|
printf ("Listening on %s.\n", srv.spath);
|
|
|
|
|
|
|
|
// creates the service named pipe, that listens to client applications
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_create (&srv))
|
2016-09-14 23:05:02 +02:00
|
|
|
ohshit(1, "service_create error");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PROCESS
|
|
|
|
*/
|
|
|
|
|
2018-10-04 00:30:47 +02:00
|
|
|
struct ipc_client p;
|
|
|
|
memset (&p, 0, sizeof (struct ipc_client));
|
2016-09-14 23:05:02 +02:00
|
|
|
|
2018-11-02 21:03:54 +01:00
|
|
|
int32_t index = 0; // first time we communication with the service
|
|
|
|
int32_t version = 1;
|
2016-09-14 23:05:02 +02:00
|
|
|
|
|
|
|
printf ("app creation\n");
|
2018-10-03 21:24:20 +02:00
|
|
|
if (application_create (&p, index, version)) // called by the application
|
|
|
|
ohshit (1, "application_create");
|
2016-09-14 23:05:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2018-10-03 21:24:20 +02:00
|
|
|
if (application_destroy (&p))
|
|
|
|
ohshit (1, "application_destroy");
|
2016-09-14 23:05:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* /PROCESS
|
|
|
|
*/
|
|
|
|
|
|
|
|
// the application will shut down, and remove the service named pipe
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_close (&srv))
|
|
|
|
ohshit (1, "server_close error");
|
2016-05-26 18:27:59 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|