2 * Copyright (C) 2005-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @author Sebastian Hack
24 #ifndef LPP_LPP_COMM_H
25 #define LPP_LPP_COMM_H
33 typedef SSIZE_T ssize_t;
37 #define LPP_BUFSIZE (1 << 20)
52 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
55 if((err_check_res = (expr)) op cond) { \
56 fprintf(stderr, "%s(%u): %d = %s(%d): ", \
57 __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
59 fprintf(stderr, "\n"); \
64 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
66 int _basic_errno_check_res = (expr); \
67 if(_basic_errno_check_res op cond) { \
68 fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
69 __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
74 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
75 BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
77 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
78 BASIC_ERRNO_CHECK(expr, op, cond, return retval)
80 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
81 BASIC_ERR_CHECK(expr, op, cond, fmt, return)
83 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
84 BASIC_ERRNO_CHECK(expr, op, cond, return)
86 #define ERR_CHECK(expr, op, cond, fmt) \
87 BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
89 #define ERRNO_CHECK(expr, op, cond) \
90 BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
92 typedef struct _lpp_comm_t lpp_comm_t;
94 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
96 int lpp_comm_fileno(const lpp_comm_t *comm);
98 ssize_t lpp_flush(lpp_comm_t *comm);
100 void lpp_comm_free(lpp_comm_t *comm);
102 void lpp_print_err(const char *fmt, ...);
104 void lpp_writel(lpp_comm_t *comm, uint32_t x);
106 void lpp_writed(lpp_comm_t *comm, double dbl);
108 void lpp_writes(lpp_comm_t *comm, const char *str);
110 uint32_t lpp_readl(lpp_comm_t *comm);
112 int lpp_read_cmd(lpp_comm_t *comm);
114 double lpp_readd(lpp_comm_t *comm);
116 char *lpp_reads(lpp_comm_t *comm);
118 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
120 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
122 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
124 void lpp_send_ack(lpp_comm_t *comm);
126 const char *lpp_get_cmd_name(int cmd);