2016-05-26 18:27:59 +02:00
|
|
|
#ifndef __COMMUNICATION_H__
|
|
|
|
#define __COMMUNICATION_H__
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-09-17 22:57:32 +02:00
|
|
|
#include <cbor.h>
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-06-05 03:19:36 +02:00
|
|
|
#include "process.h"
|
2016-05-26 18:27:59 +02:00
|
|
|
#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-26 18:27:59 +02:00
|
|
|
#define COMMUNICATION_VERSION 1
|
|
|
|
|
2016-06-13 09:47:19 +02:00
|
|
|
#define ER_FILE_OPEN 1
|
|
|
|
#define ER_FILE_CLOSE 2
|
|
|
|
#define ER_FILE_READ 3
|
|
|
|
#define ER_FILE_WRITE 4
|
|
|
|
#define ER_FILE_WRITE_PARAMS 5
|
2016-06-12 12:38:43 +02:00
|
|
|
|
|
|
|
#define ER_MEM_ALLOC 100
|
2016-06-13 09:47:19 +02:00
|
|
|
#define ER_PARAMS 101
|
2016-06-12 12:38:43 +02: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-27 16:25:33 +02:00
|
|
|
int server_fd;
|
2016-05-30 01:54:19 +02:00
|
|
|
};
|
|
|
|
|
2016-06-13 09:47:19 +02:00
|
|
|
int srv_init (int argc, char **argv, char **env
|
|
|
|
, struct service *srv, const char *sname
|
|
|
|
, int (*cb)(int argc, char **argv, char **env
|
|
|
|
, struct service *srv, const char *sname));
|
2016-06-04 20:33:44 +02:00
|
|
|
|
2016-10-27 16:25:33 +02:00
|
|
|
int srv_get_new_process (const char *buf, struct process *proc);
|
2016-05-26 18:27:59 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* returns
|
|
|
|
* 0 : ok
|
|
|
|
* 1 : no service name
|
|
|
|
* 2 : service name too long
|
|
|
|
* 3 : unable to create fifo
|
|
|
|
*/
|
2016-06-05 20:48:13 +02:00
|
|
|
int srv_create (struct service *srv);
|
|
|
|
int srv_close (struct service *srv);
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-10-27 16:25:33 +02:00
|
|
|
int srv_read (struct process *, char ** buf);
|
2016-06-12 12:38:43 +02:00
|
|
|
int srv_write (struct process *, char * buf, size_t);
|
2016-06-04 20:33:44 +02:00
|
|
|
|
2016-06-05 03:19:36 +02:00
|
|
|
// APPLICATION
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-06-10 01:21:04 +02:00
|
|
|
// send the connection string to $TMP/<service>
|
|
|
|
int app_srv_connection (struct service *, const char *, size_t);
|
|
|
|
|
2016-06-13 09:47:19 +02:00
|
|
|
int app_create (struct process *, pid_t pid, int index, int version);
|
|
|
|
int app_destroy (struct process *);
|
2016-05-26 18:27:59 +02:00
|
|
|
|
2016-10-27 16:25:33 +02:00
|
|
|
int app_read (struct process *, char ** buf);
|
2016-06-12 12:38:43 +02:00
|
|
|
int app_write (struct process *, char * buf, size_t);
|
|
|
|
|
|
|
|
// wrappers
|
2016-10-27 16:25:33 +02:00
|
|
|
int file_read (int fd, char **buf);
|
|
|
|
int file_write (int fd, const char *buf, const int m_size);
|
|
|
|
|
|
|
|
//close socket
|
|
|
|
int close_socket(int fd);
|
2016-05-30 16:30:05 +02:00
|
|
|
|
2016-10-14 17:47:08 +02:00
|
|
|
//open, close, read, write
|
|
|
|
|
2016-05-26 18:27:59 +02:00
|
|
|
#endif
|