added lpp
[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
16 #ifdef _MSC_VER
17
18 typedef size_t              ssize_t;
19 typedef unsigned __int16    uint16_t;
20 typedef unsigned __int32    uint32_t;
21
22 /* disable warning: 'foo' was declared deprecated, use 'bla' instead */
23 /* of course MS had to make 'bla' incompatible to 'foo', so a simple */
24 /* define will not work :-((( */
25 #pragma warning( disable : 4996 )
26
27 #else /* _MSC_VER */
28
29 #include <stdint.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <netinet/in.h>
33
34 #endif /* _MSC_VER */
35
36
37
38 #define LPP_PORT    2175
39 #define LPP_BUFSIZE (1 << 20)
40
41 enum {
42 #define LPP_CMD(x) LPP_CMD_ ## x,
43 #include "lpp_cmd.def"
44 #undef LPP_CMD
45   LPP_CMD_LAST
46 };
47
48 #define BASIC_ERR_CHECK(expr,op,cond,fmt,last) \
49 { \
50   int res; \
51   if((res = (expr)) op cond) { \
52     fprintf(stderr, "%s(%u): %d = %s(%d): ", \
53         __FILE__, (unsigned) __LINE__, res, #expr, cond); \
54     lpp_print_err fmt; \
55     fprintf(stderr, "\n"); \
56     last; \
57   } \
58 }
59
60 #define BASIC_ERRNO_CHECK(expr,op,cond,last) \
61 { \
62   int _basic_errno_check_res = (expr); \
63   if(_basic_errno_check_res op cond) { \
64     fprintf(stderr, "%s(%u): %d = %s(%d): %s\n", \
65         __FILE__, (unsigned) __LINE__, _basic_errno_check_res, #expr, (int) cond, strerror(errno)); \
66     last; \
67   } \
68 }
69
70 #define ERR_CHECK_RETURN(expr, op, cond, fmt, retval) \
71   BASIC_ERR_CHECK(expr, op, cond, fmt, return retval)
72
73 #define ERRNO_CHECK_RETURN(expr, op, cond, retval) \
74   BASIC_ERRNO_CHECK(expr, op, cond, return retval)
75
76 #define ERR_CHECK_RETURN_VOID(expr, op, cond, fmt) \
77   BASIC_ERR_CHECK(expr, op, cond, fmt, return)
78
79 #define ERRNO_CHECK_RETURN_VOID(expr, op, cond) \
80   BASIC_ERRNO_CHECK(expr, op, cond, return)
81
82 #define ERR_CHECK(expr, op, cond, fmt) \
83   BASIC_ERR_CHECK(expr, op, cond, fmt, (void) 0)
84
85 #define ERRNO_CHECK(expr, op, cond) \
86   BASIC_ERRNO_CHECK(expr, op, cond, (void) 0)
87
88 typedef struct _lpp_comm_t lpp_comm_t;
89
90 lpp_comm_t *lpp_comm_new(int fd, size_t buf_size);
91
92 int lpp_comm_fileno(const lpp_comm_t *comm);
93
94 ssize_t lpp_flush(lpp_comm_t *comm);
95
96 void lpp_comm_free(lpp_comm_t *comm);
97
98 void lpp_print_err(const char *fmt, ...);
99
100 void lpp_writel(lpp_comm_t *comm, uint32_t x);
101
102 void lpp_writed(lpp_comm_t *comm, double dbl);
103
104 void lpp_writes(lpp_comm_t *comm, const char *str);
105
106 uint32_t lpp_readl(lpp_comm_t *comm);
107
108 int lpp_read_cmd(lpp_comm_t *comm);
109
110 double lpp_readd(lpp_comm_t *comm);
111
112 char *lpp_reads(lpp_comm_t *comm);
113
114 char *lpp_readbuf(lpp_comm_t *comm, char *buf, size_t buflen);
115
116 int lpp_ack(lpp_comm_t *comm, char *buf, size_t buflen);
117
118 void lpp_send_res(lpp_comm_t *comm, int ok, const char *fmt, ...);
119
120 void lpp_send_ack(lpp_comm_t *comm);
121
122 const char *lpp_get_cmd_name(int cmd);
123
124 #endif /* _LPP_COMM_H */