Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

238 lines (185 sloc) 7.563 kb
/*
EIBD client library
Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
In addition to the permissions in the GNU General Public License,
you may link the compiled version of this file into combinations
with other programs, and distribute those combinations without any
restriction coming from the use of this file. (The General Public
License restrictions do apply in other respects; for example, they
cover modification of the file, and distribution when not linked into
a combine executable.)
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define EIBC_LICENSE(text)
#define STR(A) #A
#define SHORT2INT(h) "(((@data[" #h "])<<8)|(@data[" #h "+1]))"
#define SHORT2LONG(h) "(((@data[" #h "])<<24)|((@data[" #h "+1])<<16)|((@data[" #h "+2])<<8)|(@data[" #h "+3]))"
#define EIBTYPE (SHORT2INT(0))
#define EIBC_GETREQUEST \
printf(" if __EIB_GetRequest() == -1\n"); \
printf(" return -1\n"); \
printf(" end\n");
#define EIBC_RETURNERROR(msg, error) \
printf(" if %s != %d\n", EIBTYPE, msg); \
printf(" @errno = Errno::%s\n", #error); \
printf(" return -1\n"); \
printf(" end\n");
#define EIBC_RETURNERROR_UINT16(offset, error) \
printf(" if %s == 0\n", SHORT2INT (offset)); \
printf(" @errno = Errno::%s\n", #error); \
printf(" return -1\n"); \
printf(" end\n");
#define EIBC_RETURNERROR_SIZE(Length, error) \
printf(" if @data.length <= %d\n", Length); \
printf(" @errno = Errno::%s\n", #error); \
printf(" return -1\n"); \
printf(" end\n");
#define EIBC_CHECKRESULT(msg, msgsize) \
printf(" if %s != %d or @data.length < %d\n", EIBTYPE, msg, msgsize); \
printf(" @errno = Errno::ECONNRESET\n"); \
printf(" return -1\n"); \
printf(" end\n");
#define EIBC_RETURN_BUF(offset) \
printf(" @buf.buffer = @data[%d..-1]\n", offset); \
printf(" return @buf.buffer.length\n");
#define EIBC_RETURN_OK \
printf(" return 0\n");
#define EIBC_RETURN_LEN \
printf(" return @sendlen\n");
#define EIBC_RETURN_UINT8(offset) \
printf(" return @data[%d]\n", offset);
#define EIBC_RETURN_UINT16(offset) \
printf(" return %s\n", SHORT2INT (offset));
#define EIBC_RETURN_PTR1(offset) \
printf(" if @ptr1 != nil\n"); \
printf(" @ptr1.data = %s\n", SHORT2INT (offset)); \
printf(" end\n");
#define EIBC_RETURN_PTR2(offset) \
printf(" if @ptr2 != nil\n"); \
printf(" @ptr2.data = @data[%d]\n", offset); \
printf(" end\n");
#define EIBC_RETURN_PTR3(offset) \
printf(" if @ptr3 != nil\n"); \
printf(" @ptr3.data = @data[%d]\n", offset); \
printf(" end\n");
#define EIBC_RETURN_PTR4(offset) \
printf(" if @ptr4 != nil\n"); \
printf(" @ptr4.data = %s\n", SHORT2INT (offset)); \
printf(" end\n");
#define EIBC_RETURN_PTR5(offset) \
printf(" if @ptr5 != nil\n"); \
printf(" @ptr5.data = %s\n", SHORT2INT (offset)); \
printf(" end\n");
#define EIBC_RETURN_PTR6(offset) \
printf(" if @ptr6 != nil\n"); \
printf(" @ptr6.data = %s\n", SHORT2INT (offset)); \
printf(" end\n");
#define EIBC_RETURN_PTR7(offset) \
printf(" if @ptr7 != nil\n"); \
printf(" @ptr7.data = %s\n", SHORT2LONG (offset)); \
printf(" end\n");
#define EIBC_COMPLETE(name, body) \
printf(" def __%s_Complete()\n", #name); \
printf(" puts \"__%s_Complete()\" if $DEBUG\n", #name); \
printf(" @__complete = nil\n"); \
body \
printf(" end\n\n");
#define EIBC_INIT_COMPLETE(name) \
printf(" @__complete = __%s_Complete()\n", #name); \
printf(" return 0\n");
#define EIBC_INIT_SEND(length) \
printf(" ibuf = [0] * %d;\n", length);
#define EIBC_SEND_BUF(name) EIBC_SEND_BUF_LEN (name, 0)
#define EIBC_SEND_BUF_LEN(name, Length) \
printf(" if %s.length < %d\n", #name, Length); \
printf(" @errno = Errno::EINVAL\n"); \
printf(" return -1\n"); \
printf(" end\n"); \
printf(" @sendlen = %s.length\n", #name); \
printf(" ibuf.concat(%s)\n", #name);
#define EIBC_SEND_LEN(name) STR((name.length))
#define EIBC_SEND(msg) \
printf(" ibuf[%d] = %d\n", 0, ((msg>>8)&0xff)); \
printf(" ibuf[%d] = %d\n", 1, ((msg)&0xff)); \
printf(" md = caller[0].match(/`(\\w*)'/); clr = md and md[1] or caller[0]\n"); \
printf(" puts(\"#{clr} calling __EIB_SendRequest, ibuf=#{ibuf.inspect}\") if $DEBUG\n"); \
printf(" if __EIB_SendRequest(ibuf) == -1\n"); \
printf(" return -1\n"); \
printf(" end\n");
#define EIBC_READ_BUF(buffer) \
printf(" @buf = %s\n", #buffer);
#define EIBC_READ_LEN(name) STR(name ## _len)
#define EIBC_PTR1(name) \
printf(" @ptr1 = %s\n", #name);
#define EIBC_PTR2(name) \
printf(" @ptr2 = %s\n", #name);
#define EIBC_PTR3(name) \
printf(" @ptr3 = %s\n", #name);
#define EIBC_PTR4(name) \
printf(" @ptr4 = %s\n", #name);
#define EIBC_PTR5(name) \
printf(" @ptr5 = %s\n", #name);
#define EIBC_PTR6(name) \
printf(" @ptr6 = %s\n", #name);
#define EIBC_PTR7(name) \
printf(" @ptr7 = %s\n", #name);
#define EIBC_SETADDR(name, offset) \
printf(" ibuf[%d] = ((%s>>8)&0xff)\n", offset, #name); \
printf(" ibuf[%d] = ((%s)&0xff)\n", offset+1, #name);
#define EIBC_SETUINT8(name, offset) \
printf(" ibuf[%d] = ((%s)&0xff)\n", offset, #name);
#define EIBC_UINT8(name, offset) \
printf(" ibuf[%d] = ((%s)&0xff)\n", offset, #name);
#define EIBC_SETUINT16(name, offset) \
printf(" ibuf[%d] = ((%s>>8)&0xff)\n", offset, #name); \
printf(" ibuf[%d] = ((%s)&0xff)\n", offset+1, #name);
#define EIBC_SETLEN(name, offset) \
printf(" ibuf[%d] = ((%s>>8)&0xff)\n", offset, name); \
printf(" ibuf[%d] = ((%s)&0xff)\n", offset+1, name);
#define EIBC_SETBOOL(value, offset) \
printf(" if %s != 0\n", #value); \
printf(" ibuf[%d] = 0xff\n", offset); \
printf(" else\n", #value); \
printf(" ibuf[%d] = 0x00\n", offset); \
printf(" end\n");
#define EIBC_SETKEY(value, offset) \
printf(" if %s.length != 4\n", #value); \
printf(" @errno = Errno::EINVAL\n"); \
printf(" return -1\n"); \
printf(" end\n"); \
printf(" ibuf[%d..%d] = %s\n", offset, offset+4, #value);
#define EIBC_ASYNC(name, args, body) \
printf("\n def %s_async(", #name); \
AG ## args \
printf(")\n"); \
printf(" puts \"%s_async()\" if $DEBUG\n", #name); \
body \
printf(" end\n\n"); \
printf(" def %s(", #name); \
AG ## args \
printf(")\n"); \
printf(" puts \"%s()\" if $DEBUG\n", #name); \
printf (" if %s_async(", #name); \
AL ## args \
printf (") == -1\n"); \
printf (" return -1\n"); \
printf(" end\n") ; \
printf (" return EIBComplete()"); \
printf("\n end\n\n");
#define EIBC_SYNC(name, args, body) \
printf(" def %s(", #name); \
AG ## args \
printf(")\n"); \
printf(" puts \"%s()\" if $DEBUG\n", #name); \
body \
printf("\n end\n\n");
Jump to Line
Something went wrong with that request. Please try again.