Java Client functions
[bcusdk.git] / eibd / client / java / def.def
blob98e8d8944e761679118fac0f7b076aa4f724f6db
1 /*
2 EIBD client library
3 Copyright (C) 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 In addition to the permissions in the GNU General Public License,
11 you may link the compiled version of this file into combinations
12 with other programs, and distribute those combinations without any
13 restriction coming from the use of this file. (The General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked into
16 a combine executable.)
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define EIBC_LICENSE(text)
30 #define BYTE2INT(val) (((int)(val))&0xff)
31 #define SHORT2INT(h,l) ((BYTE2INT(h)<<8)|(BYTE2INT(l)))
33 #define EIBTYPE (SHORT2INT(data[0],data[1]))
35 #define EIBC_GETREQUEST \
36 int i; \
37 if (_EIB_GetRequest()== -1) \
38 return -1;
40 #define EIBC_RETURNERROR(msg, error) \
41 if (EIBTYPE == msg) \
42 { \
43 errno = error; \
44 return -1; \
47 #define EIBC_RETURNERROR_UINT16(offset, error) \
48 if (SHORT2INT (data[offset], data[offset+1]) == 0) \
49 { \
50 errno = error; \
51 return -1; \
54 #define EIBC_RETURNERROR_SIZE(Length, error) \
55 if (data.length <= Length) \
56 { \
57 errno = error; \
58 return -1; \
61 #define EIBC_CHECKRESULT(msg, msgsize) \
62 if (EIBTYPE != msg || data.length < msgsize) \
63 { \
64 errno = ECONNRESET; \
65 return -1; \
68 #define EIBC_RETURN_BUF(offset) \
69 i = data.length - offset; \
70 buf.data = new byte[i]; \
71 System.arraycopy (data, offset, buf.data, 0, i); \
72 return i;
74 #define EIBC_RETURN_OK \
75 return 0;
77 #define EIBC_RETURN_LEN \
78 return sendlen;
80 #define EIBC_RETURN_UINT8(offset) \
81 return BYTE2INT (data[offset]);
83 #define EIBC_RETURN_UINT16(offset) \
84 return SHORT2INT (data[offset], data[offset+1]);
86 #define EIBC_RETURN_PTR1(offset) \
87 if (ptr1 != null) \
88 ptr1.data = (short)SHORT2INT (data[offset],data[offset+1]);
90 #define EIBC_RETURN_PTR2(offset) \
91 if (ptr2 != null) \
92 ptr2.data = data[offset];
94 #define EIBC_RETURN_PTR3(offset) \
95 if (ptr3 != null) \
96 ptr3.data = data[offset];
98 #define EIBC_RETURN_PTR4(offset) \
99 if (ptr4 != null) \
100 ptr4.data = (short)SHORT2INT (data[offset],data[offset+1]);
102 #define EIBC_RETURN_PTR5(offset) \
103 if (ptr5 != null) \
104 ptr5.addr = (short)SHORT2INT (data[offset], data[offset+1]);
106 #define EIBC_RETURN_PTR6(offset) \
107 if (ptr6 != null) \
108 ptr6.addr = (short)SHORT2INT (data[offset], data[offset+1]);
110 #define EIBC_COMPLETE(name, body) \
111 private class name##_complete implements _complete { \
112 public int complete () throws IOException { \
113 body \
117 #define EIBC_INIT_COMPLETE(name) \
118 complete = new name ## _complete (); \
119 return 0;
121 #define EIBC_INIT_SEND(length) \
122 byte head[] = new byte[length]; \
123 byte ibuf[] = head;
125 #define EIBC_SEND_BUF(name) EIBC_SEND_BUF_LEN (name, 0)
127 #define EIBC_SEND_BUF_LEN(name, Length) \
128 if (name.length < Length) \
129 throw new ArrayIndexOutOfBoundsException ("data to short"); \
130 ibuf = new byte[head.length + data.length]; \
131 System.arraycopy (head, 0, ibuf, 0, head.length); \
132 System.arraycopy (name, 0, ibuf, head.length, data.length);
134 #define EIBC_SEND_LEN(name) (name.length)
136 #define EIBC_SEND(msg) \
137 ibuf[0] = (byte)((msg>>8)&0xff); \
138 ibuf[1] = (byte)((msg)&0xff); \
139 if (_EIB_SendRequest (ibuf) == -1) \
140 return -1;
142 #define EIBC_READ_BUF(buffer) \
143 this.buf = buffer;
145 #define EIBC_READ_LEN(name) (name ## _len)
147 #define EIBC_PTR1(name) \
148 this.ptr1 = name;
150 #define EIBC_PTR2(name) \
151 this.ptr2 = name;
153 #define EIBC_PTR3(name) \
154 this.ptr3 = name;
156 #define EIBC_PTR4(name) \
157 this.ptr4 = name;
159 #define EIBC_PTR5(name) \
160 this.ptr5 = name;
162 #define EIBC_PTR6(name) \
163 this.ptr6 = name;
165 #define EIBC_SETADDR(name, offset) \
166 ibuf[offset] = (byte)((name>>8)&0xff); \
167 ibuf[offset+1] = (byte)((name)&0xff);
169 #define EIBC_SETUINT8(name, offset) \
170 ibuf[offset] = (byte)((name)&0xff);
172 #define EIBC_SETUINT16(name, offset) \
173 ibuf[offset] = (byte)((name>>8)&0xff); \
174 ibuf[offset+1] = (byte)((name)&0xff);
176 #define EIBC_SETBOOL(value, offset) \
177 ibuf[offset] = (byte)((value) ? 0xff : 0);
179 #define EIBC_SETKEY(value, offset) \
180 if (value.length != 4) \
181 throw new ArrayIndexOutOfBoundsException ("key is not 4 bytes long"); \
182 System.arraycopy (value, 0, ibuf, offset, 4);
184 #define EIBC_ASYNC(name, args, body) \
185 public int name ## _async ( AG ## args ) throws IOException { \
186 body \
189 public int name ( AG ## args ) throws IOException { \
190 if (name ##_async (AL##args) == -1) \
191 return -1; \
192 return EIBComplete (); \
195 #define EIBC_SYNC(name, args, body) \
196 public int name ( AG ## args ) throws IOException { \
197 body \