43 lines
2.7 KiB
C
43 lines
2.7 KiB
C
#ifndef VESSEL_HOOK_H_
|
|
#define VESSEL_HOOK_H_
|
|
|
|
#include "conf.h"
|
|
|
|
#include "def.h"
|
|
|
|
#define VS_DECLARE_HOOKS(owner, types, t) \
|
|
typedef struct { \
|
|
types type; \
|
|
bool (*hook)(t); \
|
|
} owner##Hook; \
|
|
bool owner##Hook_runall( \
|
|
const owner##Hook *hooks, const types type, t arg, const bool errors, size_t *count)
|
|
|
|
#define VS_DEFINE_HOOKS(owner, types, t) \
|
|
bool owner##Hook_runall( \
|
|
const owner##Hook *hooks, const types type, t arg, const bool errors, size_t *count) { \
|
|
size_t idx; \
|
|
bool result = true; \
|
|
if (!hooks) { \
|
|
if (count) \
|
|
*count = 0; \
|
|
return true; \
|
|
} \
|
|
for (idx = 0; hooks[idx].hook != NULL; ++idx) \
|
|
if (hooks[idx].type == type && !hooks[idx].hook(arg)) { \
|
|
if (errors) { \
|
|
if (count) \
|
|
*count = idx + 1; \
|
|
return false; \
|
|
} \
|
|
result = false; \
|
|
} \
|
|
if (count) \
|
|
*count = idx; \
|
|
return result; \
|
|
} \
|
|
const bool __##owner##Hook_defined = true
|
|
|
|
#define VS_HOOKS(...) { __VA_ARGS__, { 0 } }
|
|
|
|
#endif /* VESSEL_HOOK_H_ */
|