1 /*
2  * Copyright (c) 2014 Hugh Bailey <obs.jim@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #pragma once
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #elif _MSC_VER
25 #ifndef inline
26 #define inline __inline
27 #endif
28 #endif
29 
30 struct ipc_pipe_server;
31 struct ipc_pipe_client;
32 typedef struct ipc_pipe_server ipc_pipe_server_t;
33 typedef struct ipc_pipe_client ipc_pipe_client_t;
34 
35 typedef void (*ipc_pipe_read_t)(void *param, uint8_t *data, size_t size);
36 
37 bool ipc_pipe_server_start(ipc_pipe_server_t *pipe, const char *name,
38 			   ipc_pipe_read_t read_callback, void *param);
39 void ipc_pipe_server_free(ipc_pipe_server_t *pipe);
40 
41 bool ipc_pipe_client_open(ipc_pipe_client_t *pipe, const char *name);
42 void ipc_pipe_client_free(ipc_pipe_client_t *pipe);
43 bool ipc_pipe_client_write(ipc_pipe_client_t *pipe, const void *data,
44 			   size_t size);
45 static inline bool ipc_pipe_client_valid(ipc_pipe_client_t *pipe);
46 
47 #ifdef _WIN32
48 #include "pipe-windows.h"
49 #else /* assume posix */
50 #include "pipe-posix.h"
51 #endif
52 
53 #ifdef __cplusplus
54 }
55 #endif
56