2013-12-25 21:40:33 -08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "../util/c99defs.h"
|
2013-12-30 09:14:28 -08:00
|
|
|
#include "../util/bmem.h"
|
2013-12-25 21:40:33 -08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Procedure call data structure
|
|
|
|
*
|
|
|
|
* This is used to store parameters (and return value) sent to/from signals,
|
|
|
|
* procedures, and callbacks.
|
|
|
|
*/
|
|
|
|
|
2013-12-26 01:02:24 -08:00
|
|
|
struct calldata {
|
|
|
|
size_t size; /* size of the stack, in bytes */
|
|
|
|
size_t capacity; /* capacity of the stack, in bytes */
|
|
|
|
uint8_t *stack;
|
|
|
|
};
|
|
|
|
|
2013-12-25 21:40:33 -08:00
|
|
|
typedef struct calldata *calldata_t;
|
|
|
|
|
2013-12-26 01:02:24 -08:00
|
|
|
static inline void calldata_init(struct calldata *data)
|
|
|
|
{
|
|
|
|
memset(data, 0, sizeof(struct calldata));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void calldata_free(struct calldata *data)
|
|
|
|
{
|
|
|
|
bfree(data->stack);
|
|
|
|
}
|
2013-12-25 21:40:33 -08:00
|
|
|
|
|
|
|
/* NOTE: 'get' functions return true only if paramter exists, and is the
|
|
|
|
* same size. They return false otherwise. */
|
|
|
|
|
|
|
|
EXPORT bool calldata_getdata(calldata_t data, const char *name, void *out,
|
|
|
|
size_t size);
|
|
|
|
EXPORT void calldata_setdata(calldata_t data, const char *name, const void *in,
|
|
|
|
size_t new_size);
|
|
|
|
|
2013-12-26 01:02:24 -08:00
|
|
|
static inline void calldata_clear(struct calldata *data)
|
|
|
|
{
|
|
|
|
if (data->stack) {
|
|
|
|
data->size = sizeof(size_t);
|
|
|
|
*(size_t*)data->stack = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-12-25 21:40:33 -08:00
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getchar (calldata_t data, const char *name,
|
|
|
|
char *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getuchar (calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned char *val)
|
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getshort (calldata_t data, const char *name,
|
|
|
|
short *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getushort(calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned short *val)
|
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getint (calldata_t data, const char *name,
|
|
|
|
int *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getuint (calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned int *val)
|
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getlong (calldata_t data, const char *name,
|
|
|
|
long *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getulong (calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned long *val)
|
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getint8 (calldata_t data, const char *name,
|
|
|
|
int8_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getuint8 (calldata_t data, const char *name,
|
|
|
|
uint8_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getint16 (calldata_t data, const char *name,
|
|
|
|
int8_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getuint16(calldata_t data, const char *name,
|
|
|
|
uint8_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getint32 (calldata_t data, const char *name,
|
|
|
|
int32_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getuint32(calldata_t data, const char *name,
|
|
|
|
uint32_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getint64 (calldata_t data, const char *name,
|
|
|
|
int64_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getuint64(calldata_t data, const char *name,
|
|
|
|
uint64_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getfloat (calldata_t data, const char *name,
|
|
|
|
long *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getdouble(calldata_t data, const char *name,
|
|
|
|
long *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getbool (calldata_t data, const char *name,
|
|
|
|
bool *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getsize (calldata_t data, const char *name,
|
|
|
|
size_t *val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, val, sizeof(*val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline bool calldata_getptr (calldata_t data, const char *name,
|
|
|
|
void **ptr)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
return calldata_getdata(data, name, ptr, sizeof(*ptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT bool calldata_getstring(calldata_t data, const char *name,
|
|
|
|
const char **str);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2013-12-26 03:26:17 -08:00
|
|
|
static void calldata_setchar (calldata_t data, const char *name, char val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setuchar (calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned char val)
|
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setshort (calldata_t data, const char *name,
|
|
|
|
short val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setushort(calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned short val)
|
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setint (calldata_t data, const char *name,
|
|
|
|
int val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setuint (calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned int val)
|
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setlong (calldata_t data, const char *name,
|
|
|
|
long val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setulong (calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
unsigned long val)
|
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setint8 (calldata_t data, const char *name,
|
|
|
|
int8_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setuint8 (calldata_t data, const char *name,
|
|
|
|
uint8_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setint16 (calldata_t data, const char *name,
|
|
|
|
int8_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setuint16(calldata_t data, const char *name,
|
|
|
|
uint8_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setint32 (calldata_t data, const char *name,
|
|
|
|
int32_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setuint32(calldata_t data, const char *name,
|
|
|
|
uint32_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setint64 (calldata_t data, const char *name,
|
|
|
|
int64_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setuint64(calldata_t data, const char *name,
|
|
|
|
uint64_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setfloat (calldata_t data, const char *name,
|
|
|
|
long val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setdouble(calldata_t data, const char *name,
|
|
|
|
long val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setbool (calldata_t data, const char *name,
|
|
|
|
bool val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setsize (calldata_t data, const char *name,
|
|
|
|
size_t val)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setptr (calldata_t data, const char *name,
|
|
|
|
void *ptr)
|
2013-12-25 21:40:33 -08:00
|
|
|
{
|
|
|
|
calldata_setdata(data, name, &ptr, sizeof(ptr));
|
|
|
|
}
|
|
|
|
|
2013-12-30 10:09:32 -08:00
|
|
|
static inline void calldata_setstring(calldata_t data, const char *name,
|
2013-12-25 21:40:33 -08:00
|
|
|
const char *str)
|
|
|
|
{
|
|
|
|
if (str)
|
|
|
|
calldata_setdata(data, name, str, strlen(str)+1);
|
|
|
|
else
|
|
|
|
calldata_setdata(data, name, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|