Created
May 22, 2019 12:54
-
-
Save dvdhrm/3ecb905cd78aa852e6928e052498d9f1 to your computer and use it in GitHub Desktop.
C-Bus1 API Proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
/** | |
* Capability-based IPC for Linux | |
*/ | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
#include <inttypes.h> | |
#include <stdlib.h> | |
#include <sys/uio.h> | |
typedef struct CBus1 CBus1; | |
typedef struct CBus1Event CBus1Event; | |
typedef struct CBus1Handle CBus1Handle; | |
typedef struct CBus1Message CBus1Message; | |
typedef struct CBus1Object CBus1Object; | |
typedef struct CBus1Transfer CBus1Transfer; | |
enum { | |
C_BUS1_EVENT_TYPE_CUSTOM, | |
C_BUS1_EVENT_TYPE_RELEASE, | |
C_BUS1_EVENT_TYPE_DESTRUCTION, | |
_C_BUS1_EVENT_TYPE_N, | |
}; | |
struct CBus1Transfer { | |
uint64_t flags; | |
uint64_t id; | |
}; | |
struct CBus1Message { | |
uint64_t flags; | |
uint64_t type; | |
uint64_t n_transfers; | |
union { | |
uint64_t u64; | |
CBus1Transfer *ptr; | |
} ptr_transfers; | |
uint64_t n_data; | |
uint64_t n_data_vecs; | |
union { | |
uint64_t u64; | |
struct iovec *ptr; | |
} ptr_data_vecs; | |
}; | |
struct CBus1Object { | |
void *internal0[4]; | |
uint64_t internal1; | |
}; | |
/* events */ | |
CBus1Event *c_bus1_event_ref(CBus1Event *event); | |
CBus1Event *c_bus1_event_unref(CBus1Event *event); | |
unsigned int c_bus1_event_type(CBus1Event *event); | |
void c_bus1_event_message(CBus1Event *event, CBus1Object **objectp, CBus1Message **messagep); | |
void c_bus1_event_release(CBus1Event *event, CBus1Object **objectp); | |
void c_bus1_event_destruction(CBus1Event *event, CBus1Handle **handlep); | |
/* handles */ | |
CBus1Handle *c_bus1_handle_ref(CBus1Handle *handle); | |
CBus1Handle *c_bus1_handle_unref(CBus1Handle *handle); | |
uint64_t c_bus1_handle_id(CBus1Handle *handle); | |
/* objects */ | |
void c_bus1_object_init(CBus1Object *object, CBus1 *b1); | |
void c_bus1_object_deinit(CBus1Object *object); | |
int c_bus1_object_create(CBus1Object *object, CBus1Handle **handlep, CBus1 *remote); | |
void c_bus1_object_destroy(CBus1Object *object); | |
/* contexts */ | |
int c_bus1_new(CBus1 **b1p); | |
CBus1 *c_bus1_ref(CBus1 *b1); | |
CBus1 *c_bus1_unref(CBus1 *b1); | |
int c_bus1_fd(CBus1 *b1); | |
int c_bus1_dispatch(CBus1 *b1); | |
int c_bus1_pop_event(CBus1 *b1, CBus1Event **eventp); | |
int c_bus1_send(CBus1 *b1, | |
size_t n_destinations, | |
uint64_t *destination_ids, | |
int *destination_errors, | |
CBus1Message *message); | |
/* inline helpers */ | |
static inline void c_bus1_event_unrefp(CBus1Event **event) { | |
if (*event) | |
c_bus1_event_unref(*event); | |
} | |
static inline void c_bus1_handle_unrefp(CBus1Handle **handle) { | |
if (*handle) | |
c_bus1_handle_unref(*handle); | |
} | |
static inline void c_bus1_unrefp(CBus1 **b1) { | |
if (*b1) | |
c_bus1_unref(*b1); | |
} | |
#ifdef __cplusplus | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment