1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/*
(c) Copyright 2012-2013 DirectFB integrated media GmbH
(c) Copyright 2001-2013 The world wide DirectFB Open Source Community (directfb.org)
(c) Copyright 2000-2004 Convergence (integrated media) GmbH
All rights reserved.
Written by Denis Oliver Kropp <dok@directfb.org>,
Andreas Shimokawa <andi@directfb.org>,
Marek Pikarski <mass@directfb.org>,
Sven Neumann <neo@directfb.org>,
Ville Syrjälä <syrjala@sci.fi> and
Claudio Ciccani <klan@users.sf.net>.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __VOODOO__MESSAGE_H__
#define __VOODOO__MESSAGE_H__
#include <voodoo/types.h>
#include <direct/debug.h>
#include <direct/memcpy.h>
#define VOODOO_MSG_ALIGN(i) (((i) + 3) & ~3)
typedef enum {
VMBT_NONE,
VMBT_ID,
VMBT_INT,
VMBT_UINT,
VMBT_DATA,
VMBT_ODATA,
VMBT_STRING
} VoodooMessageBlockType;
typedef enum {
VREQ_NONE = 0x00000000,
VREQ_RESPOND = 0x00000001,
VREQ_ASYNC = 0x00000002,
VREQ_QUEUE = 0x00000004
} VoodooRequestFlags;
typedef enum {
VMSG_SUPER,
VMSG_REQUEST,
VMSG_RESPONSE,
VMSG_DISCOVER, // temporary solution for compatibility
VMSG_SENDINFO, // temporary solution for compatibility
} VoodooMessageType;
struct __V_VoodooMessageHeader {
int size;
VoodooMessageSerial serial;
VoodooMessageType type;
};
struct __V_VoodooSuperMessage {
VoodooMessageHeader header;
};
struct __V_VoodooRequestMessage {
VoodooMessageHeader header;
VoodooInstanceID instance;
VoodooMethodID method;
VoodooRequestFlags flags;
};
struct __V_VoodooResponseMessage {
VoodooMessageHeader header;
VoodooMessageSerial request;
DirectResult result;
VoodooInstanceID instance;
};
typedef struct {
int magic;
const char *msg;
const char *ptr;
} VoodooMessageParser;
#define __VOODOO_PARSER_PROLOG( parser, req_type ) \
const char *_vp_ptr; \
VoodooMessageBlockType _vp_type; \
int _vp_length; \
VoodooMessageParser *_parser = &parser; \
\
D_MAGIC_ASSERT( _parser, VoodooMessageParser ); \
\
(void)_vp_type; \
\
_vp_ptr = _parser->ptr; \
\
/* Read message block type. */ \
_vp_type = *(const VoodooMessageBlockType*) _vp_ptr; \
\
D_ASSERT( _vp_type == (req_type) ); \
\
/* Read data block length. */ \
_vp_length = *(const s32*) (_vp_ptr + 4)
#define __VOODOO_PARSER_EPILOG( parser ) \
/* Advance message data pointer. */ \
_parser->ptr += 8 + VOODOO_MSG_ALIGN(_vp_length)
#define VOODOO_PARSER_BEGIN( parser, message ) \
do { \
const VoodooMessageHeader *_vp_header = (const VoodooMessageHeader *) (message); \
VoodooMessageParser *_parser = &parser; \
\
D_ASSERT( (message) != NULL ); \
D_ASSERT( _vp_header->type == VMSG_REQUEST || _vp_header->type == VMSG_RESPONSE ); \
\
_parser->msg = (const char*)(message); \
_parser->ptr = _parser->msg + (_vp_header->type == VMSG_REQUEST ? \
sizeof(VoodooRequestMessage) : sizeof(VoodooResponseMessage)); \
\
D_MAGIC_SET_ONLY( _parser, VoodooMessageParser ); \
} while (0)
#define VOODOO_PARSER_GET_ID( parser, ret_id ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_ID ); \
\
D_ASSERT( _vp_length == 4 ); \
\
/* Read the ID. */ \
(ret_id) = *(const u32*) (_vp_ptr + 8); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_GET_INT( parser, ret_int ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_INT ); \
\
D_ASSERT( _vp_length == 4 ); \
\
/* Read the integer. */ \
(ret_int) = *(const s32*) (_vp_ptr + 8); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_GET_UINT( parser, ret_uint ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_UINT ); \
\
D_ASSERT( _vp_length == 4 ); \
\
/* Read the unsigned integer. */ \
(ret_uint) = *(const u32*) (_vp_ptr + 8); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_GET_DATA( parser, ret_data ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_DATA ); \
\
/*D_ASSERT( _vp_length > 0 );*/ \
\
/* Return pointer to data. */ \
(ret_data) = (__typeof__(ret_data))(_vp_ptr + 8); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_READ_DATA( parser, dst, max_len ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_DATA ); \
\
/*D_ASSERT( _vp_length > 0 );*/ \
D_ASSERT( _vp_length <= max_len ); \
\
/* Copy data block. */ \
direct_memcpy( (dst), _vp_ptr + 8, _vp_length ); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_COPY_DATA( parser, ret_data ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_DATA ); \
\
/*D_ASSERT( _vp_length > 0 );*/ \
\
/* Allocate memory on the stack. */ \
(ret_data) = alloca( _vp_length ); \
\
/* Copy data block. */ \
direct_memcpy( (ret_data), _vp_ptr + 8, _vp_length ); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_GET_ODATA( parser, ret_data ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_ODATA ); \
\
D_ASSERT( _vp_length >= 0 ); \
\
/* Return pointer to data or NULL. */ \
if (_vp_length) \
(ret_data) = (__typeof__(ret_data))(_vp_ptr + 8); \
else \
(ret_data) = NULL; \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_GET_STRING( parser, ret_string ) \
do { \
__VOODOO_PARSER_PROLOG( parser, VMBT_STRING ); \
\
D_ASSERT( _vp_length > 0 ); \
\
/* Return pointer to string. */ \
(ret_string) = (const char*) (_vp_ptr + 8); \
\
__VOODOO_PARSER_EPILOG( parser ); \
} while (0)
#define VOODOO_PARSER_END( parser ) \
do { \
VoodooMessageParser *_parser = &parser; \
\
D_MAGIC_ASSERT( _parser, VoodooMessageParser ); \
\
D_ASSUME( *(const u32*) (_parser->ptr) == VMBT_NONE ); \
\
D_MAGIC_CLEAR( _parser ); \
} while (0)
#endif
|