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
32 #define LPP_BUFSIZE (1 << 20)
47 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
50 if((err_check_res = (expr)) op cond) { \
51 fprintf(stderr, "%s(%u): %d = %s(%d): ", \
52 __FILE__, (unsigned) __LINE__, err_check_res, #expr, cond); \
54 fprintf(stderr, "\n"); \
59 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
61 int _basic_errno_check_res = (expr); \
62 if(_basic_errno_check_res op cond) { \
63 fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
64 __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
69 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
70 BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
72 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
73 BASIC_ERRNO_CHECK(expr, op, cond, return retval)
75 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
76 BASIC_ERR_CHECK(expr, op, cond, fmt, return)
78 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
79 BASIC_ERRNO_CHECK(expr, op, cond, return)
81 #define ERR_CHECK(expr, op, cond, fmt) \
82 BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
84 #define ERRNO_CHECK(expr, op, cond) \
85 BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
87 typedef struct _lpp_comm_t lpp_comm_t;
89 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
91 int lpp_comm_fileno(const lpp_comm_t *comm);
93 void lpp_flush(lpp_comm_t *comm);
95 void lpp_comm_free(lpp_comm_t *comm);
97 void lpp_print_err(const char *fmt, ...);
99 void lpp_writel(lpp_comm_t *comm, uint32_t x);
101 void lpp_writed(lpp_comm_t *comm, double dbl);
103 void lpp_writes(lpp_comm_t *comm, const char *str);
105 uint32_t lpp_readl(lpp_comm_t *comm);
107 int lpp_read_cmd(lpp_comm_t *comm);
109 double lpp_readd(lpp_comm_t *comm);
111 char *lpp_reads(lpp_comm_t *comm);
113 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
115 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
117 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
119 void lpp_send_ack(lpp_comm_t *comm);
121 const char *lpp_get_cmd_name(int cmd);