23 static int iface_count = 0;
30 ifaces[iface_count++] = bi;
37 dbg_trace(
"%llu", size);
39 new_buf = malloc(
sizeof(
struct photon_buffer_handle_t));
41 log_err(
"malloc failed");
45 memset(new_buf, 0,
sizeof(*new_buf));
47 new_buf->bint.buf.addr = (uintptr_t)addr;
48 new_buf->bint.buf.size = size;
50 new_buf->bint.priv_ptr = NULL;
51 new_buf->bint.priv_size = 0;
54 new_buf->ifaces = ifaces;
55 new_buf->iface_count = iface_count;
57 new_buf->ref_count = 1;
58 new_buf->is_registered = 0;
60 dbg_trace(
"allocated buffer handle: %p", new_buf);
61 dbg_trace(
"contains ptr to addr: %p of size %" PRIu64, addr, size);
69 if (iface_count <= 0) {
70 log_err(
"No buffer interfaces set!");
76 for (i=0; i<buf->iface_count; i++) {
77 if (buf->ifaces[i]->buffer_create)
78 buf->ifaces[i]->buffer_create(&(buf->bint), flags);
88 if (iface_count <= 0) {
89 log_err(
"No buffer interfaces set!");
93 for (i=0; i<buf->iface_count; i++) {
94 if (buf->ifaces[i]->buffer_free)
95 buf->ifaces[i]->buffer_free(&(buf->bint));
102 if (iface_count <= 0) {
103 log_err(
"No buffer interfaces set!");
107 for (i=0; i<buf->iface_count; i++) {
108 if (buf->ifaces[i]->buffer_register)
109 err += buf->ifaces[i]->buffer_register(&(buf->bint), flags);
113 buf->is_registered = 1;
122 if (iface_count <= 0) {
123 log_err(
"No buffer interfaces set!");
127 for (i=0; i<buf->iface_count; i++) {
128 if (buf->ifaces[i]->buffer_unregister)
129 err += buf->ifaces[i]->buffer_unregister(&(buf->bint));
133 buf->is_registered = 0;
photonBufferHandle photon_buffer_create(void *addr, uint64_t size, int flags)
#define BUFFER_IFACES_MAX
struct photon_buffer_handle_t * photonBufferHandle
photonBufferHandle _photon_buffer_create(void *addr, uint64_t size, int flags)
void photon_buffer_free(photonBufferHandle buf)
int photon_buffer_register(photonBufferHandle buf, int flags)
#define PHOTON_ERROR
Error code, general error.
int photon_buffer_unregister(photonBufferHandle buf)
#define PHOTON_OK
Photon success code.
int photon_buffer_init(photonBufferInterface bi)
Convenience pointer type for the private buffer structure.