870c031fd60c3c4761164cf3bc92bbf5f1420828
[libfirm] / ir / lpp / lpp_comm.h
1 /**
2  * @file   lpp_server.h
3  * @date   19.07.2005
4  * @author Sebastian Hack
5  *
6  * Copyright (C) 2005 Universitaet Karlsruhe
7  * Released under the GPL
8  */
9
10 #ifndef _LPP_COMM_H
11 #define _LPP_COMM_H
12
13 #include <stdio.h>
14 #include <stdarg.h>
15 #include <stdint.h>
16
17 #define LPP_PORT    2175
18 #define LPP_BUFSIZE (1 << 20)
19
20 enum {
21 #define LPP_CMD(x) LPP_CMD_ ## x,
22 #include "lpp_cmd.def"
23 #undef LPP_CMD
24         LPP_CMD_LAST
25 };
26
27 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
28 do { \
29   int err_check_res; \
30   if((err_check_res = (expr)) op cond) { \
31     fprintf(stderr, "%s(%u): %d = %s(%d): ", \
32         __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
33     lpp_print_err fmt; \
34     fprintf(stderr, "\n"); \
35     last; \
36   } \
37 } while(0)
38
39 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
40 do { \
41   int _basic_errno_check_res = (expr); \
42   if(_basic_errno_check_res op cond) { \
43     fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
44         __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
45     last; \
46   } \
47 } while(0)
48
49 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
50   BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
51
52 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
53   BASIC_ERRNO_CHECK(expr, op, cond, return retval)
54
55 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
56   BASIC_ERR_CHECK(expr, op, cond, fmt, return)
57
58 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
59   BASIC_ERRNO_CHECK(expr, op, cond, return)
60
61 #define ERR_CHECK(expr, op, cond, fmt) \
62   BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
63
64 #define ERRNO_CHECK(expr, op, cond) \
65   BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
66
67 typedef struct _lpp_comm_t lpp_comm_t;
68
69 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
70
71 int lpp_comm_fileno(const lpp_comm_t *comm);
72
73 ssize_t lpp_flush(lpp_comm_t *comm);
74
75 void lpp_comm_free(lpp_comm_t *comm);
76
77 void lpp_print_err(const char *fmt, ...);
78
79 void lpp_writel(lpp_comm_t *comm, uint32_t x);
80
81 void lpp_writed(lpp_comm_t *comm, double dbl);
82
83 void lpp_writes(lpp_comm_t *comm, const char *str);
84
85 uint32_t lpp_readl(lpp_comm_t *comm);
86
87 int lpp_read_cmd(lpp_comm_t *comm);
88
89 double lpp_readd(lpp_comm_t *comm);
90
91 char *lpp_reads(lpp_comm_t *comm);
92
93 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
94
95 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
96
97 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
98
99 void lpp_send_ack(lpp_comm_t *comm);
100
101 const char *lpp_get_cmd_name(int cmd);
102
103 #endif