2016-05-26 18:27:59 +02:00
|
|
|
#ifndef __COMMUNICATION_H__
|
|
|
|
#define __COMMUNICATION_H__
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-05-27 17:00:02 +02:00
|
|
|
#include <errno.h> // error numbers
|
2016-12-21 01:26:47 +01:00
|
|
|
#include "msg.h"
|
2016-05-27 17:00:02 +02:00
|
|
|
|
2016-12-19 18:16:38 +01:00
|
|
|
#include "process.h"
|
|
|
|
|
2016-05-26 18:27:59 +02:00
|
|
|
#define COMMUNICATION_VERSION 1
|
|
|
|
|
2016-12-17 18:00:04 +01:00
|
|
|
#define ER_MEM_ALLOC 100
|
|
|
|
#define ER_PARAMS 101
|
|
|
|
|
|
|
|
#define TMPDIR "/tmp/ipc/"
|
|
|
|
|
|
|
|
#define PATH_MAX BUFSIZ
|
2016-06-12 12:38:43 +02:00
|
|
|
|
2016-12-23 01:33:52 +01:00
|
|
|
#define CONNECTION 0
|
2016-12-20 23:36:00 +01:00
|
|
|
#define APPLICATION 1
|
2016-12-23 01:33:52 +01:00
|
|
|
#define CON_APP 2
|
2016-12-20 23:36:00 +01:00
|
|
|
|
2016-05-30 01:54:19 +02:00
|
|
|
struct service {
|
|
|
|
unsigned int version;
|
|
|
|
unsigned int index;
|
2016-06-05 20:48:13 +02:00
|
|
|
char spath[PATH_MAX];
|
2016-10-28 13:58:04 +02:00
|
|
|
int service_fd;
|
2016-05-30 01:54:19 +02:00
|
|
|
};
|
|
|
|
|
2016-12-15 00:28:42 +01:00
|
|
|
|
|
|
|
// SERVICE
|
|
|
|
|
2016-12-17 18:00:04 +01:00
|
|
|
// srv->version and srv->index must be already set
|
|
|
|
// init unix socket + fill srv->spath
|
2016-06-13 09:47:19 +02:00
|
|
|
int srv_init (int argc, char **argv, char **env
|
2016-12-15 00:28:42 +01:00
|
|
|
, struct service *srv, const char *sname);
|
2016-06-05 20:48:13 +02:00
|
|
|
int srv_close (struct service *srv);
|
2016-12-19 18:16:38 +01:00
|
|
|
int srv_close_proc (struct process *p);
|
|
|
|
int srv_accept (struct service *srv, struct process *p);
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-12-21 01:26:47 +01:00
|
|
|
int srv_read (const struct process *, struct msg *m);
|
|
|
|
int srv_write (const struct process *, const struct msg *m);
|
2016-06-04 20:33:44 +02:00
|
|
|
|
2016-12-23 01:33:52 +01:00
|
|
|
int srv_select (struct array_proc *, struct service *, struct array_proc *);
|
2016-12-20 23:36:00 +01:00
|
|
|
|
2016-06-05 03:19:36 +02:00
|
|
|
// APPLICATION
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-12-17 18:00:04 +01:00
|
|
|
// Initialize connection with unix socket
|
2016-06-10 01:21:04 +02:00
|
|
|
// send the connection string to $TMP/<service>
|
2016-12-17 18:00:04 +01:00
|
|
|
// fill srv->spath && srv->service_fd
|
2016-12-19 18:16:38 +01:00
|
|
|
int app_connection (int argc, char **argv, char **env
|
|
|
|
, struct service *, const char *, const char *, size_t);
|
2016-12-15 00:28:42 +01:00
|
|
|
int app_close (struct service *);
|
2016-10-28 13:58:04 +02:00
|
|
|
|
2016-12-21 01:26:47 +01:00
|
|
|
int app_read (struct service *srv, struct msg *m);
|
|
|
|
int app_write (struct service *, const struct msg *m);
|
2016-10-14 17:47:08 +02:00
|
|
|
|
2016-12-20 23:36:00 +01:00
|
|
|
|
|
|
|
|
2016-05-26 18:27:59 +02:00
|
|
|
#endif
|