4c425d7adbe0920ab795c4a58879a5a6ce812655
[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         LPP_CMD_BAD,
22         LPP_CMD_OK,
23         LPP_CMD_PROBLEM,
24         LPP_CMD_SOLUTION,
25         LPP_CMD_SOLVER,
26         LPP_CMD_BYE,
27         LPP_CMD_SOLVERS,
28         LPP_CMD_SET_DEBUG,
29         LPP_CMD_INFO,
30         LPP_CMD_LAST
31 };
32
33 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
34 do { \
35   int err_check_res; \
36   if((err_check_res = (expr)) op cond) { \
37     fprintf(stderr, "%s(%u): %d = %s(%d): ", \
38         __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
39     lpp_print_err fmt; \
40     fprintf(stderr, "\n"); \
41     last; \
42   } \
43 } while(0)
44
45 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
46 do { \
47   int _basic_errno_check_res = (expr); \
48   if(_basic_errno_check_res op cond) { \
49     fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
50         __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
51     last; \
52   } \
53 } while(0)
54
55 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
56   BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
57
58 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
59   BASIC_ERRNO_CHECK(expr, op, cond, return retval)
60
61 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
62   BASIC_ERR_CHECK(expr, op, cond, fmt, return)
63
64 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
65   BASIC_ERRNO_CHECK(expr, op, cond, return)
66
67 #define ERR_CHECK(expr, op, cond, fmt) \
68   BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
69
70 #define ERRNO_CHECK(expr, op, cond) \
71   BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
72
73 typedef struct _lpp_comm_t lpp_comm_t;
74
75 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
76
77 int lpp_comm_fileno(const lpp_comm_t *comm);
78
79 ssize_t lpp_flush(lpp_comm_t *comm);
80
81 void lpp_comm_free(lpp_comm_t *comm);
82
83 void lpp_print_err(const char *fmt, ...);
84
85 void lpp_writel(lpp_comm_t *comm, uint32_t x);
86
87 void lpp_writed(lpp_comm_t *comm, double dbl);
88
89 void lpp_writes(lpp_comm_t *comm, const char *str);
90
91 uint32_t lpp_readl(lpp_comm_t *comm);
92
93 int lpp_read_cmd(lpp_comm_t *comm);
94
95 double lpp_readd(lpp_comm_t *comm);
96
97 char *lpp_reads(lpp_comm_t *comm);
98
99 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
100
101 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
102
103 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
104
105 void lpp_send_ack(lpp_comm_t *comm);
106
107 const char *lpp_get_cmd_name(int cmd);
108
109 #endif