Adjust copyright for 2010
[bcusdk.git] / eibd / client / perl / def.def
blob39ddd51337aa95cca3b1a1107752212b37fcd8e3
2 /*
3 EIBD client library
4 Copyright (C) 2005-2010 Martin Koegler <mkoegler@auto.tuwien.ac.at>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 In addition to the permissions in the GNU General Public License,
12 you may link the compiled version of this file into combinations
13 with other programs, and distribute those combinations without any
14 restriction coming from the use of this file. (The General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked into
17 a combine executable.)
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #define EIBC_LICENSE(text)
31 #define BYTE2INT(val) (val)
32 #define SHORT2INT(array, offset) ((vec(array,offset,8) << 8) | (vec(array,offset+1,8)))
34 #define EIBTYPE (SHORT2INT($self->{data},0))
36 #define EIBC_GETREQUEST \
37 $self->_EIB_Get_Request()==0 or return undef; \
39 #define EIBC_RETURNERROR(msg, error) \
40 if (EIBTYPE == msg) \
41 { \
42 $! = &Errno::error; \
43 return undef; \
46 #define EIBC_RETURNERROR_UINT16(offset, error) \
47 if (SHORT2INT ($self->{data}, offset) == 0) \
48 { \
49 $! = &Errno::error; \
50 return undef; \
53 #define EIBC_RETURNERROR_SIZE(Length, error) \
54 if (bytes::length($self->{data}) <= Length) \
55 { \
56 $! = &Errno::error; \
57 return undef; \
60 #define EIBC_CHECKRESULT(msg, msgsize) \
61 if (EIBTYPE != msg || bytes::length($self->{data}) < msgsize) \
62 { \
63 $! = &Errno::ECONNRESET; \
64 return undef; \
67 #define EIBC_RETURN_BUF(offset) \
68 ${$self->{buf}} = substr($self->{data}, offset); \
69 return bytes::length(${$self->{buf}});
71 #define EIBC_RETURN_OK \
72 return 0;
74 #define EIBC_RETURN_LEN \
75 return $self->{sendlen};
77 #define EIBC_RETURN_UINT8(offset) \
78 return BYTE2INT ($self->{data}[offset]);
80 #define EIBC_RETURN_UINT16(offset) \
81 return SHORT2INT ($self->{data}, offset);
83 #define EIBC_RETURN_PTR1(offset) \
84 if (defined $self->{ptr1}) \
85 { \
86 ${$self->{ptr1}} = SHORT2INT ($self->{data}, offset); \
89 #define EIBC_RETURN_PTR2(offset) \
90 if (defined $self->{ptr2}) \
91 { \
92 ${$self->{ptr2}} = BYTE2INT ($self->{data}[offset]); \
95 #define EIBC_RETURN_PTR3(offset) \
96 if (defined $self->{ptr3}) \
97 { \
98 ${$self->{ptr3}} = BYTE2INT ($self->{data}[offset]); \
101 #define EIBC_RETURN_PTR4(offset) \
102 if (defined $self->{ptr4}) \
104 ${$self->{ptr4}} = SHORT2INT ($self->{data}, offset); \
107 #define EIBC_RETURN_PTR5(offset) \
108 if (defined $self->{ptr5}) \
110 ${$self->{ptr5}} = SHORT2INT ($self->{data}, offset); \
113 #define EIBC_RETURN_PTR6(offset) \
114 if (defined $self->{ptr6}) \
116 ${$self->{ptr6}} = SHORT2INT ($self->{data}, offset); \
119 #define EIBC_COMPLETE(name, body) \
120 sub name##_complete { \
121 my $self = shift; \
122 $self->{complete} = undef; \
123 my $i; \
124 body \
127 #define EIBC_INIT_COMPLETE(name) \
128 $self->{complete} = #name . "_complete"; \
129 return 0;
131 #define EIBC_INIT_SEND(length) \
132 for ($i = 0; $i<length; $i++) { \
133 $ibuf[$i]=0x00; } \
134 my $headlen = length;
136 #define EIBC_SEND_BUF(name) EIBC_SEND_BUF_LEN (name, 0)
138 #define EIBC_SEND_BUF_LEN(name, Length) \
139 if (bytes::length(SCALAR(name)) < Length) \
141 $! = &Errno::EINVAL; \
142 return undef; \
144 $self->{sendlen} = bytes::length(SCALAR(name)); \
145 for ($i = 0; $i < bytes::length(SCALAR(name)); $i++) { \
146 $ibuf[$headlen + $i] = vec(SCALAR(name),$i,8); }
148 #define EIBC_SEND_LEN(name) (SCALAR(name))
150 #define EIBC_SEND(msg) \
151 $ibuf[0] = (msg>>8)&0xff; \
152 $ibuf[1] = (msg)&0xff; \
153 $self->_EIB_SendRequest (pack("C".@ibuf, @ibuf))==0 or return undef;
155 #define EIBC_READ_BUF(buffer) \
156 $self->{buf} = SCALAR(buffer);
158 #define EIBC_READ_LEN(name) (SCALAR(name ## _len))
160 #define EIBC_PTR1(name) \
161 $self->{ptr1} = SCALAR(name);
163 #define EIBC_PTR2(name) \
164 $self->{ptr2} = SCALAR(name);
166 #define EIBC_PTR3(name) \
167 $self->{ptr3} = SCALAR(name);
169 #define EIBC_PTR4(name) \
170 $self->{ptr4} = SCALAR(name);
172 #define EIBC_PTR5(name) \
173 $self->{ptr5} = SCALAR(name);
175 #define EIBC_PTR6(name) \
176 $self->{ptr6} = SCALAR(name);
178 #define EIBC_SETADDR(name, offset) \
179 $ibuf[offset] = (SCALAR(name)>>8)&0xff; \
180 $ibuf[offset+1] = (SCALAR(name))&0xff;
182 #define EIBC_SETUINT8(name, offset) \
183 $ibuf[offset] = (SCALAR(name))&0xff;
185 #define EIBC_UINT8(name, offset) \
186 $ibuf[offset] = ((name))&0xff;
188 #define EIBC_SETUINT16(name, offset) \
189 $ibuf[offset] = (SCALAR(name)>>8)&0xff; \
190 $ibuf[offset+1] = (SCALAR(name))&0xff;
192 #define EIBC_SETLEN(name, offset) \
193 $ibuf[offset] = ((name)>>8)&0xff; \
194 $ibuf[offset+1] = ((name))&0xff;
196 #define EIBC_SETBOOL(value, offset) \
197 $ibuf[offset] = (SCALAR(value)) ? 0xff : 0;
199 #define EIBC_SETKEY(value, offset) \
200 if (ARRAY(value) != 4) \
202 $! = &Errno::EINVAL; \
203 return undef; \
205 for ($i = 0; $i < 4; $i++) \
207 $ibuf [offset + $i] = vec(SCALAR(value),$i,8); \
210 #define EIBC_ASYNC(name, args, body) \
211 sub name ## _async { \
212 my ($self KAG##args) = @_; \
213 my $i; \
214 my @ibuf = {}; \
215 body \
217 sub name { \
218 my ($self KAG##args) = @_; \
219 $self -> name ## _async ( AL##args )==0 or return undef; \
220 return $self -> EIBComplete(); \
223 #define EIBC_SYNC(name, args, body) \
224 sub name { \
225 my ($self KAG##args) = @_; \
226 my $i; \
227 my @ibuf = {}; \
228 body \