| 1 | #ifndef XC_SHM_H |
|---|
| 2 | #define XC_SHM_H |
|---|
| 3 | |
|---|
| 4 | #include <stdlib.h> |
|---|
| 5 | |
|---|
| 6 | typedef struct _xc_shm_handlers_t xc_shm_handlers_t; |
|---|
| 7 | |
|---|
| 8 | #ifndef XC_SHM_IMPL |
|---|
| 9 | struct _xc_shm_t { |
|---|
| 10 | const xc_shm_handlers_t *handlers; |
|---|
| 11 | }; |
|---|
| 12 | #define XC_SHM_IMPL _xc_shm_t |
|---|
| 13 | #endif |
|---|
| 14 | |
|---|
| 15 | typedef struct XC_SHM_IMPL xc_shm_t; |
|---|
| 16 | typedef size_t xc_shmsize_t; |
|---|
| 17 | |
|---|
| 18 | /* shm */ |
|---|
| 19 | #define XC_SHM_CAN_READONLY(func) int func(xc_shm_t *shm) |
|---|
| 20 | #define XC_SHM_IS_READWRITE(func) int func(xc_shm_t *shm, const void *p) |
|---|
| 21 | #define XC_SHM_IS_READONLY(func) int func(xc_shm_t *shm, const void *p) |
|---|
| 22 | #define XC_SHM_TO_READWRITE(func) void *func(xc_shm_t *shm, void *p) |
|---|
| 23 | #define XC_SHM_TO_READONLY(func) void *func(xc_shm_t *shm, void *p) |
|---|
| 24 | |
|---|
| 25 | #define XC_SHM_INIT(func) xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) |
|---|
| 26 | #define XC_SHM_DESTROY(func) void func(xc_shm_t *shm) |
|---|
| 27 | |
|---|
| 28 | #define XC_SHM_MEMINIT(func) void *func(xc_shm_t *shm, xc_shmsize_t size) |
|---|
| 29 | #define XC_SHM_MEMDESTROY(func) void func(void *mem) |
|---|
| 30 | |
|---|
| 31 | #define XC_SHM_HANDLERS(name) { \ |
|---|
| 32 | xc_##name##_can_readonly \ |
|---|
| 33 | , xc_##name##_is_readwrite \ |
|---|
| 34 | , xc_##name##_is_readonly \ |
|---|
| 35 | , xc_##name##_to_readwrite \ |
|---|
| 36 | , xc_##name##_to_readonly \ |
|---|
| 37 | \ |
|---|
| 38 | , xc_##name##_init \ |
|---|
| 39 | , xc_##name##_destroy \ |
|---|
| 40 | \ |
|---|
| 41 | , xc_##name##_meminit \ |
|---|
| 42 | , xc_##name##_memdestroy \ |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | struct _xc_shm_handlers_t { |
|---|
| 46 | XC_SHM_CAN_READONLY((*can_readonly)); |
|---|
| 47 | XC_SHM_IS_READWRITE((*is_readwrite)); |
|---|
| 48 | XC_SHM_IS_READONLY((*is_readonly)); |
|---|
| 49 | XC_SHM_TO_READWRITE((*to_readwrite)); |
|---|
| 50 | XC_SHM_TO_READONLY((*to_readonly)); |
|---|
| 51 | XC_SHM_INIT((*init)); |
|---|
| 52 | XC_SHM_DESTROY((*destroy)); |
|---|
| 53 | |
|---|
| 54 | XC_SHM_MEMINIT((*meminit)); |
|---|
| 55 | XC_SHM_MEMDESTROY((*memdestroy)); |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | typedef struct _xc_shm_scheme_t xc_shm_scheme_t; |
|---|
| 59 | |
|---|
| 60 | void xc_shm_init_modules(); |
|---|
| 61 | int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers); |
|---|
| 62 | const xc_shm_handlers_t *xc_shm_scheme_find(const char *name); |
|---|
| 63 | xc_shm_scheme_t *xc_shm_scheme_first(); |
|---|
| 64 | xc_shm_scheme_t *xc_shm_scheme_next(xc_shm_scheme_t *scheme); |
|---|
| 65 | const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme); |
|---|
| 66 | |
|---|
| 67 | xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2); |
|---|
| 68 | void xc_shm_destroy(xc_shm_t *shm); |
|---|
| 69 | #endif |
|---|