2016-05-26 18:27:59 +02:00
|
|
|
#ifndef __COMMUNICATION_H__
|
|
|
|
#define __COMMUNICATION_H__
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <unistd.h> // unlink
|
|
|
|
|
|
|
|
#include <sys/types.h> // mkfifo
|
|
|
|
#include <sys/stat.h> // mkfifo
|
|
|
|
#include <fcntl.h> // open
|
|
|
|
|
2016-05-27 17:00:02 +02:00
|
|
|
#include <errno.h> // error numbers
|
|
|
|
|
2016-05-30 01:54:19 +02:00
|
|
|
#define TMPDIR "/tmp/ipc/"
|
2016-05-26 18:27:59 +02:00
|
|
|
|
|
|
|
#define COMMUNICATION_VERSION 1
|
|
|
|
|
|
|
|
// TODO to check the right length for a path
|
|
|
|
#define PATH_MAX BUFSIZ
|
|
|
|
|
|
|
|
struct process {
|
|
|
|
pid_t pid;
|
|
|
|
unsigned int version;
|
|
|
|
unsigned int index;
|
2016-05-27 17:00:02 +02:00
|
|
|
FILE *in, *out;
|
2016-05-26 18:27:59 +02:00
|
|
|
};
|
|
|
|
|
2016-05-30 01:54:19 +02:00
|
|
|
struct service {
|
|
|
|
unsigned int version;
|
|
|
|
unsigned int index;
|
|
|
|
};
|
|
|
|
|
2016-05-26 18:27:59 +02:00
|
|
|
// TODO create the service process structure
|
|
|
|
|
|
|
|
int service_path (char *buf, const char *sname);
|
|
|
|
|
|
|
|
void gen_process_structure (struct process *p
|
|
|
|
, pid_t pid, unsigned int index, unsigned int version);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns
|
|
|
|
* 0 : ok
|
|
|
|
* 1 : no service name
|
|
|
|
* 2 : service name too long
|
|
|
|
* 3 : unable to create fifo
|
|
|
|
*/
|
|
|
|
int service_create (const char *sname);
|
|
|
|
int service_close (const char *sname);
|
|
|
|
|
2016-05-30 01:54:19 +02:00
|
|
|
int service_get_new_process (struct process *proc, const char * spath);
|
|
|
|
void service_get_new_processes (struct process ***, int *nproc, char *spath);
|
2016-05-26 21:56:43 +02:00
|
|
|
void service_free_processes (struct process **, int nproc);
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-05-27 17:00:02 +02:00
|
|
|
void process_print (struct process *);
|
2016-05-26 18:27:59 +02:00
|
|
|
int process_create (struct process *, int index); // called by the application
|
|
|
|
int process_destroy (struct process *); // called by the application
|
|
|
|
|
|
|
|
int process_read (struct process *, void * buf, size_t *);
|
|
|
|
int process_write (struct process *, void * buf, size_t);
|
|
|
|
|
2016-05-30 16:30:05 +02:00
|
|
|
int service_read (struct process *, void * buf, size_t *);
|
|
|
|
int service_write (struct process *, void * buf, size_t);
|
|
|
|
|
2016-05-26 18:27:59 +02:00
|
|
|
#endif
|