Introduce EIBC_RETURN_BUF
[bcusdk.git] / eibd / client / eibclient-int.h
blobd3f5e652ac405f122d325a8d42fea8f622350e14
1 /*
2 EIBD client library - internals
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 #ifndef EIBCLIENT_INT_H
29 #define EIBCLIENT_INT_H
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
36 #include "eibtypes.h"
38 /** unsigned char */
39 typedef uint8_t uchar;
41 /** EIB Connection internal */
42 struct _EIBConnection
44 int (*complete) (EIBConnection *);
45 /** file descriptor */
46 int fd;
47 unsigned readlen;
48 /** buffer */
49 uchar *buf;
50 /** buffer size */
51 unsigned buflen;
52 /** used buffer */
53 unsigned size;
54 struct
56 int len;
57 uint8_t *buf;
58 int16_t *ptr1;
59 uint8_t *ptr2;
60 uint8_t *ptr3;
61 uint16_t *ptr4;
62 eibaddr_t *ptr5;
63 eibaddr_t *ptr6;
64 } req;
67 /** extracts TYPE code of an eibd packet */
68 #define EIBTYPE(con) (((con)->buf[0]<<8)|((con)->buf[1]))
69 /** sets TYPE code for an eibd packet*/
70 #define EIBSETTYPE(buf,type) do{(buf)[0]=(type>>8)&0xff;(buf)[1]=(type)&0xff;}while(0)
72 /** set EIB address */
73 #define EIBSETADDR(buf,type) do{(buf)[0]=(type>>8)&0xff;(buf)[1]=(type)&0xff;}while(0)
75 int _EIB_SendRequest (EIBConnection * con, unsigned int size, uchar * data);
76 int _EIB_CheckRequest (EIBConnection * con, int block);
77 int _EIB_GetRequest (EIBConnection * con);
79 #define EIBC_GETREQUEST \
80 int i; \
81 i = _EIB_GetRequest (con); \
82 if (i == -1) \
83 return -1;
85 #define EIBC_RETURNERROR(msg, error) \
86 if (EIBTYPE (con) == msg) \
87 { \
88 errno = error; \
89 return -1; \
92 #define EIBC_CHECKRESULT(msg, msgsize) \
93 if (EIBTYPE (con) != msg || con->size < msgsize) \
94 { \
95 errno = ECONNRESET; \
96 return -1; \
99 #define EIBC_RETURN_BUF(offset) \
100 i = con->size - offset; \
101 if (i > con->req.len) \
102 i = con->req.len; \
103 memcpy (con->req.buf, con->buf + offset, i); \
104 return i;
107 #endif